Skip to content

Conversation

@byroot
Copy link
Member

@byroot byroot commented Nov 22, 2025

Closes: #894

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

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
```
@byroot
Copy link
Member Author

byroot commented Nov 22, 2025

Specific benchmark:

benchmark_parsing "some_unescape", JSON.dump([((" "*100) + "\n")*15] * 100)
benchmark_parsing "more_unescape", JSON.dump([((" "*100) + "\n")*30] * 100)
== Parsing some_unescape (153301 bytes)
ruby 3.4.6 (2025-09-16 revision dbd83256b1) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
               after     3.691k i/100ms
Calculating -------------------------------------
               after     36.850k (± 0.5%) i/s   (27.14 μs/i) -    184.550k in   5.008228s

Comparison:
              before:    25529.8 i/s
               after:    36850.3 i/s - 1.44x  faster


== Parsing more_unescape (306301 bytes)
ruby 3.4.6 (2025-09-16 revision dbd83256b1) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
               after     1.801k i/100ms
Calculating -------------------------------------
               after     18.039k (± 4.0%) i/s   (55.44 μs/i) -     91.851k in   5.101041s

Comparison:
              before:    14315.5 i/s
               after:    18038.9 i/s - 1.26x  faster

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.

@byroot byroot merged commit 4f4551f into ruby:master Nov 22, 2025
37 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