diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2024-10-28 21:08:26 +0100 |
|---|---|---|
| committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2024-10-29 13:25:01 +0900 |
| commit | 2e43621806e752227b9e246b1b5ef1080c89fdaa (patch) | |
| tree | 5895a9f0091257d8a0df10b54ff1e6841aa8eab2 /include/ruby/backward | |
| parent | b094ee3f23097f3e02c54476a0499e590e1bf5d7 (diff) | |
[ruby/json] Optimize `fbuffer_append_long`
Ref: https://github.com/ruby/json/issues/655
Rather than to write the number backward, and then reverse
the buffer, we can start from the back of the buffer and write
the number in the proper direction.
Before:
```
== Encoding integers (8009 bytes)
ruby 3.3.4 (2024-07-09 revision https://github.com/ruby/json/commit/be1089c8ec) +YJIT [arm64-darwin23]
Warming up --------------------------------------
json 8.606k i/100ms
oj 9.598k i/100ms
Calculating -------------------------------------
json 86.059k (± 0.8%) i/s (11.62 μs/i) - 430.300k in 5.000416s
oj 97.409k (± 0.6%) i/s (10.27 μs/i) - 489.498k in 5.025360s
Comparison:
json: 86058.8 i/s
oj: 97408.8 i/s - 1.13x faster
```
After:
```
== Encoding integers (8009 bytes)
ruby 3.3.4 (2024-07-09 revision https://github.com/ruby/json/commit/be1089c8ec) +YJIT [arm64-darwin23]
Warming up --------------------------------------
json (reuse) 9.500k i/100ms
json 9.359k i/100ms
oj 9.722k i/100ms
Calculating -------------------------------------
json (reuse) 96.270k (± 0.4%) i/s (10.39 μs/i) - 484.500k in 5.032777s
json 94.800k (± 2.2%) i/s (10.55 μs/i) - 477.309k in 5.037495s
oj 97.131k (± 0.7%) i/s (10.30 μs/i) - 486.100k in 5.004822s
Comparison:
json (reuse): 96270.1 i/s
oj: 97130.5 i/s - same-ish: difference falls within error
json: 94799.9 i/s - same-ish: difference falls within error
```
https://github.com/ruby/json/commit/0655b58d14
Diffstat (limited to 'include/ruby/backward')
0 files changed, 0 insertions, 0 deletions
