SlideShare a Scribd company logo
1 of 35
Download to read offline
mruby can be more
lightweight
2018-06-01 RubyKaigi 2018
Yurie Yamane
Team Yamanekko
About me
• yurie yamane
• Team yamanekko
• GitHub: https://github.com/yamanekko
• Qiita: https://qiita.com/yamanekko
• a member of Toppers project
• a staff of SWEST
(Summer Workshop on Embedded System Technologies)
https://swest.toppers.jp/
TOPAME
matz
About me
• smaller mruby
• low cost microcomputer
• IDE for mruby(VS Code)
• porting nomitory to VS Code
• DEMO
• mruby for ET robot contest
sponsors
wanted!
Today's topic
• how to make mruby smaller
• why?
• how?
Why?
price RAM ROM mruby
LEGO
MindStorms
60,000yen 64MB 16MB OK
GR-PEACH 10,000yen 10MB 8MB OK
nucleo
F412ZG
3,000yen 256KB 1024KB OK
nucleo
F411RE
2,000yen 128KB 512KB OK
Arduino uno 3,000yen 2KB 32KB NG
porting microcomputers
ref)
F411RE or F401RE
F411RE F401RE
RAM:96KB
ROM:512KB
RAM:128KB
ROM:512KB
How?
how to reduce
A
B
C
reduce RAM
use ROM
tuning by #define
change
implementation
RAM size
0
40000
80000
120000
160000
default A B and C
66919
82783
152829
• DEMO
Assigned symbols to ROM
• why method definition in RAM?
RAM
Assigned symbols to ROM
predefined 
method RAM
ROM
predefined 
method
 method
 method
RAM
Assigned symbols to ROM
symbol
symbol
RAM
ROM
predefined 
method
 method
symbol
symbol
predefined 
method
 method
RAM
RAM
ROM
Assigned symbols to ROM
khash
 method
khash
 method
 method
method table
struct RClass {

MRB_OBJECT_HEADER;

struct iv_tbl *iv;

struct kh_mt *mt;

struct RClass *super;

};
RClass
RAM
method table
keys
vals
typedef struct kh_mt{

khint_t n_buckets;

khint_t size;

khint_t n_occupied;

uint8_t *ed_flags;

mrb_sym *keys;

mrb_method_t *vals;

} kh_mt_t;
ed_flags
buckets
https://tatsu-zine.com/books/ruby-under-a-microscope-ja
"Ruby Under a Microscope"
method table
RClass
mt2
struct RClass {

MRB_OBJECT_HEADER;

struct iv_tbl *iv;

struct kh_mt *mt;

#ifdef USE_PRESYM

struct method_table *mt2;

#endif

struct RClass *super;

};
hash vs array
keys
vals
Array
RAM
ROM struct method_table{

  mrb_sym sym;

  mrb_method_t method;

};
typedef struct kh_mt{

khint_t n_buckets;

khint_t size;

khint_t n_occupied;

uint8_t *ed_flags;

mrb_sym *keys;

mrb_method_t *vals;

} kh_mt_t;

ed_flags
buckets
sym
method
Ruby method to C function
• Ex.String class
String class
to_i mrb_str_to_i
upcase mrb_str_upcase
length mrb_str_size
reverse mrb_str_reverse
size mrb_str_size
mrb_define_method(mrb, a, "size",mrb_str_size, MRB_ARGS_NONE());
Ruby method to C function
• perf
method name id
to_i 290
upcase 298
length 212
reverse 259
size 271
id function name
290 mrb_str_to_i
298 mrb_str_upcase
212 mrb_str_size
259 mrb_str_reverse
271 mrb_str_size
extract symbols
• *.c
• intern literal
• method
• const
• global const
• class
• module
• class method
• *.rb
• def
• class
mrb_intern_lit(mrb, "to_a")

mrb_define_class(mrb, "Array", mrb->object_class);

mrb_define_method(mrb, a, "+", mrb_ary_plus, MRB_ARGS_REQ(1));

mrb_define_method(mrb, a, "size",mrb_ary_size, MRB_ARGS_NONE());
class Foo

