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
Kotlin/JS の仕組み / How KotlinJS works
Search
Yuku Kotani
August 24, 2019
Technology
5
3.4k
Kotlin/JS の仕組み / How KotlinJS works
Kotlin Fest 2019の発表資料
Yuku Kotani
August 24, 2019
Tweet
Share
More Decks by Yuku Kotani
See All by Yuku Kotani
一億総業務改善を支える社内AIエージェント基盤の要諦
yukukotani
8
3.2k
MCPとデザインシステムに立脚したデザインと実装の融合
yukukotani
6
2.5k
Scale out your Claude Code ~自社専用Agentで10xする開発プロセス~
yukukotani
10
4.8k
AI Coding Agent Enablement in TypeScript
yukukotani
21
15k
AI Coding Agent Enablement - エージェントを自走させよう
yukukotani
14
8.1k
Expoによるアプリ開発の現在地とReact Server Componentsが切り開く未来
yukukotani
3
790
React 19でお手軽にCSS-in-JSを自作する
yukukotani
6
980
僕が思い描くTypeScriptの未来を勝手に先取りする
yukukotani
12
3.4k
Web技術を駆使してユーザーの画面を「録画」する
yukukotani
14
8k
Other Decks in Technology
See All in Technology
システムのアラート調査をサポートするAI Agentの紹介/Introduction to an AI Agent for System Alert Investigation
taddy_919
0
410
AI時代、1年目エンジニアの悩み
jin4
1
120
AI時代のPMに求められるのは 「Ops」と「Enablement」
shimotaroo
1
480
2026年はチャンキングを極める!
shibuiwilliam
7
1.6k
ドキュメントからはじめる未来のソフトウェア
pkshadeck
4
2k
しろおびセキュリティへ ようこそ
log0417
0
190
GCASアップデート(202510-202601)
techniczna
0
200
toCプロダクトにおけるAI機能開発のしくじりと学び / ai-product-failures-and-learnings
rince
6
4.3k
Werner Vogelsが14年間 問い続けてきたこと
yusukeshimizu
2
260
新規事業 toitta におけるAI 機能評価の話 / AI Feature Evaluation in toitta
pokutuna
0
280
人はいかにして 確率的な挙動を 受け入れていくのか
vaaaaanquish
4
3.1k
Vitest Highlights in Angular
rainerhahnekamp
0
110
Featured
See All Featured
エンジニアに許された特別な時間の終わり
watany
106
230k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
86
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
120
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
110
WENDY [Excerpt]
tessaabrams
9
36k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
55
49k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
0
300
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
190
My Coaching Mixtape
mlcsv
0
41
Amusing Abliteration
ianozsvald
0
90
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Transcript
Kotlin/JS の仕組み Kotlin Fest 2019
自己紹介 - 名前: 小谷 優空 (Yuku Kotani) - GitHub: @Monchi
- Twitter: @MonchiFC - 所属: Ubie, Everforth, 筑波大学情報科学類 - Kontributor 2
コンパイルの流れ
謎のコンパイラ コンパイルの流れ 4 CLI kotlin-gradle-plugin JVM JavaScript Native(LLVM) 出力
コンパイルの流れ 5 CLI kotlin-gradle-plugin JVM JavaScript Native(LLVM) AST (PSI) Kotlin
コード コンパイラ 出力 IR (中間表現)
コンパイルの流れ 6 CLI kotlin-gradle-plugin JVM JavaScript Native(LLVM) AST (PSI) Kotlin
コード コンパイラ 出力 参照 コンパイル先に関わらず Kotlinコードとして 参照、操作できる! IR (中間表現)
コンパイルの流れ 7 CLI kotlin-gradle-plugin JVM JavaScript Native(LLVM) AST (PSI) Kotlin
コード コンパイラ 出力 IR (中間表現)
Kotlin/JS変換の工夫
Dead Code Elimination - Tree Shakingとも言う - 使われていない関数やプロパティ、クラスを削除 - KotlinのIRも参照する
- JSにしてからwebpackとか使うより精度がいい 9
結局バンドルサイズどうなの?
Dead Code Elimination - 単純なTodoMVCアプリケーションをDCE 1922KB -> 416KB - minifyすると更に
198KB に - gzipすると更に 45KB に - webpackのTree Shakingも重ねがけでもっと減らせそう 11
型変換 - KotlinからJavaScriptに型変換 String -> string Int -> number Any
-> {} クラス -> prototypeでよしなに 12
型変換 - 型付き配列 - 型に応じて [], Int8Array, Int16Array... に変換 -
Long(64bit整数) - JavaScriptは53bit整数までしか扱えない - 内部的にエミュレートするKotlin.Longクラスに変換 13
モジュール 14 - JavaScriptには様々なモジュール管理方法がある - Kotlin/JSもそれに合わせて色々吐ける - plain: そのままブラウザで動く -
commonjs, amd: webpackとかでバンドルする - umd: 上2つのハイブリッド
moduleKind = plain の場合
moduleKind = plain の場合 グローバル変数として定義
moduleKind = plain の場合 - モジュールシステムを使わない - ブラウザでそのまま動く - 依存順を意識してロードする必要がある
moduleKind = commonjs の場合
moduleKind = commonjs の場合 require()でロード
moduleKind = commonjs の場合 - Node.jsのモジュールシステム - Webpackなどでバンドルする必要がある - 最適化の余地がある
- ライブラリとして他から読み込める(JSからも!)
Kotlin/JSすげー! もっと知りてー!
Deep Dive into Kotlin/JS 22
Deep Dive into Kotlin/JS 23 激アツリポジトリ
Deep Dive into Kotlin/JS 24 https://github.com/JetBrains/kotlin/tree /master/compiler/ir/backend.js 信じられるのはソースコードだけ
25 ありがとうございました Kotlinかわいい!