fix: strong wrapper cache — weak identity was a GC race - #20
Merged
Conversation
The four wrapper-identity specs failed on the Windows CI matrix (188 examples, 4 failures; mac/linux green): ObjectSpace::WeakMap holds values weakly, so between two doc.root calls the first wrapper was referenced only by the map — any GC sweep evicted it and the second call built a fresh object. Identity was a GC timing race, not a property of the interface. The cache is now a plain Hash owned by the Document and cleared in free. Cost: at most one wrapper per node actually visited, held until the document dies. Full suite 188/188 locally; doc.root.equal?(doc.root) survives 50 forced GC.start rounds.
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.
Summary
Fixes the four Windows-only wrapper-identity failures in PR #19.
The cache was an ObjectSpace::WeakMap — values held weakly — so wrapper identity was a GC race: between two
doc.rootcalls the first wrapper was referenced only by the map, any sweep evicted it, and the second call built a fresh object. Windows CI lost that race (188 examples, the 4 identity specs); mac/linux happened to win it.Now a plain Hash owned by the Document, cleared in
free. Cost: one wrapper per node actually visited, held until the document dies.Test plan
doc.root.equal?(doc.root)survives 50 forcedGC.startrounds.