def foo

(...)

end

end
ROM
mrb_method_search_vm
Dynamically added methods
are defined here
 method
RAM
khash
 method
irep_remove_lv
remove local variable's names
• make bytecode without irep->lv
static void

irep_remove_lv(mrb_state *mrb, mrb_irep *irep)

{

int i;

if (irep->lv) {

mrb_free(mrb, irep->lv);

irep->lv = NULL;

}

for (i = 0; i < irep->rlen; ++i) {

irep_remove_lv(mrb, irep->reps[i]);

}

}
khash size
• KHASH_DEFAULT_SIZE 4
• KHASH_MIN_SIZE
#ifndef KHASH_DEFAULT_SIZE

# define KHASH_DEFAULT_SIZE 32

#endif

#define KHASH_MIN_SIZE 8
# define KHASH_DEFAULT_SIZE 4
#ifndef KHASH_DEFAULT_SIZE

# define KHASH_DEFAULT_SIZE 32

#endif

#define KHASH_MIN_SIZE 4
others
delete -g option
• mrbc.compile_options = "-g -B%{funcname} -o-"
• MRB_USE_ETEXT_EDATA
mrbconf.md
. = ALIGN(4);

_etext = .; /* define a global symbols at end of code
*/

} >FLASH
{

. = ALIGN(4);

_sdata = .; /* create a global symbol at data start */

*(.data) /* .data sections */

*(.data*) /* .data* sections */

. = ALIGN(4);

_edata = .; /* define a global symbol at data end */

} >RAM AT> FLASH
• MRB_HEAP_PAGE_SIZE
• Specifies number of `RBasic` per each heap
page.
• MRB_WORD_BOXING
• If defined represent `mrb_value` as a word.
• If defined `Float` will be a mruby object with
`RBasic`.
• MRB_STR_BUF_MIN_SIZE
• Specifies initial capacity of `RString` created
by `mrb_str_buf_new` function. mrbconf.md
Future works
RClass
mt2 to iv
RClass
struct RClass {

MRB_OBJECT_HEADER;

struct iv_tbl *iv;

struct kh_mt *mt;

#ifdef USE_PRESYM

struct method_table *mt2;

#endif

struct RClass *super;

};
iv
mt2
iv
mt2
• Implementation to unsupported class
• known bug
• "remove_method" can't remove method on
ROM
🙀
Thanks

More Related Content

Similar to mruby can be more lightweight

视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)Night Sailer
 
MongoDB开发应用实践
MongoDB开发应用实践MongoDB开发应用实践
MongoDB开发应用实践iammutex
 
Information from pixels
Information from pixelsInformation from pixels
Information from pixelsDave Snowdon
 
reading suture
reading suturereading suture
reading suturetreby
 
Processing Large Graphs
Processing Large GraphsProcessing Large Graphs
Processing Large GraphsNishant Gandhi
 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++Mike Acton
 
MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?Joshua Ballanco
 
Postgres for MySQL (and other database) people
Postgres for MySQL (and other database) peoplePostgres for MySQL (and other database) people
Postgres for MySQL (and other database) peopleCommand Prompt., Inc
 
Invitation to the dark side of Ruby
Invitation to the dark side of RubyInvitation to the dark side of Ruby
Invitation to the dark side of RubySATOSHI TAGOMORI
 
What's new in Redis v3.2
What's new in Redis v3.2What's new in Redis v3.2
What's new in Redis v3.2Itamar Haber
 
Gopher in performance_tales_ms_go_cracow
Gopher in performance_tales_ms_go_cracowGopher in performance_tales_ms_go_cracow
Gopher in performance_tales_ms_go_cracowMateuszSzczyrzyca
 
Git - Some tips to do it better
Git - Some tips to do it betterGit - Some tips to do it better
Git - Some tips to do it betterJonas De Smet
 
Dragon Ruby 孩子的游戏编程.pdf
Dragon Ruby 孩子的游戏编程.pdfDragon Ruby 孩子的游戏编程.pdf
Dragon Ruby 孩子的游戏编程.pdfEric Guo
 
