Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
mruby to C parser
Ruby C Shell Prolog
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
build-aux
build-binary
build
mrbcc
mrbcc_mrblib
mruby @ 3f06307
standalone_runner
test
.gitignore
.gitmodules
.ruby-gemset
Cheffile
Cheffile.lock
Gemfile
Gemfile.lock
Makefile.in
README.rdoc
Vagrantfile
compile
configure
configure.ac
crashing_tests.rb
custom_tests.rb
dbg_recompile
failing_tests.rb
passing_tests.rb
run_performance_test.rb
setup.sh
testsuite.rb

README.rdoc

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

Something went wrong with that request. Please try again.