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
NaN BoxingによるJSONパーサーの高速化
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Kazuhiro Fujieda
February 14, 2020
Programming
2
1k
NaN BoxingによるJSONパーサーの高速化
DynaJsonの高速化で使っているNaN Boxingという技術を紹介する。
Kazuhiro Fujieda
February 14, 2020
Tweet
Share
More Decks by Kazuhiro Fujieda
See All by Kazuhiro Fujieda
静的クラスは遅いことがあるよ
kfujieda
3
2.1k
ftp.jaist.ac.jpの低レイヤーの話
kfujieda
0
89
Other Decks in Programming
See All in Programming
20260315 AWSなんもわからん🥲
chiilog
2
180
ファインチューニングせずメインコンペを解く方法
pokutuna
0
200
メッセージングを利用して時間的結合を分離しよう #phperkaigi
kajitack
3
460
生成 AI 時代のスナップショットテストってやつを見せてあげますよ(α版)
ojun9
0
310
GC言語のWasm化とComponent Modelサポートの実践と課題 - Scalaの場合
tanishiking
0
130
Understanding Apache Lucene - More than just full-text search
spinscale
0
140
それはエンジニアリングの糧である:AI開発のためにAIのOSSを開発する現場より / It serves as fuel for engineering: insights from the field of developing open-source AI for AI development.
nrslib
1
610
Coding at the Speed of Thought: The New Era of Symfony Docker
dunglas
0
1.6k
LM Linkで(非力な!)ノートPCでローカルLLM
seosoft
0
250
Goの型安全性で実現する複数プロダクトの権限管理
ishikawa_pro
2
1.4k
AI時代の脳疲弊と向き合う ~言語学としてのPHP~
sakuraikotone
1
1.6k
AI活用のコスパを最大化する方法
ochtum
0
340
Featured
See All Featured
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
220
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
270
The untapped power of vector embeddings
frankvandijk
2
1.6k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
240
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Speed Design
sergeychernyshev
33
1.6k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
91
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Transcript
NaN BoxingによるJSON パーサーの高速化 藤枝 和宏 twitter: kfujieda
[email protected]
DynaJson • https://github.com/fujieda/DynaJson/ • 高速なJSONパーサー • DynamicJson互換 var json =
JsonObject.Parse(@"{ ""foo"": ""json"", ""nest"": {""foobar"": true} }"); var a1 = json.foo; // "json" var a2 = json.nest.foobar; // true
速い citm_catalog.json (1.7MB)⇒DynamicObject 11.849 21.123 34.711 50.772 58.141 0 10
20 30 40 50 60 70 DynaJson Utf8Json Jil Newtonsoft.Json DynamicJson Time (ms) ←lower is better
なぜ速いか • JSONの値を16バイトの構造体に格納 • 動的メモリ割り当てが不要に • 代入でコピーが発生するが16バイトまでは速い
16バイトに格納する • Explicitレイアウトでフィールドを重ねる • doubleの上4バイトにJsonTypeを重ねる ⇒ NaN Boxing [StructLayout(LayoutKind.Explicit)] internal
struct InternalObject { [FieldOffset(4)] public JsonType Type; [FieldOffset(0)] public double Number; [FieldOffset(8)] public string String; [FieldOffset(8)] public JsonArray Array; [FieldOffset(8)] public JsonDictionary Dictionary; }
NaN Boxing • doubleのNaNの隙間に値を詰める • NaNは0/0などで発生する特別な値 • 表現は0xfff800000000 (qNANの場合) •
下位51ビットは任意の値でいい
NaNに値を詰める enum JsonType : uint { Null = 0xfff80001, True
= 0xfff80002, False = 0xfff80003, String = 0xfff80004, Array = 0xfff80005, Object = 0xfff80006 } static object ToValue(InternalObject obj) { switch (obj.Type) { case JsonType.Null: return null; case JsonType.True: return true; case JsonType.False: return false; case JsonType.String: return obj.String; case JsonType.Array: case JsonType.Object: return new JsonObject(obj); default: return obj.Number; } }
NaN Boxingの効果 11.849 13.418 16.294 0 5 10 15 20
struct 16 struct 24 class Time (ms) ←lower is better