Skip to content

perf: reduce per-character overhead in hot parsing paths#5

Merged
tymondesigns merged 4 commits intomainfrom
claude/unruffled-jepsen
Mar 20, 2026
Merged

perf: reduce per-character overhead in hot parsing paths#5
tymondesigns merged 4 commits intomainfrom
claude/unruffled-jepsen

Conversation

@tymondesigns
Copy link
Copy Markdown
Contributor

  • Short-circuit removeComments() with str_contains fast path — avoids full character-by-character scan for the common case of JSON without comment markers
  • Replace preg_match() + substr() for boolean/null keyword detection with substr_compare and a first-char gate, eliminating regex engine overhead and the intermediate substring allocation
  • Batch digit reads in handleNumber() and unquoted key reads in handleObjectKey() using substr() instead of char-by-char concatenation
  • Cache strlen($json) in handleObjectKey, handleExpectingColon, handleObjectValue, handleArrayValue, and handleExpectingCommaOrEnd to avoid repeated function calls inside their hot paths

tymondesigns and others added 3 commits March 20, 2026 00:08
- Short-circuit removeComments() with str_contains fast path — avoids
  full character-by-character scan for the common case of JSON without
  comment markers
- Replace preg_match() + substr() for boolean/null keyword detection
  with substr_compare and a first-char gate, eliminating regex engine
  overhead and the intermediate substring allocation
- Batch digit reads in handleNumber() and unquoted key reads in
  handleObjectKey() using substr() instead of char-by-char concatenation
- Cache strlen($json) in handleObjectKey, handleExpectingColon,
  handleObjectValue, handleArrayValue, and handleExpectingCommaOrEnd
  to avoid repeated function calls inside their hot paths

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Extract keyword specs into keywordMatchSpecs() static method, use
in_array() for the first-char gate, add blank lines between loop body
and subsequent statements, and enable --parallel for the test script.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tymondesigns tymondesigns marked this pull request as ready for review March 20, 2026 00:19
- Add error handling section to quickstart covering JsonRepairException
- Add smart/curly quote and invalid escape sequence examples to repair-examples
- Add missing log messages to the logging page (comments, trailing comma,
  smart quotes, doubled delimiter, incomplete string removal)
- Clarify what composer check runs in the installation dev setup steps
- Simplify the ensureAscii example to use a less noisy key name

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tymondesigns tymondesigns merged commit 0d89064 into main Mar 20, 2026
17 checks passed
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.

1 participant