Lessons learned while building Omroep.nl
Lessons learned while building Omroep.nlLessons learned while building Omroep.nl
Lessons learned while building Omroep.nlbartzon
 
OSインストーラーの自作方法
OSインストーラーの自作方法OSインストーラーの自作方法
OSインストーラーの自作方法LINE Corporation
 
5 NoSQL Options - Toronto - May 2018
5 NoSQL Options - Toronto - May 20185 NoSQL Options - Toronto - May 2018
5 NoSQL Options - Toronto - May 2018Matthew Groves
 

Similar to mruby can be more lightweight (20)

遇見 Ruby on Rails
遇見 Ruby on Rails遇見 Ruby on Rails
遇見 Ruby on Rails
 
视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)
 
MongoDB开发应用实践
MongoDB开发应用实践MongoDB开发应用实践
MongoDB开发应用实践
 
Information from pixels
Information from pixelsInformation from pixels
Information from pixels
 
reading suture
reading suturereading suture
reading suture
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Processing Large Graphs
Processing Large GraphsProcessing Large Graphs
Processing Large Graphs
 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++
 
MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?
 
Postgres for MySQL (and other database) people
Postgres for MySQL (and other database) peoplePostgres for MySQL (and other database) people
Postgres for MySQL (and other database) people
 
Invitation to the dark side of Ruby
Invitation to the dark side of RubyInvitation to the dark side of Ruby
Invitation to the dark side of Ruby
 
What's new in Redis v3.2
What's new in Redis v3.2What's new in Redis v3.2
What's new in Redis v3.2
 
Gopher in performance_tales_ms_go_cracow
Gopher in performance_tales_ms_go_cracowGopher in performance_tales_ms_go_cracow
Gopher in performance_tales_ms_go_cracow
 
Git - Some tips to do it better
Git - Some tips to do it betterGit - Some tips to do it better
Git - Some tips to do it better
 
RubyGems 3 & 4
RubyGems 3 & 4RubyGems 3 & 4
RubyGems 3 & 4
 
Dragon Ruby 孩子的游戏编程.pdf
Dragon Ruby 孩子的游戏编程.pdfDragon Ruby 孩子的游戏编程.pdf
Dragon Ruby 孩子的游戏编程.pdf
 
Lessons learned while building Omroep.nl
Lessons learned while building Omroep.nlLessons learned while building Omroep.nl
Lessons learned while building Omroep.nl
 
OSインストーラーの自作方法
OSインストーラーの自作方法OSインストーラーの自作方法
OSインストーラーの自作方法
 
5 NoSQL Options - Toronto - May 2018
5 NoSQL Options - Toronto - May 20185 NoSQL Options - Toronto - May 2018
5 NoSQL Options - Toronto - May 2018
 

More from yamanekko

Model2code mruby 2018
Model2code mruby 2018Model2code mruby 2018
Model2code mruby 2018yamanekko
 
Ev3rt and mruby-ev3rt 2018ver
Ev3rt and mruby-ev3rt 2018verEv3rt and mruby-ev3rt 2018ver
Ev3rt and mruby-ev3rt 2018veryamanekko
 
Rubykaigi2016 High Tech Seat in mruby
Rubykaigi2016 High Tech Seat in mrubyRubykaigi2016 High Tech Seat in mruby
Rubykaigi2016 High Tech Seat in mrubyyamanekko
 
Domo Arigato, Mr(uby) Roboto
Domo Arigato, Mr(uby) RobotoDomo Arigato, Mr(uby) Roboto
Domo Arigato, Mr(uby) Robotoyamanekko
 
RubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mrubyRubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mrubyyamanekko
 
mrubyでETロボコンに出よう
mrubyでETロボコンに出ようmrubyでETロボコンに出よう
mrubyでETロボコンに出ようyamanekko
 
Writing mruby Debugger
Writing mruby DebuggerWriting mruby Debugger
Writing mruby Debuggeryamanekko
 
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)yamanekko
 
ルネサスナイト
ルネサスナイトルネサスナイト
ルネサスナイトyamanekko
 
