Repository navigation
Conversation
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.
Fixes: #5681
It changes the following:
ForwardTransitionby the prototype'saddress (
PrototypeTransitionKey) instead of holding a strongJsPrototypekey, so the map no longer keeps prototypes alive.
prune_prototype_transitions, so that early cleanup doesn't postpone theperiodic prune.
test_prototype_transition_does_not_keep_prototype_alive,test_prototype_transition_is_reused, and makestest_prune_prototype_on_counter_limitdeterministic (prototypes are keptalive while entries are being counted, since dead same-sized allocations can
reuse an address).
Root cause
ForwardTransition::prototypesusedJsPrototypeas the key, i.e. a strongreference to the prototype. A prototype can indirectly reference an object that
uses the transitioned shape, which reaches the shape that owns the map, so the
map closed the cycle and pinned the prototype — and everything reachable from
it — for as long as the owning shape lived. For a long-lived shape (for example
the realm root shape), every prototype ever created against it was retained, so
force_collectgot slower with each iteration.Why an address is a valid key
The map no longer holds a GC reference, but it still identifies prototypes
uniquely: every shape stored under the key strongly references the prototype it
was created for, so an entry that is still alive can only ever match that same
live prototype. The
nullprototype is represented by address0, which cannever be the address of an allocation. Dead entries are pruned exactly as
before (bounded, every 255 insertions), which is why the reproducer keeps a
small constant plateau rather than returning to zero.
Testing
Reproducer from the issue (class with
Foo.instance = new Foo(), created 1,000times in one
Context, timingforce_collectin release mode):cargo test -p boa_engine --lib— 1142 passed, 0 failedcargo test -p boa_engine --tests— 11 passedcargo clippy -p boa_engine --lib -- -D warnings— cleancargo fmt --all -- --check— clean