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
mruby hacking guide
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
ksss
April 19, 2014
Programming
2k
7
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
mruby hacking guide
大江戸Ruby会議04 Ninja Talks
http://regional.rubykaigi.org/oedo04/
ksss
April 19, 2014
More Decks by ksss
See All by ksss
RaaP
ksss
0
790
Railsの型ファイル自動生成における課題と解決
ksss
4
5.5k
RBS generation framework using Rack architecture
ksss
1
7.9k
mrubyでruby/specを走らせてみた結果www
ksss
1
2.6k
Rubyに型があると便利か
ksss
4
4.8k
A New Testing Framework Rgot
ksss
0
1.3k
Other Decks in Programming
See All in Programming
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
2.8k
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
590
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
140
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
480
Built Our Own Background Agent at LayerX
layerx
PRO
9
5.1k
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
180
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
260
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
460
Jindong: Introducing Declarative Haptics in Compose Multiplatform
l2hyunwoo
0
100
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
180
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
480
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
210
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Agile that works and the tools we love
rasmusluckow
331
22k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
360
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
The browser strikes back
jonoalderson
0
1.5k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
650
We Are The Robots
honzajavorek
0
290
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.8k
The Cost Of JavaScript in 2023
addyosmani
55
10k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
25k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
66
57k
Transcript
mruby hacking guide 第256回 Asakusa.rb 2014/04/19 大江戸Ruby会議04
IUUQJMPWFSVCZOFUKBSIHCPPL w .JOFSP"PLJ w 3VCZJTUͷόΠϒϧ w ճಡ͏ʂʂ
about me { name: "Yuki Kurihara", twitter: "@_ksss_", github: "ksss",
commit: "mruby(59)", since: "Feb 26, 2014" }
生活発表会
3VCZͱͷग़ձ͍ ・phpに危機感 ・そうだ、外へ出よう ・RubyKaigi2013に行ってみる
3VCZͱͷग़ձ͍ ・@_zzakのスピーチに感動 ・完全にRubyにハマる ・ゴミみたいなGemを量産
"TBLVTBSCͱͷग़ձ͍ ・今のおまえに足りないものがある ・危機感だ
"TBLVTBSCͱͷग़ձ͍ ・そうだ、Asakusa.rbへ行こう
"TBLVTBSCͱͷग़ձ͍ ・なんか無言でパチパチしてる
"TBLVTBSCͱͷग़ձ͍ ・みんな好き勝手やっているだけ
"TBLVTBSCͱͷग़ձ͍ ・なんだ、好き勝手やっていいんだ
Gemを量産して わかったこと
Rubyの実装は宝の山
None
Ruby is 21 years old Ruby is 21 years old
Ruby is red ocean Ruby is red ocean
None
mruby is 2 years old mruby is 2 years old
mruby is blue ocean mruby is blue ocean
mruby ・コードが短い ・シンプルで読みやすい ・Matzがcommitしてる
✔ github ✖ mail ✖ redmine IUUQTHJUIVCDPNNSVCZNSVCZ
Let's Hack mruby
VM Object lib Build GC parse.y
“Bad programmers worry about the code. Good programmers worry about
data structures and their relationships.” Linus Torvalds
ʮඞཁͳσʔλߏମʹʯ mrubyの方針 ʮγεςϜʹԿ͔Λڧ੍͠ͳ͍ʯ
「データ構造重要」
VM Object lib Build GC parse.y
RString
RString ptr len capa lNSVCZz 5 5
Hack
RString ptr len capa lNSVCZz 5 5
RString ptr len capa void * void * void *
RVALUE
RString lNSVCZz ptr len capa
RString ptr len capa “ m r u b y
” as.ary[]
RString struct RString { MRB_OBJECT_HEADER; mrb_int len; union { mrb_int
capa; struct mrb_shared_string *shared; } aux; char *ptr; };
RString struct RString { MRB_OBJECT_HEADER; union { struct { mrb_int
len; union { mrb_int capa; struct mrb_shared_string *shared; } aux; char *ptr; } heap; char ary[RSTRING_EMBED_LEN_MAX + 1]; } as; };
Embed-String ・less -10% memory allocs ! でもこれって…… https://github.com/mruby/mruby/pull/1820
CRubyから パクった
͜͜Ͱ͘Β͍
Enumerator
昔のHash#each #call-seq: # hsh.each {|k, v| block} -> hsh #
hsh.each -> an_enumerator def each(&block) self.keys.each{|k| block.call([k, self[k]]) } self end
!?
昔のHash#each #call-seq: # hsh.each {|k, v| block} -> hsh #
hsh.each -> an_enumerator def each(&block) self.keys.each{|k| block.call([k, self[k]]) } self end
Hack
NSVCZFOVNFSBUPS IUUQTHJUIVCDPNLTTTNSVCZFOVNFSBUPS
NHFN IUUQTHJUIVCDPNNSVCZNHFNMJTU IUUQTHJUIVCDPNCPWJNHFN NHFNMJTU
Send Pull Request to mruby/mgem-list
IUUQTHJUIVCDPNNSVCZNHFNMJTUQVMM %JEZPVNJTUBLFSFQPTJUPSZ GPSTFOEJOHQVMMSFRVFTU IUUQTHJUIVCDPNNSVCZNSVCZ
/src/* /mrblib/* /mrbgems/* mgem ISO mgem mgem Ruby互換 Freedom
Send Pull Request to mruby/mruby
Merged IUUQTHJUIVCDPNNSVCZNSVCZQVMM
CRubyから パクった
khash
khash ✔IBTIςʔϒϧ ✔$3VCZͰݴ͏TU@UBCMF ✔IU NU JW OT TU ✔γϯϓϧগϝϞϦ ✔։൪๏
✔
khash n_buckets size n_occupied mask inc upper_bound keys vals ed_flags
kh_*
khash keys vals ed_flags malloc( )
khash keys vals ed_flags n_buckets=2
khash keys vals ed_flags empty del khkey_t khval_t n_buckets=1 1
0 1 0 1 0 1 0
hash[a]=1 a 1 0 1 0 1 0 1 0
hash function empty del
hash[a]=1 a 1 hash function a 1 0 0 0
1 0 1 0 empty del 1
hash[b]=2 b 1 hash function a b 1 0 0
0 0 0 1 0 1 2 empty del
hash[b]=2 b 1 hash function del b 1 0 0
1 0 0 1 0 - 2 empty del
Hack
khash n_buckets size n_occupied mask inc upper_bound keys vals ed_flags
kh_* n_buckets-1 n_buckets/2-1 n_buckets*3/4
khash n_buckets size n_occupied mask inc upper_bound keys vals ed_flags
kh_* n_buckets-1 n_buckets/2-1 n_buckets*3/4
kh_get delを無視 kh_put delを上書き khash
khash hashいくつ? 空だった? うん 3 hashいくつ? 3 空だった? うん そこ入れといて
kh_get kh_put
khash hashいくつ? 空だった? うん 3 hashいくつ? 3 空だった? うん そこ入れといて
khash hashいくつ? 空だった? うん 3 そこ入れといて おっけー kh_put
PRしようとしたら matzに先を越された IUUQTHJUIVCDPNNSVCZNSVCZDPNNJU BFDEBGCDFFBFCEDCECGCDDDFCFE
͜Ε͔ΒͬͯΈ͍ͨ͜ͱ ɾIBTIΛ࿈๏Ͱ࣮ͯ͠ൺֱ ɾWN ($ΛಡΜͰվળ ɾͻͨ͢Βόάফ͠
FOE
Hack