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
AOT と direct linking
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
xorphitus
January 26, 2016
Programming
0
77
AOT と direct linking
Clojure 1.8 の新機能である direct linking の解説です。
xorphitus
January 26, 2016
Tweet
Share
More Decks by xorphitus
See All by xorphitus
オリジナリティのあるGitLabを標準に近づける
xorphitus
1
750
マイクロサービスを作ろう
xorphitus
0
150
コンテナ起動への道
xorphitus
0
160
型システムを学ぼうとした結果
xorphitus
0
66
M-x doctor
xorphitus
0
160
型で数を表そう
xorphitus
0
97
CFS入門
xorphitus
0
76
HyperLogLog
xorphitus
0
110
immutable database
xorphitus
0
310
Other Decks in Programming
See All in Programming
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
230
AI巻き込み型コードレビューのススメ
nealle
1
280
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
280
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.6k
余白を設計しフロントエンド開発を 加速させる
tsukuha
7
2.1k
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
130
Architectural Extensions
denyspoltorak
0
290
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
180
Basic Architectures
denyspoltorak
0
670
「ブロックテーマでは再現できない」は本当か?
inc2734
0
1k
Implementation Patterns
denyspoltorak
0
290
AWS re:Invent 2025参加 直前 Seattle-Tacoma Airport(SEA)におけるハードウェア紛失インシデントLT
tetutetu214
2
110
Featured
See All Featured
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
140
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
The Cost Of JavaScript in 2023
addyosmani
55
9.5k
A better future with KSS
kneath
240
18k
The untapped power of vector embeddings
frankvandijk
1
1.6k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
940
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
110
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
170
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
0
3.4k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
120
Transcript
AOT と direct linking @xorphitus (2016-01)
Clojure のコンパイル・モデル 新機能 direct linking の前に Clojure のコンパイル (Java バイトコードへの変換)
は、だいたい2種類 • ソースコードを Clojure の処理系がロードする時に行う ◦ えーと、ここボヤっとしてるんだけど、 JIT ってことなのかなと ◦ ってことは、JVM が JIT しているのでダブル JIT ですね • 先にコンパイルしておいてから処理系に渡す ◦ ahead-of-time compilation (AOT) ◦ direct linking が有効になるのはこっち ※ちなみに、ランタイムにコンパイルを実行する関数も用意されている
JIT vs AOT (Java バイトコードコンパイル時) • JIT の利点 (たぶん) ◦
動的コンパイルが許されるがゆえの REPL 駆動開発 ◦ プログラムが全て REPL の上に乗るので、実際のプロセスの中に入って改変・実行しながら開発が できる ◦ ところで、REPL 駆動駆動って Haskell 辺りとも相性いいと思うのだがどうだろう • AOT の利点 (公式より転載) ◦ ソースコードなしでアプリケーションを配布できる ◦ アプリケーションの起動速度を向上させられる ◦ Java から呼び出し可能な名前付きクラスを生成できる ◦ ランタイムのバイトコード生成と、カスタムクラスローダのどちらも不要なアプリケーションを作れる
JIT vs AOT 体感してみよう • 実演: REPL 駆動開発および速度比較 ◦ https://github.com/xorphitus/aot-experiments
• 参考 ◦ http://qiita.com/ayato_p/items/56595ece48837438d97f ◦ というか、ほぼパクっている
さて、direct linking だが
direct linking とは 三行で言うと • AOT 時のコンパイルオプションで • 関数実行のオーバーヘッドを小さくできて •
コードサイズも削減されて起動速度が上がるもの この理解には、まず Clojure の関数実行の仕組みを知る必要がある
direct linking は Var の存在を消す こんなコードがあったとして (defn add [a b]
(+ a b)) add (λ (+ a b)) シンボル Var 関数 mutable なポインタみたいなもの ポインティング先は immutable 可変ゆえに REPL 駆動開発中は 再定義して動作確認ができる direct linking しない場合は 赤矢印のフローで関数実行される つまり、Var の dereference の コストが発生する direct linking する場合は AOT 時に Var が解決されて 関数実行が青矢印で行われる ついでに不要な Var は一掃され class ファイルは小さくなる
実行してみる • が、コードが小さすぎてぶっちゃけ意味ないかも • direct linking すると JVM の JIT
の最適化がされやすくもなるっぽい
じゃあ Java バイトコードを見よう
Var の減を確認してみる $ find simple-aot/target/classes/simple_aot -type f | xargs javap
| grep Var $ find direct-linking/target/classes/direct_linking -type f | xargs javap | grep Var ちなみに消えない Var もある Var は動的スコープを作ることもできて 例えば、スレッド毎に動的スコープを作り、並行処理を行うのに使われる こういう場合は流石に Var を消したらマズいわけで なお、今回残っている Var が何なのかはよく分からn(ry