Skip to content

mrbrdo/mruby_cc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

bcd47cf · Oct 19, 2014
Mar 6, 2013
Oct 19, 2014
Oct 19, 2014
Oct 19, 2014
Oct 19, 2014
Oct 18, 2014
Oct 14, 2014
Oct 19, 2014
Oct 17, 2014
Dec 9, 2012
Apr 29, 2013
Oct 13, 2014
Oct 13, 2014
Mar 8, 2013
Mar 8, 2013
Oct 3, 2014
Oct 13, 2014
Oct 13, 2014
Oct 13, 2014
Oct 3, 2014
Oct 3, 2014
Oct 19, 2014
Oct 19, 2014
Dec 14, 2012
Oct 19, 2014
Oct 19, 2014
Oct 13, 2014
Mar 6, 2013
Dec 12, 2012

Repository files navigation

What

This enables translating mruby code into C code (not necessarily human readable). The main benefit is increased performance. We cannot achieve performance of real programmer-written C code, but we can improve on performance of interpreted mruby.

Stable enough for testing, but not tested enough for production use.

Install

github.com/mrbrdo/mruby_cc/wiki/Install

Use

echo "puts 'hello world'" > test.rb
./compile test.rb

./runner test.so

Advantages and disadvantages

Advantages

  • improved performance, obviously

  • code is shipped in binary form

    • virtually impossible to get back the original ruby code, because the binary code is compiled from mruby bytecode

    • 3rd party binary obfuscators can be used to make it virtually impossible to recover even the bytecode from which it was compiled

  • output is a C file, which can be manually optimized if necessary (this is an extreme case however)

Disadvantages

  • code is shipped in binary form

    • need to provide precompiled version for each platform, or compile on the fly (currently, this requires gcc or some compiler present on target machine)

    • it is not possible to ensure that the compiled file includes only ruby code, malicious users could include anything - solution is for vendor to oversee user-provided scripts, or to not allow user scripts, also to check CRC of binary to confirm authenticity

  • larger size of binary compared to ruby source file

    • about 300-500KB for typical script

    • compression should be very efficient, especially when compressing multiple files

Dynamic loading of other files

Now it is possible to dynamically load other pre-compiled ruby files.

# some_ruby_file.rb
load_compiled_mrb "dyn.so"

I recommend you use the full file path.

Examples

github.com/mrbrdo/mruby_cc/wiki/Examples

FAQ

github.com/mrbrdo/mruby_cc/wiki/FAQ

Performance

github.com/mrbrdo/mruby_cc/wiki/Performance