Tokyurubykaigi05
Tokyurubykaigi05Tokyurubykaigi05
Tokyurubykaigi05yamanekko
 
使用Eclipse快樂的mruby開發
使用Eclipse快樂的mruby開發使用Eclipse快樂的mruby開發
使用Eclipse快樂的mruby開發yamanekko
 
RubyConfの話の続きのおはなし
RubyConfの話の続きのおはなしRubyConfの話の続きのおはなし
RubyConfの話の続きのおはなしyamanekko
 

More from yamanekko (12)

Model2code mruby 2018
Model2code mruby 2018Model2code mruby 2018
Model2code mruby 2018
 
Ev3rt and mruby-ev3rt 2018ver
Ev3rt and mruby-ev3rt 2018verEv3rt and mruby-ev3rt 2018ver
Ev3rt and mruby-ev3rt 2018ver
 
Rubykaigi2016 High Tech Seat in mruby
Rubykaigi2016 High Tech Seat in mrubyRubykaigi2016 High Tech Seat in mruby
Rubykaigi2016 High Tech Seat in mruby
 
Domo Arigato, Mr(uby) Roboto
Domo Arigato, Mr(uby) RobotoDomo Arigato, Mr(uby) Roboto
Domo Arigato, Mr(uby) Roboto
 
RubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mrubyRubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mruby
 
mrubyでETロボコンに出よう
mrubyでETロボコンに出ようmrubyでETロボコンに出よう
mrubyでETロボコンに出よう
 
Writing mruby Debugger
Writing mruby DebuggerWriting mruby Debugger
Writing mruby Debugger
 
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)
 
ルネサスナイト
ルネサスナイトルネサスナイト
ルネサスナイト
 
Tokyurubykaigi05
Tokyurubykaigi05Tokyurubykaigi05
Tokyurubykaigi05
 
使用Eclipse快樂的mruby開發
使用Eclipse快樂的mruby開發使用Eclipse快樂的mruby開發
使用Eclipse快樂的mruby開發
 
RubyConfの話の続きのおはなし
RubyConfの話の続きのおはなしRubyConfの話の続きのおはなし
RubyConfの話の続きのおはなし
 

