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
最速で最速のRuby擴張を作る
Search
さっちゃん
March 23, 2017
Programming
1
1.6k
最速で最速のRuby擴張を作る
CrystalでRubyの擴張を書く
https://github.com/ne-sachirou/sample_ruby_extension_in_crystal
さっちゃん
March 23, 2017
Tweet
Share
More Decks by さっちゃん
See All by さっちゃん
作ってよかったgraceful shutdownライブラリ #kyotogo
ne_sachirou
0
830
path 依存型って何?
ne_sachirou
0
290
野生の onbording と onbording 設計 #kyototechtalk
ne_sachirou
0
470
メトリックはいかにして見え續ける樣になったか #devio2022
ne_sachirou
0
54
名實一致
ne_sachirou
0
560
まかれるあなとみあ ―Mackerel のしくみを理解する 30 分― @ Hatena Engineer Seminar #16
ne_sachirou
0
2.9k
tacit programming : Point-free, Concatenatives & J
ne_sachirou
0
650
Monitoring Containerized Elixir
ne_sachirou
1
810
Let's create stateful systems, by Elixir
ne_sachirou
1
760
Other Decks in Programming
See All in Programming
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
270
雑に思考を整理する技術と効能
konifar
60
29k
Code Reviews
bkuhlmann
4
890
MicrosoftのPlatform Engineeringガイドを読んで実際になにかやってみた
ymd65536
1
400
初心者のためのRubyKaigi入門/RubyKaigi Introduction
a_matsuda
7
990
Komplexe Oberflächen mit SVG und der Web Animation API
joergneumann
0
680
GitHub Actionsで泣かないためにやっておきたい設定 / Recommended GHA settings to avoid crying
pinkumohikan
3
540
if constexpr文はテンプレート世界のラムダ式である
faithandbrave
3
650
1BRC--Nerd Sniping the Java Community
gunnarmorling
0
340
Ruby GitHub Packages
bkuhlmann
0
630
Milestoner
bkuhlmann
1
410
Git Lint
bkuhlmann
4
750
Featured
See All Featured
How GitHub (no longer) Works
holman
304
140k
Side Projects
sachag
451
41k
Building Flexible Design Systems
yeseniaperezcruz
319
37k
5 minutes of I Can Smell Your CMS
philhawksworth
199
19k
Practical Orchestrator
shlominoach
182
9.7k
Web development in the modern age
philhawksworth
202
10k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
21
1.6k
Building Adaptive Systems
keathley
31
1.9k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
244
20k
The Art of Programming - Codeland 2020
erikaheidi
42
12k
Bootstrapping a Software Product
garrettdimon
PRO
302
110k
Web Components: a chance to create the future
zenorocha
305
41k
Transcript
最速で最速の Ruby擴張を作る
.。oO(さっちゃんですよヾ(〃l _ l)ノ゙☆)
Ruby
Ruby 最速で開發出來る⾔語
None
Crystal
Crystal LLVMでcompile出來るRuby-likeな⾔語
Crystal LLVMでcompile出來るRuby-likeな⾔語 Ruby-likeなsyntax 型推論 macroによるDSL Cのlibをそのまま使へる → 最速の開發
Crystal LLVMでcompile出來るRuby-likeな⾔語 型による最適化 LLVMによる最適化 macroによるcompile時計算 Cのlibをover head無く使へる → 最速の實⾏
Rubyの實⾏速度が遅い
Rubyの實⾏速度が遅い ↓ Cで擴張を作る
Rubyの實⾏速度が遅い ↓ Cで擴張を作る ↓ 實⾏速度は速く成ったが 開發速度が遅く成った
Rubyのeco systemに頼りながら 開發速度を落とさず 遲い部分をCrystalで速く出來ないだらうか
既存の試み manastech/crystal_ruby 頑張る前に放棄されてゐる 全然使へない 動かない phoffer/crystalized_ruby 頑張った跡 rb_define_module_function等を⼿動で呼ばなければならない もう動かない
♥ Ruby meets Crystal ♥ ne-sachirou/sample_ruby_extension_in_crystal
ne-sachirou/sample_ruby_extension_in_crystal ruby hello_cr, def hello_cr : Nil puts "Hello, World!”
end hello_cr
ne-sachirou/sample_ruby_extension_in_crystal ruby Fib, module Fib def self.fib_cr(n : Int32) :
Int32 (1..n-1).reduce([1,1]){|ns|[ns[1],ns[0]+ns[1]]}[1] end end p Fib.fib_cr
ne-sachirou/sample_ruby_extension_in_crystal Benchmark 同じalgorithmで、fibonacci數列の31番⽬を100万回計算する def self.fib_rb(n) ns = [1, 1] i
= 1 while i < n ns0 = ns[0] ns[0] = ns[1] ns[1] = ns0 + ns[1] i += 1 end ns[1] end
ne-sachirou/sample_ruby_extension_in_crystal Benchmark 同じalgorithmで、fibonacci數列の31番⽬を100万回計算する C 0.1秒
ne-sachirou/sample_ruby_extension_in_crystal Benchmark 同じalgorithmで、fibonacci數列の31番⽬を100万回計算する C 0.1秒 Ruby 3.0秒
ne-sachirou/sample_ruby_extension_in_crystal Benchmark 同じalgorithmで、fibonacci數列の31番⽬を100万回計算する C 0.1秒 Ruby 3.0秒 Crystal 0.2秒
ne-sachirou/sample_ruby_extension_in_crystal macro ruby(name, code) {{ code }} {% if code.class_name
== "Def" %} Ruby.ruby_def {{ name }}, {{ code }} {% elsif code.class_name == "ModuleDef" %} Ruby.ruby_module_def {{ name }}, {{ code }} {% end %} end LLVMで速いbinaryを作る ⾃動でRubyにmodule/methodを登録する `rake compile`
ne-sachirou/sample_ruby_extension_in_crystal gem化をマテ!