4 ms·
Improving TruffleRuby Performance
- jerven 9y agoI am always impressed by the IGV of graal/truffle to see how code is compiled. Really looking forward to JVM-9/JVMCI general availability so it becomes easier to play with truffle.
- bostise 9y agoTruffleRuby looks really promising for those who like Ruby but would also like better performance. Whats the easiest way to install it these days ? Last time I thought of installing it, it required signing up for an account on the Oracle website simply to be allowed to download it, at which point I abandoned my attempt.
- thibaut_barrere 9y agoI think the easiest way so far is still the Oracle website: http://www.oracle.com/technetwork/oracle-labs/program-languages/downloads/index.html http://www.oracle.com/technetwork/oracle-labs/program-langua... It has release 0.23 from a few days ago. I think the home-brew recipe is not so recent (but may be wrong here).
- eregon 9y agoYes, this is quite annoying, we are working on it and there is an issue opened about it: https://github.com/graalvm/truffleruby/issues/118 https://github.com/graalvm/truffleruby/issues/118 It is also possible to build TruffleRuby and Graal entirely from open-source and no sign-up components, but currently this is not so easy as it needs building your own JVM with JVMCI (due to lack of recent OpenJDK releases on linux & macOS).
- misterbowfinger 9y agoI'm kind of confused about the difference between TruffleRuby and JRuby. Are they... using different VMs? If anyone can point to a blog post explaining the difference, that'd be helpful. I'm mainly a Ruby dev and know little about the JVM or GraalVM. Aaaaalso, how does this compare to Eclipse Ruby+OMR? https://github.com/rubyomr-preview/ruby https://github.com/rubyomr-preview/ruby
- nirvdrum 9y agoTruffleRuby and JRuby are two different projects. The history is a bit confusing. TruffleRuby was originally its own project internal to Oracle Labs. It was open-sourced and merged into JRuby as an alternative runtime, called JRuby+Truffle, and shipped with the JRuby 9K releases, activated by a special flag. As JRuby and JRuby+Truffle both kept evolving, it really became two separate projects within the same repository. So, at the end of 2016 we rolled JRuby+Truffle back out of JRuby into its own project, now called TruffleRuby. Both JRuby & TruffleRuby are written in Java and target the JVM. JRuby now has its own IR for performing Ruby-level optimizations and it targets the JVM's invokedynamic system. TruffleRuby uses the Truffle self-optimizing AST framework [1] to implement its runtime and relies on integration with the Graal compiler to produce fast code via partial evaluation. Graal is a new compiler for the JVM written in Java. However, you need a JVMCI-enabled JVM to activate Graal. JVMCI is a new feature in Java 9, but we have a backport package available for Java 8 on the Oracle Technology Network (OTN) [3]. In addition, we ship a package with multiple Truffle languages and a Graal-enabled JVM in a package we call GraalVM. You can download that from OTN as well. That package also ships with a builder for the Substrate VM, which allows you to build an ahead-of-time compiled static binary of the various Truffle languages [4]. So, both JRuby and TruffleRuby target the JVM but they currently use different JITs. There's nothing stopping JRuby from using Graal, and indeed they've been looking at it, but they likely will continue using invokedynamic rather than Truffle. Eclipse Ruby+OMR is a completely different project looking to take some VM components IBM has developed and integrate them with MRI. Since they're actually running MRI rather than a completely new project, they have 100% compatibility with Ruby, but they also have to operate within the confines of MRI's internal design. [1] -- https://github.com/graalvm/graal/tree/master/truffle https://github.com/graalvm/graal/tree/master/truffle [2] -- https://github.com/graalvm/graal/tree/master/compiler https://github.com/graalvm/graal/tree/master/compiler [3] -- http://www.oracle.com/technetwork/oracle-labs/program-languages/downloads/index.html http://www.oracle.com/technetwork/oracle-labs/program-langua... [4] -- http://nirvdrum.com/2017/02/15/truffleruby-on-the-substrate-vm.html http://nirvdrum.com/2017/02/15/truffleruby-on-the-substrate-...
- misterbowfinger 9y agoCool! That was really informative, thank you!
- themgt 9y agoNot knowing the internals of Array#size implementation / Array data structure, but my first thought would be whether Array#empty? could just check for the presence of at least one element (i.e. stop at the first), rather than checking whether the size of a large array is equal to zero.
- nirvdrum 9y agoWhile there's no requirement that a Ruby Array is implemented as an array in the implementation language (C, C++, Java, etc.), in practice it is in all the Ruby implementations. In order to traverse an array, you need to know the length so you can ensure your array index is in bounds. I.e., to read the first element of an array, you'll need to read the size anyway. That being the case, you would want to compare the size to 0 because comparing ints is much faster than reading from memory.