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
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
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
190
ぼくの開発環境2026
yuzneri
0
230
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
270
CSC307 Lecture 09
javiergs
PRO
1
840
2026年 エンジニアリング自己学習法
yumechi
0
140
Best-Practices-for-Cortex-Analyst-and-AI-Agent
ryotaroikeda
1
110
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
570
izumin5210のプロポーザルのネタ探し #tskaigi_msup
izumin5210
1
130
CSC307 Lecture 08
javiergs
PRO
0
670
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6.1k
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
430
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
240
Skip the Path - Find Your Career Trail
mkilby
0
56
Claude Code のすすめ
schroneko
67
210k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
117
110k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
230
Building Applications with DynamoDB
mza
96
6.9k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
60
42k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
270
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
62
A better future with KSS
kneath
240
18k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.6k
Documentation Writing (for coders)
carmenintech
77
5.3k
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