Recently uploaded

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Recently uploaded (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

mruby can be more lightweight

  • 1. mruby can be more lightweight 2018-06-01 RubyKaigi 2018 Yurie Yamane Team Yamanekko
  • 2. About me • yurie yamane • Team yamanekko • GitHub: https://github.com/yamanekko • Qiita: https://qiita.com/yamanekko • a member of Toppers project • a staff of SWEST (Summer Workshop on Embedded System Technologies) https://swest.toppers.jp/ TOPAME matz
  • 3. About me • smaller mruby • low cost microcomputer • IDE for mruby(VS Code) • porting nomitory to VS Code • DEMO • mruby for ET robot contest sponsors wanted!
  • 4. Today's topic • how to make mruby smaller • why? • how?
  • 6. price RAM ROM mruby LEGO MindStorms 60,000yen 64MB 16MB OK GR-PEACH 10,000yen 10MB 8MB OK nucleo F412ZG 3,000yen 256KB 1024KB OK nucleo F411RE 2,000yen 128KB 512KB OK Arduino uno 3,000yen 2KB 32KB NG porting microcomputers ref)
  • 7. F411RE or F401RE F411RE F401RE RAM:96KB ROM:512KB RAM:128KB ROM:512KB
  • 9. how to reduce A B C reduce RAM use ROM tuning by #define change implementation
  • 13. • why method definition in RAM?
  • 14. RAM Assigned symbols to ROM predefined  method RAM ROM predefined  method  method  method
  • 15. RAM Assigned symbols to ROM symbol symbol RAM ROM predefined  method  method symbol symbol predefined  method  method
  • 16. RAM RAM ROM Assigned symbols to ROM khash  method khash  method  method
  • 17. method table struct RClass { MRB_OBJECT_HEADER; struct iv_tbl *iv; struct kh_mt *mt; struct RClass *super; }; RClass
  • 18. RAM method table keys vals typedef struct kh_mt{ khint_t n_buckets; khint_t size; khint_t n_occupied; uint8_t *ed_flags; mrb_sym *keys; mrb_method_t *vals; } kh_mt_t; ed_flags buckets https://tatsu-zine.com/books/ruby-under-a-microscope-ja "Ruby Under a Microscope"
  • 19. method table RClass mt2 struct RClass { MRB_OBJECT_HEADER; struct iv_tbl *iv; struct kh_mt *mt; #ifdef USE_PRESYM struct method_table *mt2; #endif struct RClass *super; };
  • 20. hash vs array keys vals Array RAM ROM struct method_table{   mrb_sym sym;   mrb_method_t method; }; typedef struct kh_mt{ khint_t n_buckets; khint_t size; khint_t n_occupied; uint8_t *ed_flags; mrb_sym *keys; mrb_method_t *vals; } kh_mt_t; ed_flags buckets sym method
  • 21. Ruby method to C function • Ex.String class String class to_i mrb_str_to_i upcase mrb_str_upcase length mrb_str_size reverse mrb_str_reverse size mrb_str_size mrb_define_method(mrb, a, "size",mrb_str_size, MRB_ARGS_NONE());
  • 22. Ruby method to C function • perf method name id to_i 290 upcase 298 length 212 reverse 259 size 271 id function name 290 mrb_str_to_i 298 mrb_str_upcase 212 mrb_str_size 259 mrb_str_reverse 271 mrb_str_size
  • 23. extract symbols • *.c • intern literal • method • const • global const • class • module • class method • *.rb • def • class mrb_intern_lit(mrb, "to_a") mrb_define_class(mrb, "Array", mrb->object_class); mrb_define_method(mrb, a, "+", mrb_ary_plus, MRB_ARGS_REQ(1)); mrb_define_method(mrb, a, "size",mrb_ary_size, MRB_ARGS_NONE()); class Foo def foo (...) end end
  • 24. ROM mrb_method_search_vm Dynamically added methods are defined here  method RAM khash  method
  • 26. remove local variable's names • make bytecode without irep->lv static void irep_remove_lv(mrb_state *mrb, mrb_irep *irep) { int i; if (irep->lv) { mrb_free(mrb, irep->lv); irep->lv = NULL; } for (i = 0; i < irep->rlen; ++i) { irep_remove_lv(mrb, irep->reps[i]); } }
  • 27. khash size • KHASH_DEFAULT_SIZE 4 • KHASH_MIN_SIZE #ifndef KHASH_DEFAULT_SIZE # define KHASH_DEFAULT_SIZE 32 #endif #define KHASH_MIN_SIZE 8 # define KHASH_DEFAULT_SIZE 4 #ifndef KHASH_DEFAULT_SIZE # define KHASH_DEFAULT_SIZE 32 #endif #define KHASH_MIN_SIZE 4
  • 29. delete -g option • mrbc.compile_options = "-g -B%{funcname} -o-"
  • 30. • MRB_USE_ETEXT_EDATA mrbconf.md . = ALIGN(4); _etext = .; /* define a global symbols at end of code */ } >FLASH { . = ALIGN(4); _sdata = .; /* create a global symbol at data start */ *(.data) /* .data sections */ *(.data*) /* .data* sections */ . = ALIGN(4); _edata = .; /* define a global symbol at data end */ } >RAM AT> FLASH
  • 31. • MRB_HEAP_PAGE_SIZE • Specifies number of `RBasic` per each heap page. • MRB_WORD_BOXING • If defined represent `mrb_value` as a word. • If defined `Float` will be a mruby object with `RBasic`. • MRB_STR_BUF_MIN_SIZE • Specifies initial capacity of `RString` created by `mrb_str_buf_new` function. mrbconf.md
  • 33. RClass mt2 to iv RClass struct RClass { MRB_OBJECT_HEADER; struct iv_tbl *iv; struct kh_mt *mt; #ifdef USE_PRESYM struct method_table *mt2; #endif struct RClass *super; }; iv mt2 iv mt2
  • 34. • Implementation to unsupported class • known bug • "remove_method" can't remove method on ROM 🙀