-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
performance-boost and fix memory-issues: Get rid of Object.finalize()
#8780
Comments
As with all performance-related diffs we should profile the results. There's some chance that finalizers are cheap enough or behave differently on ART. |
Ok, but how would you profile this?
|
Well you claimed there would be an extreme performance boost and reduced memory consumption - so show a before-and-after comparison of speed and memory use. |
I actually don't know how to craft a correct reproducible GC profiling test-case, since this behaviour is not defined and relies on the manufacturers of the phones and their memory and heapsize settings. I hope someone else can step in here. The thing I know for sure is that in the last 10 years, every java expert anywhere advised against finalizers for many reasons. But everybody has the right to discard well meant advice. |
Object.finalize()
Object.finalize()
@ide Here is a test-case: FinalizerTest.java It profiles creation-time of 1000 simple objects (1 int field) with
Results:
Keep in mind that this is just instantiation of objects, not the actual finalisation and GC time and complexity that's imposed later. |
@Stoffern Good question.
|
@fab1an can you run a app in simulator:
I know my app is leaking memory after 30-40 refreshs when loading 10 different components. |
@Stoffern That's not much use. The native resources that are disposed in the finalizers in |
@Stoffern I've setup and compiled ReactNative, but unfortunately I can't afford putting more time into this right now. I've already spent about 10 hours researching, reading the code, providing benchmarks, detailed bug-reports and citing sources for this. I'm not getting paid for doing this work ;). |
@fab1an i dont get payed either 😄 And this issue is a core issue both in RN and Fresco lib, it will be quite a job for both of us to figure out how to fix this. @andreicoman11 @mkonicek you guys know more of the core to how it works, would this be possible to fix? |
@ide I figured a way of profiling this, or at least the beginning of a way: Since |
@fab1an That seems reasonable to me so we get a basic idea of whether there is a performance improvement (or unexpected regression) and roughly how big the improvement is. |
I think the discussion here has converged on saying, if there is indeed a performance improvement, it would be valuable to have a pull request for it, we just need to profile to be sure. I'm going to close this issue since it no longer seems useful but if someone does indeed create a pull request improving performance that would be pretty nice here. |
@lacker There are two benchmarks in this bug-report. One here: #8780 (comment) There other one linked from here: #10504 But it seems that just nobody wants to change this. |
Is there a pull request somewhere that is improving performance? Maybe I missed it. If there is a pull request to improve performance then it is easier for me to drive that to a conclusion, vs having an issue where it's hard to see what should be concluded per se. |
This leak is killing me. Will this be fixed? |
I opened this bug to separate it from the Fresco image-loading bug.
Here (#8711) you can find a lengthy explanation why
Object.finalize()
is bad, but the two main reasons, why RN should stop using it are:The
FinalizerQueue
can fill-up and stop being processed, this can happen for many reasons, and it's possible thatObject.finalize()
is never called until the JVM exits. This also means that, every object that's referenced from an object whose finalizer isn't called, isn't garbage-collected. Like everything referenced fromCatalystInstanceImpl
because of this log-statement.Finalizers slow everything down by a giant amount. Quote from Effective Java:
Usage of
finalize()
in RN.I would write the PR myself, but I'm not sure how RN manages
HybridData
. I know it's tedious to release everything manually, but doing it will give RN an extreme performance-boost and lower memory-footprint. This will help everyone.Finalizers were just a bad idea which should have never happened.
The text was updated successfully, but these errors were encountered: