Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
`go get`したらELFが降ってきた件
Search
鹿
October 31, 2026
Technology
90
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
`go get`したらELFが降ってきた件
github.com/velox-io/json の native acceleration の仕組みを調べてみました。
すごい黒魔術です。
鹿
October 31, 2026
More Decks by 鹿
See All by 鹿
なぜselectはselectではないのか
taiyow
1
490
Go の GC の不得意な部分を克服したい
taiyow
4
2.1k
Golang と Erlang
taiyow
8
2.3k
Other Decks in Technology
See All in Technology
Vue で書く 空間コンピューティング、TresJS と WebXR を使ったXR デバイスのフロントエンド開発
hiranuma
0
150
[General] 개발자로 해외 기업에서 일하기
skydoves
1
250
Flutter Webを「SDK」として配る — 50以上のゲームを支える埋め込みアーキテクチャ
masayukisuda
0
170
構造で守らせる データ・法務・セキュリティ・開発チームとつくる AI時代のデータガバナンスとデータ基盤のリアル
legalontechnologies
PRO
3
720
複雑な業務システムを高速でつくるため、チーム全員をつくれる人へ
ayakurabuchi
0
120
ひとりで始めた AI駆動開発、チームに広げて何が変わったのか
kenichiodo
1
210
デザインレビューは自動化できるのか?─ Flutter × Figma で UI 品質保証を考える
techiro
2
720
なぜAI時代に技術記事を書くのか?どう書くのか? 〜bunの場合〜
kworkdev
PRO
0
3.5k
AIコーディングエージェント開発_全体像
happysamurai294
0
150
AIに任せられるFlutterコードベースを作る 〜仕様をコードで表し、ハーネスで守る〜
myohei
1
610
Content Mapper APIの応用例~CSS Modules、言語ファイル~
uhyo
2
490
新米を「売り越さない」、Aurora DSQLで作る在庫ゼロ死守の限定ドロップEC
yama3133
0
140
Featured
See All Featured
First, design no harm
axbom
PRO
2
1.4k
The SEO Collaboration Effect
kristinabergwall1
1
610
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
380
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Why Our Code Smells
bkeepers
PRO
340
58k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Making the Leap to Tech Lead
cromwellryan
135
10k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
290
Code Review Best Practice
trishagee
74
20k
Transcript
`go get`したら ELFが降ってきた件 鹿 @mizushika1
github.com/velox-io/json • Podcast 『八百万のOSS』 #25 「go-jsonはなぜ速いのか」で紹介 • Go の高性能 JSON
ライブラリ • encoding/json 風のAPI • amd64/arm64 ではネイティブで高速 • 作者のベンチマークでは、velox-ioはJSONv2の7%〜41%の処理時間 • さらに、go-jsonよりも速いそう
It uses native acceleration on supported platforms and pure Go
elsewhere • なるほど、cgo で書いてるのかな? • でもなんでプラットフォームが限定?アセンブラ利用? • cloneして中を見ると、ELFバイナリが置いてある % git clone https://github.com/velox-io/json % cd json % find native -name '*.elf' native/encvm/encvm_arm64.elf native/encvm/encvm_amd64.elf native/ndec/ndec_amd64.elf native/ndec/ndec_arm64.elf native/vlib/internal/nativeref/vlib_arm64.elf native/vlib/internal/nativeref/vlib_amd64.elf
ELF (Executable and Linkable Format) • Linux, *BSD などの実行形式 •
macOS (darwin) は Mach-O • じゃあ macOS では native acceleration は出来ない? • 出来ます! • 本当に?
ベンチマーク • 35MBのJSONのUnmarshal を繰り返すbench • go 1.27.3 • github.com/goccy/go-json v0.11.2
• github.com/velox-io/json v0.4.4 • ※入力バッファを流用しない版でそろえた • on Apple M1 MAX MacBook Pro BenchmarkUnmarshalStd-10 BenchmarkUnmarshalGoJSON-10 BenchmarkUnmarshalVeloxCopy-10 • Std -> go-json は x0.25 • Std -> velox-io は x0.15 • 確かに速い 5 220989567 ns/op 166.78 MB/s 168171168 B/op 1326991 allocs/op 21 54326377 ns/op 678.42 MB/s 51958075 B/op 232535 allocs/op 33 32098043 ns/op 1148.23 MB/s 50191388 B/op 9576 allocs/op
仕組み • ELFの実行形式バイナリをembed • cgoではない • 子プロセスではない • プロセスのメモリで直接実行する •
起動時にELFを実行可能メモリへmapする • 利点:Cコンパイラ不要、1バイナリに、OSごとのビルド分け不要 • 疑問:本当に動くの?安全なの?
Unmarshal時の動作イメージ • C製のVMがGoのオブジェク トを直接構築する • 状態はVM内に保存 • メモリ確保などGoにしかで きない処理はyieldしてGo に戻る(回数も最低限に)
• JSONパース中はGo側で到 達可能に保ちGCも安全 • GoのmapのSwiss tableも 直接操作(メモリレイアウト を知ってる)
個人的な疑問 • なぜVMをCで? • フローの精密な制御 • コンパイラ最適化 • なぜ cgo
ではないの? • 利用時にCコンパイラが不要、archが同じならOSやリンカに依存せず使える • (推測)ABI変換切り替えの負荷を避けた?Go側のスタックをC VMから使うため? • なぜ dlopen ではないの? • (推測)cgo前提になるし、OSの作法に縛られるから? • embedしたバイナリを実行できるの? • LinuxではRWでmmap→copy→mprotect(R|X) • darwinではMAP_JITで書き込み、JIT関連の機能を使う • その他、AIに聞いたら工夫が凄すぎた
まとめ • velox-io/json は(作者のベンチマークによると)Go界最速 • ELFバイナリをembed→実行時にメモリにマップ→Goと協調して動作 • 利用者はコンパイルしなくてもネイティブ実行可能 • archごとに一つのELFバイナリで、複数のOSをサポート
(linux/darwin/windows) • 環境依存と互換性リスクが高い • メモリへのマップの仕組みはOS固有 • 実行時のメモリ制約では動かないかも(推測) • Goランタイムの内部レイアウトに依存