perf: reduce per-character overhead in hot parsing paths#5
Merged
tymondesigns merged 4 commits intomainfrom Mar 20, 2026
Merged
perf: reduce per-character overhead in hot parsing paths#5tymondesigns merged 4 commits intomainfrom
tymondesigns merged 4 commits intomainfrom
Conversation
Contributor
tymondesigns
commented
Mar 20, 2026
- 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
- 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>
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.