Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve performance of reading escaped string (#948)
This patch will improve the performance of reading escaped string by using a lookup table. − | before | after | result -- | -- | -- | -- Oj.load | 601.508 | 654.004 | 1.087x ### Environment - Linux - Manjaro Linux x86_64 - Kernel: 6.12.4-1-MANJARO - AMD Ryzen 9 8945HS - gcc version 14.2.1 - Ruby 3.4.1 ### Code ```ruby require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'benchmark-ips' gem 'oj' end # https://github.com/miloyip/nativejson-benchmark/blob/master/data/twitter.json json = File.read('twitter.json') Benchmark.ips do |x| x.time = 10 x.report('Oj.load compat') { Oj.load(json, mode: :compat) } end ``` ### Before ``` $ ruby json_load.rb ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] Warming up -------------------------------------- Oj.load compat 59.000 i/100ms Calculating ------------------------------------- Oj.load compat 601.508 (± 1.2%) i/s (1.66 ms/i) - 6.018k in 10.006395s ``` ### After ``` $ ruby json_load.rb ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] Warming up -------------------------------------- Oj.load compat 64.000 i/100ms Calculating ------------------------------------- Oj.load compat 654.004 (± 1.7%) i/s (1.53 ms/i) - 6.592k in 10.082170s ```
- Loading branch information