Skip to content

fix: strong wrapper cache — weak identity was a GC race - #20

Merged
ronaldtse merged 1 commit into
release/1.1.0from
fix/wrapper-cache-strong
Aug 22, 2026
Merged

fix: strong wrapper cache — weak identity was a GC race#20
ronaldtse merged 1 commit into
release/1.1.0from
fix/wrapper-cache-strong

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

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.root calls 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

  • Full suite 188/188 locally against the libleptris 1.1.0 shared library.
  • doc.root.equal?(doc.root) survives 50 forced GC.start rounds.

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.
@ronaldtse
ronaldtse merged commit 2ff7a4d into release/1.1.0 Aug 22, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant