Skip to content

fix: use stable native.object_id as cache key in DocumentAnalyzer (#83) - #84

Merged
ronaldtse merged 1 commit into
mainfrom
fix/document-analyzer-cache-key
Apr 9, 2026
Merged

fix: use stable native.object_id as cache key in DocumentAnalyzer (#83)#84
ronaldtse merged 1 commit into
mainfrom
fix/document-analyzer-cache-key

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

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: DocumentAnalyzer used node.object_id as cache key, but Moxml creates new wrapper objects on each traverse, causing constant cache misses.

Fix: Use node.native.object_id as cache key since underlying parser node identity is stable.

Changes

  • lib/svg_conform/document_analyzer.rb - Use node.native.object_id instead of node.object_id in three places
  • docs/performance.adoc - Document the cache key stability pattern

Performance

Operation Before After Speedup
DOM validation ~18s ~0.84s 21x
Full remediation ~3m42s ~3.35s 66x

Test plan

  • bundle exec rake spec - 335 tests pass
  • bundle exec rake rubocop - No offenses
  • Benchmarked with both Nokogiri and Oga adapters

Fixes #83

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
@ronaldtse
ronaldtse merged commit edeffec into main Apr 9, 2026
11 checks passed
@ronaldtse
ronaldtse deleted the fix/document-analyzer-cache-key branch April 9, 2026 03:44
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.

Performance: DOM validation 100x slower than SAX validation on large SVG files (Issue #79)

1 participant