-
Notifications
You must be signed in to change notification settings - Fork 194
Update documentation for native-by-default #1269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
afb4403
Don't build an extra native image in the test Dockerfiles
chrisseaton c890825
Adjust the Dockerfiles for native-by-default.
chrisseaton 61e0f59
Improve the script used to test all Dockerfiles.
chrisseaton a56fd47
Update documentation for native-by-default.
chrisseaton 773d663
Fixes from feedback.
chrisseaton ac18f91
More feedback fixes.
chrisseaton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# Using TruffleRuby with the SVM | ||
|
||
The Substrate Virtual Machine, or SubstrateVM, is a closed- and whole-world | ||
analysis ahead-of-time compiler for Java, and an implementation of parts of a | ||
JVM. | ||
|
||
We use the SVM to ahead-of-time compile TruffleRuby and the Graal dynamic | ||
compiler to a single, statically-linked native binary executable, that has no | ||
dependency on a JVM, and does not link to any JVM libraries. The technique is | ||
more sophisticated than just appending a JAR as a resource in a copy of the JVM - | ||
only parts of the JVM which are needed are included and they are specialised for | ||
how TruffleRuby uses them. There is no Java bytecode - only compiled native | ||
machine code and compiler graphs for dynamic compilation. | ||
|
||
Note that a common confusion is that the SVM is an ahead-of-time compiler for | ||
the Java code that implements the TruffleRuby interpreter and the Graal | ||
compiler, not an ahead-of-time compiler for your Ruby program. | ||
|
||
The SVM itself, like Graal and TruffleRuby, is implemented in Java. | ||
|
||
https://youtu.be/FJY96_6Y3a4?t=10023 | ||
|
||
More information can be found in Kevin's | ||
[blog post](http://nirvdrum.com/2017/02/15/truffleruby-on-the-substrate-vm.html). | ||
|
||
The TruffleRuby that is distributed in the [GraalVM](../user/using-graalvm.md) | ||
by default uses a version compiled using SVM - this is since version 0.33 of | ||
GraalVM and was changed to prioritise fast start-up and warm-up time for shorter | ||
running commands and benchmarks. | ||
|
||
```bash | ||
$ cd graalvm | ||
$ otool -L jre/bin/ruby | ||
jre/bin/ruby: | ||
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1348.28.0) | ||
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0) | ||
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8) | ||
|
||
$ du -h jre/bin/ruby | ||
200M jre/bin/ruby | ||
``` | ||
|
||
The SVM version of TruffleRuby has better startup performance and lower memory | ||
footprint than TruffleRuby or JRuby on the JVM, and better startup performance | ||
than Rubinius. We expect these numbers to improve significantly in the future as | ||
we ahead-of-time compile more of the Ruby startup process, and aim to meet or | ||
beat MRI's startup time. | ||
|
||
| Implementation | Real Time (s) | Max RSS (MB) | | ||
| -------------- | ------------: | -----------: | | ||
| TruffleRuby SVM | 0.10 | 97 | | ||
| TruffleRuby JVM | 2.86 | 272 | | ||
| JRuby 9.1.13.0 | 1.44 | 154 | | ||
| MRI 2.4.2 | 0.03 | 8 | | ||
| Rubinius 3.84 | 0.25 | 65 | | ||
|
||
Run on Linux with an Intel(R) Core(TM) i7-4702HQ CPU @ 2.20GHz. | ||
|
||
```bash | ||
$ export TIME="%e %M" | ||
|
||
$ cd graalvm-0.28 | ||
$ /usr/bin/time bin/ruby --native -e 'puts "Hello"' # TruffleRuby on the SVM | ||
Hello | ||
0.10 99764 | ||
|
||
$ /usr/bin/time bin/ruby --jvm -e 'puts "Hello"' # TruffleRuby on the JVM | ||
Hello | ||
2.86 278240 | ||
|
||
$ chruby jruby-9.1.13.0 | ||
$ /usr/bin/time jruby -e 'puts "Hello"' | ||
Hello | ||
1.44 158080 | ||
|
||
$ chruby ruby-2.4.2 | ||
$ /usr/bin/time ruby -e 'puts "Hello"' | ||
Hello | ||
0.03 8672 | ||
|
||
$ chruby rbx-3.84 | ||
$ /usr/bin/time rbx -e 'puts "Hello"' | ||
Hello | ||
0.25 66824 | ||
``` | ||
|
||
(The first number `real` is the number of actual seconds which have elapsed | ||
while the command runs, and the second `maximum resident set size` is the | ||
maximum amount of memory occupied while the command runs.) | ||
|
||
There is no need to do so, but you can actually also compile your own copy of | ||
the SVM version of TruffleRuby using a tool distributed as part of GraalVM and | ||
the Java version of TruffleRuby from GraalVM. | ||
|
||
``` | ||
$ native-image -H:Name=native-ruby --Language:ruby | ||
``` | ||
|
||
`native-ruby` is the output file name. | ||
|
||
You can build a native image using SVM from a source distribution using: | ||
|
||
``` | ||
$ jt build native | ||
``` | ||
|
||
The disadvantages of the SVM version of TruffleRuby are: | ||
|
||
* It has lower peak performance, as the GC is simpler and some optimisations | ||
such as compressed ordinary object pointers (OOPS) are not yet available. | ||
* You can't use Java interopability. | ||
* You can't use standard Java tools like VisualVM. | ||
|
||
So the SVM version may not be appropriate for all uses. | ||
|
||
For the highest performance for long-running processes you want to use the | ||
JVM version of TruffleRuby, using `--jvm`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this stay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added quite a lot so I wanted to remove some. It's also out of date - support for OpenSSL is not missing. What do you think we should say?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Nokogiri is not fully integrated yet, and database drivers is work-in-progress, so I would keep it and just drop the
OpenSSL
part.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also maybe something about C extensions where not all run out of the box.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing.