-
-
Notifications
You must be signed in to change notification settings - Fork 251
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
Oj.dump
with compat/rails mode
This patch introduces `oj_hash_has_key()` (same as rb__hash_has_key) to reduce `rb_funcall()` calling because it has a overhead. This patch will improve `Oj.dump` performance as following. − | before | after | result -- | -- | -- | -- Oj.dump | 1.949M | 1.966M | − Oj.dump (compat) | 850.154k | 1.198M | 1.41x Oj.dump (rails) | 657.383k | 840.051k | 1.28x ### Environment - MacBook Air (M1, 2020) - macOS 12.0 beta 3 - Apple M1 - Ruby 3.0.2 ### Before ``` Warming up -------------------------------------- Oj.dump 198.379k i/100ms Oj.dump (compat) 86.466k i/100ms Oj.dump (rails) 66.760k i/100ms Calculating ------------------------------------- Oj.dump 1.949M (± 0.3%) i/s - 9.919M in 5.088487s Oj.dump (compat) 850.154k (± 0.3%) i/s - 4.323M in 5.085367s Oj.dump (rails) 657.383k (± 0.4%) i/s - 3.338M in 5.077802s ``` ### After ``` Warming up -------------------------------------- Oj.dump 198.297k i/100ms Oj.dump (compat) 120.402k i/100ms Oj.dump (rails) 84.204k i/100ms Calculating ------------------------------------- Oj.dump 1.966M (± 0.3%) i/s - 9.915M in 5.044305s Oj.dump (compat) 1.198M (± 0.2%) i/s - 6.020M in 5.026524s Oj.dump (rails) 840.051k (± 0.1%) i/s - 4.210M in 5.011848s ``` ### Test code ```ruby require 'benchmark/ips' require 'oj' data = { 'short_string': 'a' * 50, 'long_string': 'b' * 255, 'utf8_string': 'あいうえお' * 10 } Benchmark.ips do |x| x.report('Oj.dump') { Oj.dump(data) } x.report('Oj.dump (compat)') { Oj.dump(data, mode: :compat) } x.report('Oj.dump (rails)') { Oj.dump(data, mode: :rails) } end ```
- Loading branch information
1 parent
cfc14d1
commit ad67f5e
Showing
3 changed files
with
30 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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