Implements bd-27: Cache compiled regexes in replaceIDReferences for performance Problem: replaceIDReferences() was compiling regex patterns on every call. With 100 issues and 10 ID mappings, that resulted in 4,000 regex compilations (100 issues × 4 text fields × 10 ID mappings). Solution: - Added buildReplacementCache() to pre-compile all regexes once - Added replaceIDReferencesWithCache() to reuse compiled regexes - Updated updateReferences() to build cache once and reuse for all issues - Kept replaceIDReferences() for backward compatibility (calls cached version) Performance Results (from benchmarks): Single text: - 1.33x faster (26,162 ns → 19,641 ns) - 68% less memory (25,769 B → 8,241 B) - 80% fewer allocations (278 → 55) Real-world (400 texts, 10 mappings): - 1.89x faster (5.1ms → 2.7ms) - 90% less memory (7.7 MB → 0.8 MB) - 86% fewer allocations (104,112 → 14,801) Tests: - All existing tests pass - Added 3 benchmark tests demonstrating improvements 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
15 KiB
15 KiB