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
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
25
RMagick, migrate to ImageMagick 7 #RubyKaigi #RubyKaigi2019
watson
0
10k
Magick
watson
0
12k
fastlane 奮闘記
watson
0
95
How to optimize Ruby internal.
watson
3
3.1k
iOS、AndroidアプリをRubyで
watson
1
510
RubyMotion 2.0
watson
6
2.8k
Differences CRuby/MacRuby/RubyMotion
watson
5
5.8k
Other Decks in Technology
See All in Technology
AIで政治は変わるのか? — 中高生と考えたAI時代の民主主義(東海高校サタデープログラム)
eitarosuda
0
130
AI 不只幫你寫 Code: 當專案從 300 暴增到 1500, 我們如何撐住 DevOps
appleboy
0
300
Hatena Engineer Seminar 37 jj1uzh
jj1uzh
0
290
Fabricをフル活用する AI Agent Hub -製造業特化AIエージェントの設計
iotcomjpadmin
0
170
CVE-2026-20833_脆弱性対応とAES 化について
jukishiya
0
290
【FinOps】データドリブンな意思決定を目指して
z63d
3
530
組織における AI-DLC 実践
askul
0
220
Zenoh on Zephyr on LiteX
takasehideki
2
140
從觀望到全公司落地:AI Agentic Coding 導入實戰 — 流程整合與安全治理
appleboy
0
240
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
11k
PostgreSQL 19 新機能概要 OSC Hokkaido 2026
nori_shinoda
0
260
スタートアップにAmazon EKSは早すぎる? マルチプロダクト戦略を加速する Platform Engineeringの実践 / Is Amazon EKS Too Soon for Startups? Practical Platform Engineering to Accelerate a Multi-Product Strategy
elmodev09
1
1.9k
Featured
See All Featured
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.6k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
170
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
400
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
350
The SEO Collaboration Effect
kristinabergwall1
1
490
We Are The Robots
honzajavorek
0
260
Balancing Empowerment & Direction
lara
6
1.2k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
450
Abbi's Birthday
coloredviolet
3
8.3k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
320
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
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 !!!