Repository navigation
fix(android): release Java-returned wrappers when JavaScript drops them - #127
Open
ammarahm-ed wants to merge 1 commit into
Open
ammarahm-ed wants to merge 1 commit into
ammarahm-ed wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every Java object returned to JS stayed alive for the life of the runtime. Its wrapper was held by a strong reference in
m_idToObject, and a host-object proxy created for the wrapper pinned it a second time, so returning a lot of objects grew the process until Android killed it. This PR makes the wrapper the only thing that keeps a returned object alive, and ties the Java side to the wrapper's lifetime. It changes the Node-API and the direct runtime the same way.extend, interface implementations) stay strong, because Java may call back into them at any time.js_adjust_external_memory/EngineHost::AdjustExternalMemory), so the engine schedules a GC under native pressure instead of only when its own heap grows.OwnerTokenthatOnDisposeRuntimeclears, because the engine can destroy native state after the manager is gone.EnsureInstanceStrongmoves it back to the strong table whenever a wrapper is (re)created. If a new wrapper was linked under an id between the collection and the drain, the drain leaves that id alone.Results
V8 release build on a Sony SO-01M (Android 11, arm64), AOT-compiled with
cmd package compile -m speed. One warm-up launch is discarded, then 5 launches; values are the median ns per call.The heap row is the native heap after one pass of the suite, which returns about 200k objects. Rows this change does not touch moved by up to ±17%.
Invoke string callbackon the direct runtime is bimodal in this build (7.9k to 11.8k ns across the five runs, against 7.8k to 8.4k before); it does not go through this code for its arguments, and the Node-API runtime is flat on it, so I am treating it as noise, but I have not isolated it.All cases
Only V8 was built and run.
Jasmine suite
Run once on a debug build of the top of this stack (this PR, the bulk array reads in the PR above, and the crash-handler PR), on the same device:
triggers interval, a timing spec)The spec count is one lower on the stack top because the crash-handler PR removes a disabled spec. This PR was not run on its own.