30 ms·
Ruby can’t be compiled easily due to the very dynamic semantics of the language. If you wanted to compile it, it would probably start behaving a lot more like
by chubot 6y ago
Ruby can’t be compiled easily due to the very dynamic semantics of the language. If you wanted to compile it, it would probably start behaving a lot more like Crystal, which looks similar but behaves completely differently.
- gameswithgo 6y agoyou could aot compile most of most programs and jit the rest. or just jit everything
- jashmatthews 6y agoIf you're talking about just compilation then it's easy enough doing something like context-threading where you translate bytecode into a call instruction per operation to a function implementing the bytecode. If you're talking about producing a static binary then both Rubymotion and TruffleRuby can do this.
- chubot 6y agoI should have clarified that I meant "compiled easily for 10-100x speedup" (on representative workloads) as the OP was saying. You can definitely compile anything... whether it's worthwhile is a totally different story. I learned this the hard way :) As far as I remember the Ruby 3x3 effort yielded 3x on SOME workloads, with tremendous effort, which is about what I would have expected due to Ruby's very dynamic semantics.
- jashmatthews 6y agoTruffleRuby already has that kind of performance increase on microbenchmarks. The CRuby JIT for 3x3 built by one person in their spare time.
- FooBarWidget 6y ago> If you're talking about just compilation then it's easy enough doing something like context-threading where you translate bytecode into a call instruction per operation to a function implementing the bytecode. Ruby has already been doing threaded dispatch on bytecodes since 1.9.
- jashmatthews 6y agoContext-threading is a JIT technique. CRuby can optionally use call-threading where each op is a function and dispatch is an infinite loop of function calls. It's not the default since direct or token threading are faster but it's there. Call-threading looks like this: while(1) { interpreter_state = *virtual_program_counter++(interpreter_state); } There's an indirect jump here. With context-threading you JIT very simple code which looks like this and has only direct calls: interpreter_state = put1(interpreter_state); interpreter_state = put1(interpreter_state); interpreter_state = plus(interpreter_state);
- pjmlp 6y agoSELF, Smalltalk beg to differ in what concerns JIT compilation.