Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Improve JSON Performance
Search
Watson
May 31, 2018
Technology
1.1k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Improve JSON Performance
Watson
May 31, 2018
More Decks by Watson
See All by Watson
クラウドネイティブ時代に 進化し続けるFluentd
watson
0
33
RMagick, migrate to ImageMagick 7 #RubyKaigi #RubyKaigi2019
watson
0
10k
Magick
watson
0
12k
fastlane 奮闘記
watson
0
98
How to optimize Ruby internal.
watson
3
3.1k
iOS、AndroidアプリをRubyで
watson
1
520
RubyMotion 2.0
watson
6
2.9k
Differences CRuby/MacRuby/RubyMotion
watson
5
5.8k
Other Decks in Technology
See All in Technology
Bet AI Day 2026丨How We Bet AI: AIとともに働く場をつくる
layerx
PRO
1
1.7k
Guerilla InnerSource in enterprises, during the AI hype
onenashev
PRO
0
140
Hub & Spoke 環境のネットワークルーティングを分解してみる
tsuyataku
1
510
Point Cloud as a Foreign Language for Multi-modal Large Language Model
takmin
0
360
なぜSRE・セキュリティは評価されないのか?守りの組織を事業成長エンジンに変えた実践
cscengineer
PRO
0
880
いま好きなこと 最初はそんなに好きじゃなかった #tamagawadev
nishiuma
1
220
When Token Pruning is Worse than Random: Understanding Visual Token Information in VLLMs
sansantech
PRO
0
230
人気商品が「ちゃんと買える」をつくる ー ECの負荷改善
ykagano
1
190
Data Hubグループ 紹介資料
sansan33
PRO
0
3.2k
Claude Codeで開発以外の業務も爆速化しよう!
minorun365
PRO
12
9.5k
Oracle AI Databaseデータベース・サービス: BaseDB/ExaDB-Dの可用性
oracle4engineer
PRO
1
1.1k
V8コントリビュート超入門
riyaamemiya
0
110
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
680
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Faster Mobile Websites
deanohume
310
32k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
760
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
850
RailsConf 2023
tenderlove
30
1.5k
Navigating Team Friction
lara
192
16k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
480
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Transcript
*NQSPWF+40/ 1FSGPSNBODF Shizuo Fujita
Self @watson1978 Ubiregi Inc. Ruby committer
JSON.parse()
None
Parsed Hash object require 'json' json =<<'END' { "id": 1,
"uuid": "ede84c89-3e5a-4025-a8d4-8c66cfed1820", "created_at": "2018-05-27 22:54:55 +0900" } END JSON.parse(json) # => {"id"=>1, # "uuid"=>"ede84c89-3e5a-4025-a8d4-8c66cfed1820", # "created_at"=>"2018-05-27 22:54:55 +0900"} Hash object has String keys.
Hash freezes string key Duplicate and freeze the string if
it isn’t frozen…
Remove redundant duplication Hash#[]= with frozen string key, you can
remove redundant duplication of string in internally
Benchmark obj = [] 1000.times do |i| obj << {
"id": i, "uuid": SecureRandom.uuid, "created_at": Time.now } end json = obj.to_json Benchmark.ips do |x| x.report("json") { JSON.parse(json) } x.report("yajl") { Yajl::Parser.parse(json) } x.report("oj") { Oj.load(json) } end
KTPO CFGPSF ZBKM KTPO BGUFS
PK VQ Before After
JSON.generate() (i.e. Object#to_json)
None
1. Remove redundant converting array = hash.keys array.each do |key|
value = hash[key] ... end hash.each do |key, value| ... end Before After Here is pseudo code…
2. Add shortcut for converting to String for Hash key
Before it always convert Object to String using #to_s via rb_funcall(). After It convert with appropriate CRuby-API if necessary.
3. Call CRuby-API instead of rb_funcall rb_funcall() is slightly heavy
to call the Ruby method. It is better performance to use rb_str_encode() API instead.
4. Convert encoding only when needed If String object has
only ASCII characters, it might not need to convert encoding.
Benchmark obj = [] 1000.times do |i| obj << {
"id" => i, :age => 42, :name => "Foo Bar Baz" } end Benchmark.ips do |x| x.report("json") { JSON.generate(obj) } x.report("yajl") { Yajl::Encoder.encode(obj, nil) } x.report("oj") { Oj.dump(obj) } end
KTPO CFGPSF ZBKM KTPO BGUFS
PK YVQ Before After
⚠
Not merged, No reaction Can you help me? https://github.com/flori/json/pull/345 https://github.com/flori/json/pull/346
Thank you !!!