Enhancing code quality part 2.2: Parser Performance Optimizations #10

Merged
Pakobbix merged 1 commits from issue-9-parser-performance into main 2026-07-12 12:01:59 +00:00
Collaborator

Implements all three parser performance optimizations from issue #9:

  1. Regex pre-compilation: All regex patterns in parser.js (~50) and jsonRepair.js (14) are now module-level constants instead of being compiled on every function call.

  2. Format detection caching: Added lastDetectedFormat cache with hit threshold (3 consecutive hits) to skip redundant format checks on subsequent calls. Exported clearFormatCache() for cache invalidation.

  3. Thinking tag removal: Already happens early in the pipeline before parsing (unchanged, confirmed optimal).

Tests: 33/33 passing. Covers repairJSON, extractJSONFromText, validateJSONSchema, safeParseJSON, all parser regex patterns, format cache logic, and performance comparison.

Closes #9

Implements all three parser performance optimizations from issue #9: 1. **Regex pre-compilation**: All regex patterns in parser.js (~50) and jsonRepair.js (14) are now module-level constants instead of being compiled on every function call. 2. **Format detection caching**: Added `lastDetectedFormat` cache with hit threshold (3 consecutive hits) to skip redundant format checks on subsequent calls. Exported `clearFormatCache()` for cache invalidation. 3. **Thinking tag removal**: Already happens early in the pipeline before parsing (unchanged, confirmed optimal). Tests: 33/33 passing. Covers repairJSON, extractJSONFromText, validateJSONSchema, safeParseJSON, all parser regex patterns, format cache logic, and performance comparison. Closes #9
ARIA added 1 commit 2026-07-12 11:58:32 +00:00
- Pre-compile all regex patterns as module-level constants in parser.js and jsonRepair.js
- Add format detection caching (lastDetectedFormat, formatCacheHits) to skip redundant checks
- Add clearFormatCache() export for cache invalidation
- Add comprehensive test suite (33 tests) for parser and jsonRepair modules
- Fix regex escaping in dynamic patterns (statRegex, fieldRegex)
- Improve toFieldKey() regex specificity
Collaborator

No issues found — changes look consistent with the stated intent. Ready to be merged.

✅ No issues found — changes look consistent with the stated intent. Ready to be merged.
Pakobbix merged commit 3c4e632906 into main 2026-07-12 12:01:59 +00:00
Pakobbix deleted branch issue-9-parser-performance 2026-07-12 12:01:59 +00:00
Sign in to join this conversation.