fix: use stable native.object_id as cache key in DocumentAnalyzer (#83) - #84
Merged
Conversation
The DocumentAnalyzer was using node.object_id as the cache key for node path IDs. However, Moxml creates new wrapper objects for the same underlying Nokogiri/Oga nodes on each traverse, causing constant cache misses and O(n*depth) path recomputation for every node. This was causing DOM validation to be ~200x slower than SAX validation on large SVG files. Fix by using node.native.object_id as the cache key since the underlying parser node identity is stable across wrapper re-creation. Performance improvement: - DOM validation: 18s -> 0.84s (21x faster) - Full remediation: 3m42s -> 3.35s (66x faster) Fixes #83
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
Fix extreme DOM validation slowness caused by cache key instability in
DocumentAnalyzer.Problem: DOM validation was ~200x slower than SAX validation on large SVG files (3m42s vs 1s for a 1.4MB file).
Root cause:
DocumentAnalyzerusednode.object_idas cache key, but Moxml creates new wrapper objects on each traverse, causing constant cache misses.Fix: Use
node.native.object_idas cache key since underlying parser node identity is stable.Changes
lib/svg_conform/document_analyzer.rb- Usenode.native.object_idinstead ofnode.object_idin three placesdocs/performance.adoc- Document the cache key stability patternPerformance
Test plan
bundle exec rake spec- 335 tests passbundle exec rake rubocop- No offensesFixes #83