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
28
RMagick, migrate to ImageMagick 7 #RubyKaigi #RubyKaigi2019
watson
0
10k
Magick
watson
0
12k
fastlane 奮闘記
watson
0
97
How to optimize Ruby internal.
watson
3
3.1k
iOS、AndroidアプリをRubyで
watson
1
510
RubyMotion 2.0
watson
6
2.9k
Differences CRuby/MacRuby/RubyMotion
watson
5
5.8k
Other Decks in Technology
See All in Technology
LLM・AIエージェントシステムベストプラクティス
shibuiwilliam
6
1.3k
PLATEAU で バーチャル花火大会
tatsuya1970
0
160
トヨタ⽣産⽅式(TPS)⼊⾨
recruitengineers
PRO
3
840
事業価値と Engineering 2026年度版
recruitengineers
PRO
49
24k
AWS ネットワーク構築でハマった(ハマりかけた) 5選とそこから得た教訓
nagisa53
4
220
Breaking the Seal: Static Deobfuscation of Compiled V8 JavaScript Bytecode Malware
hshrzd
0
780
Invisible to AI? Making TYPO3 Sites Quotable by AI Search Systems
wolfgangwagner
0
210
会社紹介資料 / Sansan Company Profile
sansan33
PRO
24
430k
同じWAFが、攻撃の“形”は弾く── 正当な“形”の不正は通す
kuroneko13
0
200
カートの信頼性を担保するWireMockを使ったe2eテスト
ykagano
0
300
【CEDEC2026】Creative Approaches to Localizing the Dialects and Unique Speech of Umamusume: Pretty Derby Characters in English
cygames
PRO
3
23k
ボトムアップ文化が強い組織で セキュリティをどう根付かせていくかの現在進行形の話 / Making Security Stick in a Bottom-Up Organization
yamaguchitk333
0
220
Featured
See All Featured
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.7k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
So, you think you're a good person
axbom
PRO
2
2.1k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.6k
Building Applications with DynamoDB
mza
96
7.2k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
660
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Crafting Experiences
bethany
1
250
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
390
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.8k
Typedesign – Prime Four
hannesfritz
42
3.1k
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 !!!