Skip to content

Releases: Clickin/stax-xml

0.5.2

18 Oct 16:27

Choose a tag to compare

Performance Improvements

StaxXmlWriter Optimization (+31.7% average improvement)

The XML Writer(sync/async both) has been significantly optimized through three key algorithmic improvements:

  1. Regex Caching (+9.3%)

    • Static readonly patterns for basic XML entities
    • Construction-time compilation for custom entities
    • Eliminates repeated regex creation overhead
  2. Attribute String Batching (+36.5%)

    • Single string concatenation before write operation
    • Reduces function call overhead from 4 calls to 1 per attribute
    • Exceptional improvement in attribute-heavy documents
  3. Early Entity Check (+25.6%)

    • Fast string.includes() checks before regex operations
    • Avoids expensive regex when no entities are present
    • Significant performance gain for clean text content

Benchmark Results (50,000 elements):

  • Realistic documents: +18.4% (180ms → 147ms)
  • Mixed content: +54.1% (99ms → 46ms)
  • Deep nested structures: +63.8% (86ms → 31ms)
  • Attribute-heavy: +35.8%

All optimizations maintain 100% API compatibility and pass all 796 test cases with identical output.

StaxXmlParserSync Optimization (+20.67% improvement)

Replaced generator-based implementation with a state machine approach:

Key Improvements:

  • Eliminated generator overhead (~95ns → ~10ns per event)
  • IteratorResult object reuse (zero allocations)
  • Pending event queue for self-closing tag handling
  • 95%+ code reuse from existing parsing logic

Benchmark Results (10MB XML file):

  • Generator baseline: 115.98ms
  • State machine: 92.00ms
  • Improvement: +20.67%

StaxXmlParser (Async) Optimization (~15% improvement)

Replaced Array-based queue with a circular buffer implementation:

Key Improvements:

  • Eliminated O(n) Array.shift() operations → O(1) dequeue
  • Improved memory locality with circular buffer pattern
  • Queue operation cost reduced from 50ns to 10ns
  • Dynamic queue growth when needed

Benchmark Results (1GB XML file):

  • Array-based queue: baseline
  • Circular buffer: ~15% faster
  • All 796 tests passed with 100% API compatibility

Changed

  • Writer performance improved by 20-60% depending on XML structure
  • Sync parser performance improved by 20.67%
  • Async parser performance improved by ~15% on large files

Technical Details

For detailed performance analysis and benchmarking methodology, see:

  • Writer optimization: packages/benchmark/writer-optimization/results/FINAL-ANALYSIS.md
  • Parser optimization: packages/benchmark/PARSER_OPTIMIZATION_FINAL_REPORT.md

Internal

  • Removed unused internal methods
  • Enhanced benchmarking infrastructure
  • Comprehensive documentation of optimization attempts and learnings

v0.4.0

21 Sep 08:13

Choose a tag to compare

Performance Improvements:

  • Optimization for V8 hidden class
  • StaxXmlParserSync: unnecessary substring operations removed
  • Caching entity regex for better performance
  • Inline functions to reduce function call overhead

API Changes:

  • Breaking: StaxXmlWriter is now async-based, synchronous version moved to StaxXmlWriterSync

Documentation & Testing:

  • Added documentation using Astro Starlight
  • Added several performance benchmarks

Major performance improvements and breaking changes for better async handling.