parser.c: Record escape positions while parsing#902
Merged
byroot merged 1 commit intoruby:masterfrom Nov 22, 2025
Merged
Conversation
We can then pass them to the decoder to save having to parse
the string again.
```
== Parsing activitypub.json (58160 bytes)
ruby 3.4.6 (2025-09-16 revision dbd83256b1) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
after 1.275k i/100ms
Calculating -------------------------------------
after 12.774k (± 0.8%) i/s (78.29 μs/i) - 65.025k in 5.090834s
Comparison:
before: 12314.3 i/s
after: 12773.8 i/s - 1.04x faster
== Parsing twitter.json (567916 bytes)
ruby 3.4.6 (2025-09-16 revision dbd83256b1) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
after 143.000 i/100ms
Calculating -------------------------------------
after 1.441k (± 0.2%) i/s (693.86 μs/i) - 7.293k in 5.060345s
Comparison:
before: 1430.1 i/s
after: 1441.2 i/s - 1.01x faster
== Parsing citm_catalog.json (1727030 bytes)
ruby 3.4.6 (2025-09-16 revision dbd83256b1) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
after 69.000 i/100ms
Calculating -------------------------------------
after 695.919 (± 0.4%) i/s (1.44 ms/i) - 3.519k in 5.056691s
Comparison:
before: 687.8 i/s
after: 695.9 i/s - 1.01x faster
```
Member
Author
|
Specific benchmark: benchmark_parsing "some_unescape", JSON.dump([((" "*100) + "\n")*15] * 100)
benchmark_parsing "more_unescape", JSON.dump([((" "*100) + "\n")*30] * 100)So this helps quite a bit for large strings with a reasonable amount of escapes, typically your comment body, etc, will contain a few newlines and double quotes, but not much more than that. |
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.
Closes: #894
We can then pass them to the decoder to save having to parse the string again.