- Added global string cache for efficient string interning (5.2x faster)
- Implemented optimized tokenizer with object pooling
- Created comprehensive benchmarks and documentation
- Cleaned up old optimization files and experiments
Performance improvements:
- String interning: 5.2x faster (1,492 ns/op vs 7,746 ns/op)
- Zero allocations for common strings
- Same memory efficiency as original (36 B/op, 9 allocs/op)
- Implemented pooled slices for function arguments
- Added specialized pooling for variable node and literal node objects
- Modified array and hash node evaluation to reduce allocations
- Optimized test and filter evaluation with pooled resources
- Added comprehensive benchmarks to validate improvements
- Updated node pool implementation to remove duplicate declarations
- Fixed memory allocations in merge filter to correctly handle array manipulations
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Latest benchmark runs show dramatic performance improvements:
- Twig is now 57x faster than Go's html/template for complex templates
- Memory usage reduced by 90% compared to standard Go templates
- Performance on medium templates improved to 0.14 µs/op from 0.35 µs/op
- Simple template rendering improved to 0.28 µs/op from 0.47 µs/op
These improvements reflect the optimizations from object pooling and
filter chain handling optimizations in recent commits.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit dramatically improves memory efficiency and performance by:
1. Adding object pooling for frequently allocated node types:
- TextNode, PrintNode, RootNode, LiteralNode, VariableNode, IfNode, ForNode
- Released nodes properly after rendering is complete
2. Implementing token pooling to reduce allocations during parsing:
- Added token pool for all token creation sites
- Optimized token slice allocation with capacity hints
3. Improved RenderContext and StringBuffer handling:
- Better cleanup and resource management
Benchmark results show:
- 91% reduction in memory usage compared to Go's templates
- 60x performance improvement in rendering speed
- Consistently 2 allocations per operation for all node types
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Added byteBufferPool to reuse buffers during rendering
- Implemented WriteString utility function to eliminate allocations
- Updated all node Render methods to use the optimized function
- Reduced memory allocations during template rendering
- Added benchmarks showing significant improvement with io.Writer
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit introduces two major performance improvements:
1. Memory optimization in string handling
- Pre-allocates slice capacities to reduce reallocations
- Uses string builders with pre-allocated capacity
- Avoids unnecessary string concatenations and conversions
- Optimizes pattern matching code to reduce allocations
- Reuses memory for string slices where possible
2. Fixed unbounded attribute cache growth
- Added maximum cache size limit (1000 entries)
- Implemented simple cache eviction strategy
- Tracks current cache size with counter
- Prevents potential memory leaks in long-running applications
These changes significantly reduce memory allocations and improve
performance, especially for large templates.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Added specific benchmark for macro performance (direct, imported, nested)
- Added memory usage benchmark comparing Twig with Go templates
- Created MEMORY_RESULTS.md to track memory efficiency
- Updated benchmark results with latest performance metrics
- Enhanced documentation for macros in README with examples
- Fixed badges in README for better rendering on GitHub
- Added comprehensive information about variable scope in macros
- Updated example code to demonstrate nested macros
- Improved organization of benchmark directory
- Updated roadmap with completed items and future plans
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>