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
KaigiEffect.new(name: "dak2").generate
Search
dak2
April 24, 2026
Technology
150
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
KaigiEffect.new(name: "dak2").generate
Lightning Talks on Hakodate Tram at Rub
2026-04-25
RubyKaigi 2026
dak2
April 24, 2026
Transcript
14 slides
KaigiEffect.new(name: "dak2").generate Daichi Kamiyama @_dak2_ Lightning Talks on Hakodate Tram
at RubyKaigi 2026 2026-04-25
Ruby を AOT コンパイル どれくらい速い? spinel で、 公式 Ruby gem
をコンパイルする実験
// test subject ipaddr Ruby 同梱の default gem
// workload 1M 個の IP を CIDR 包含判定 10.0.0.0/8 に入るか?
— 文字列 parse · object 生成 · bit 演算の総合テスト
// benchmark script ipaddr_bench.rb (抜粋) cidr = ipaddr_from_str("10.0.0.0/8") n =
1_000_000 count = 0 i = 0 while i < n addr_int = (i * 2654435761) & 0xffffffff # Knuth hash a = (addr_int >> 24) & 0xff b = (addr_int >> 16) & 0xff c = (addr_int >> 8) & 0xff d = addr_int & 0xff str = a.to_s + "." + b.to_s + "." + c.to_s + "." + d.to_s ip = ipaddr_from_str(str) count = count + 1 if cidr.include?(ip) i = i + 1 end puts "matched: #{count} / #{n}"
2.9x CRuby 3.15s → spinel 1.08s
// 最初に書いた initialize ipaddr_bench.rb class IPAddr def initialize(str) slash =
find_slash(str) # local prefix = str[0, slash] # local prefixlen = str[slash + 1, str.length].to_i # local masklen = 32 - prefixlen # local @addr = parse_ipv4(prefix) # ivar @mask = (0xffffffff >> masklen) << masklen # ivar end end ごく普通の Ruby。 でも、 これが spinel では C コンパイルで死ぬ。
// spinel's convention initialize は 単純代入だけ @foo = foo 以外は書かない
// spinel の内部挙動 initialize から 2 本の C 関数 が生成される
C には overload も継承も無い — 呼ばれ方ごとに別関数にするしかない sp_IPAddr_new ← IPAddr.new("...") · factory (alloc + 初期化) sp_IPAddr_initialize ← class Sub < IPAddr; def initialize ... super(...) · callable spinel_codegen.rb:9677 のコメント: “Initialize function (for super calls)”
// 問題はここ _initialize のループには else 節が無い spinel_codegen.rb:9719 stmts.each { |sid|
if @nd_type[sid] == "InstanceVariableWriteNode" emit_raw(" self->#{ivar} = #{val};") end # ← else 節が無い } ローカル変数代入 · if/else · メソッド呼び出し — 全部 黙って捨てられる
// だから、こうなる Ruby の initialize def initialize(str) slash = find_slash(str)
# 捨てられる prefix = str[0, slash] # 捨てられる prefixlen = str[slash+1, str.length].to_i # 捨てられる masklen = 32 - prefixlen # 捨てられる @addr = parse_ipv4(prefix) # ✓ emit @mask = (0xffffffff >> masklen) << masklen # ✓ emit end 生成された sp_IPAddr_initialize static inline void sp_IPAddr_initialize(sp_IPAddr *self, ...) { self->addr = parse_ipv4(lv_prefix); self->mask = ((4294967295 >> lv_masklen) << lv_masklen); } error: use of undeclared identifier 'lv_prefix' error: use of undeclared identifier 'lv_masklen'
// before → after × 失敗 — parse を初期化内で def
initialize(str) slash = find_slash(str) prefix = str[0, slash] masklen = 32 - prefixlen @addr = parse_ipv4(prefix) @mask = (0xffffffff >> masklen) << masklen end ✓ 成功 — parse は外に出す def initialize(addr, mask) @addr = addr @mask = mask end def ipaddr_from_str(str) # parse して .new(...) に渡す IPAddr.new(addr, mask) end
None
あなた の KaigiEffect は? Thank you · @_dak2_
More Decks by dak2
See All by dak2
我々は何を手放し、何を手放さないのか
dak2
0
58
特殊変数大全
dak2
0
600
登壇その後 - ZJIT への興味とハック
dak2
0
31
現場のトークンマネジメント
dak2
1
340
No Types Needed, Just Callable Method Check
dak2
1
9.4k
MCP Security Best Practices に見るセキュリティリスクとmodelcontextprotocol/ruby-sdk の authorization の現在地
dak2
0
81
自然言語で ActiveRecord を操作する試み
dak2
0
72
DoD x RBS
dak2
0
50
Other Decks in Technology
See All in Technology
プラガブルで宣言的なソフトウェアファクトリーを支えるTypeScript
timakin
5
2.2k
Kiro Enterprise Management: 管理者が 1 か所で決め、全員の Kiro に届ける
inariku
PRO
1
170
Welcome JXL!
dynamis
0
1.3k
【Oracle AI SPOTLIGHT ウェビナー】AI時代、狙われるデータと止められない業務をどう守るか?
oracle4engineer
PRO
1
170
LLMごとの文章力を測ってみた話
yoshimura_datam
0
130
本の挿絵に困ったから挿絵メーカーを自作した
yoshimura_datam
1
140
Ignite 2026 Security
babaneko
0
120
統制されたID・権限をどう利用するか : DPoP/FAPIによるAPIセキュリティ強化
oidfj
2
370
認知の質も文化醸成も。数年取り組んで見えてきた技術広報のKPI設計 / Tech PR KPIs: Lessons on Awareness Quality and Culture After Several Years
bitkey
PRO
0
280
AI時代に問い直す「プロダクションミーティング」の価値 〜チームでサービスの信頼性を高める取り組み〜
mackerelio
0
210
「正しいデータ」の定義をAI エージェントとつくるGoogleADKによるデータ品質定義の実践
takaha4k
0
150
OSSとミニPCと私
anatofuz
1
130
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
ラッコキーワード サービス紹介資料
rakko
5
6.1M
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.5k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.9k
How to Think Like a Performance Engineer
csswizardry
28
3k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
890
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.9k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
590
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
790