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
AOT と direct linking
Search
xorphitus
January 26, 2016
Programming
92
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AOT と direct linking
Clojure 1.8 の新機能である direct linking の解説です。
xorphitus
January 26, 2016
More Decks by xorphitus
See All by xorphitus
オリジナリティのあるGitLabを標準に近づける
xorphitus
1
800
マイクロサービスを作ろう
xorphitus
0
160
コンテナ起動への道
xorphitus
0
170
型システムを学ぼうとした結果
xorphitus
0
82
M-x doctor
xorphitus
0
180
型で数を表そう
xorphitus
0
110
CFS入門
xorphitus
0
91
HyperLogLog
xorphitus
0
130
immutable database
xorphitus
0
330
Other Decks in Programming
See All in Programming
graphql-ruby を Spinel で速くしようとした話
mtsmfm
0
140
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.3k
Seven New Principles of Software Engineering
yegor256
0
470
Moscow Python Meetup №112. Как поселить ИИ агентов в event driven архитектуре
moscowdjango
PRO
0
110
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
4
1.8k
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
410
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
1.8k
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
290
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
210
Snowflake Openflow Connector利用の勘所 / 20261024developersio2026tokyo-snowflake-openflow
kasacchiful
PRO
0
310
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
240
AI Augmentation Techniques with Liberty
ivargrimstad
1
400
Featured
See All Featured
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
590
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
530
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
570
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
520
The SEO identity crisis: Don't let AI make you average
varn
0
630
Done Done
chrislema
187
17k
Mind Mapping
helmedeiros
1
430
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Being A Developer After 40
akosma
PRO
92
590k
The World Runs on Bad Software
bkeepers
PRO
72
12k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7k
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