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
110
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
More Decks by dak2
See All by dak2
特殊変数大全
dak2
0
12
登壇その後 - ZJIT への興味とハック
dak2
0
12
現場のトークンマネジメント
dak2
1
280
No Types Needed, Just Callable Method Check
dak2
1
8.9k
MCP Security Best Practices に見るセキュリティリスクとmodelcontextprotocol/ruby-sdk の authorization の現在地
dak2
0
70
自然言語で ActiveRecord を操作する試み
dak2
0
65
DoD x RBS
dak2
0
35
Other Decks in Technology
See All in Technology
AIネイティブプロダクトで顧客価値を最大化するプロダクトエンジニアとFDEの協働
righttouch
PRO
0
310
range over func 2年間の軌跡 Issue #56413 はGoのエコシステムをどう変えたか
ryujicre8ive
0
190
Minecraft JavaのMODをSwiftで作る
1mash0
0
160
なぜ「決定性」が 決定的に重要なのか? Durable Execution 基盤の数理的理解 #serverlessjp / ServerlessDays Tokyo 2026
ytaka23
0
140
GoにおけるFFIのこれまでとこれから
goccy
5
3.5k
目の前の楽しいが人生を変える - コミュニティの螺旋の歩き方と楽しむコツ / change your life
soudai
PRO
4
620
The Agent Builder Loop from Daily Work to OSS
minorun365
PRO
3
200
Reactの設計論
uhyo
24
13k
人間はどの意思決定を手放せるのか
kawasima
14
6.9k
あるけみー式LTスライド作成術
alchemy1115
1
210
事業課題から技術的負債に向き合う
sansantech
PRO
2
1.8k
Omarchy Quattro の日本語設定周り
simosako
2
180
Featured
See All Featured
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
500
The World Runs on Bad Software
bkeepers
PRO
72
12k
HDC tutorial
michielstock
2
870
Are puppies a ranking factor?
jonoalderson
2
3.9k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.8k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
410
The Curse of the Amulet
leimatthew05
3
14k
Ethics towards AI in product and experience design
skipperchong
2
370
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Ruling the World: When Life Gets Gamed
codingconduct
0
330
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
590
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.2k
Transcript
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_