C
Charles Nutter
blog.headius.com · Personal blog · on HN since 2008
Charles Nutter (headius), a JRuby lead, writes about Ruby implementation, JVM optimization, and invokedynamic.
What HN saysCommenters cite his posts on why Ruby features like refinements are hard to optimize and call them great articles on language optimization.
74HN people shared it
45linked it in comments
63stories submitted
1.9Kstory points
1 year agolast shared
2008people per year2026
Most-shared posts
- 1Refining Ruby9 people · 168 points · first shared 2012 · 54 comments on HN
- 2How JRuby Makes Ruby Fast6 people · 9 points · first shared 2009 · discussion on HN
- 3A First Taste of InvokeDynamic5 people · 9 points · first shared 2008 · 2 comments on HN
- 4So You Want To Optimize Ruby4 people · 126 points · first shared 2012 · 39 comments on HN
- 5On Languages, VMs, Optimization, and the Way of the World4 people · 93 points · first shared 2013 · 29 comments on HN
- 6Invokedynamic in JRuby: Constant Lookup3 people · 34 points · first shared 2011 · 8 comments on HN
- 7Avoiding hash lookups in a Ruby implementation3 people · 15 points · first shared 2012 · 1 comments on HN
- 8Kicking JRuby Performance Up a Notch3 people · 3 points · first shared 2010 · discussion on HN
- 9JRuby Nailgun Support in 1.33 people · 1 points · first shared 2009 · 1 comments on HN
- 10My Thoughts on Oracle v Google2 people · 606 points · first shared 2010 · 82 comments on HN
- 11JRuby Creator's Short List of Key Missing JVM Features2 people · 124 points · first shared 2010 · 37 comments on HN
- 12Q/A: What Thread-safe Rails Means2 people · 29 points · first shared 2008 · 3 comments on HN
- 13BiteScript: Ruby DSL for generating JVM bytecode2 people · 18 points · first shared 2009 · 1 comments on HN
- 14On Benchmarking: with relation to MacRuby benchmarks2 people · 11 points · first shared 2009 · discussion on HN
- 15Busy Week: JRuby with Android, Maven, Rake, C exts, and More2 people · 8 points · first shared 2010 · 1 comments on HN
What HN people wrote when they linked it
pjungwir · 2016-02-11
I remember this blog post about how optimizing method calls becomes much harder with refinements (from MRI Ruby 2.1):
http://blog.headius.com/2012/11/refining-ruby.html
It looks like JRuby has refinements now but maybe not great support for them (based on just some quick Googling):
https://github.com/jruby/jruby/issues/1062
So I'm curious if anything tested in the article has refinements support.
Personally I'm still skeptical of refinements, but I guess JRuby will have to support them or more and more gems will start to break.
shanemhansen · 2014-11-18
You are technically correct. A Sufficiently Smart Compiler(TM) could theoretically optimize python code.
However certain language features can be inherently difficult to optimize. Most of it's over my head, but headius has written some great articles as part of his experience of implementing ruby on the jvm. http://blog.headius.com/2012/09/avoiding-hash-lookups-in-ruby.html
xxgreg · 2013-05-23
Sure, take all benchmarks with a grain of salt.
However it's worth noting that deltablue has been used to benchmark polymorphism in Smalltalk, Self, the JVM, and V8.
Some of Nickolay's numbers are from a version of the code written at Sun labs, presumably for the very purpose of benchmarking the JVM.
I think it's safe to conclude that in many cases the DartVM already performs similarly to the JVM, albeit with a much better start up time.
Charles Nutter has some interesting follow up comments here:
http://blog.headius.com/2013/05/on-languages-vms-optimization-and-way.…
Basically concluding that it's not static typing that matters, but predictable types.
amalag · 2013-02-06
http://blog.headius.com/2009/04/how-jruby-makes-ruby-fast.html
At least once a year there's a maelstrom of posts about a new Ruby implementation with stellar numbers. These numbers are usually based on very early experimental code, and they are rarely accompanied by information on compatibility. And of course we love to see crazy performance numbers, so many of us eat this stuff up.
octo_t · 2013-01-31
The hotspot inliner gives up after only 35 bytes (http://blog.headius.com/2009/01/my-favorite-hotspot-jvm-flags.html)
StefanKarpinski · 2012-12-02
The namespace mechanism was only added a few months ago and we're still working out some of the kinks with how it works. The plan going forward is to slice Base into an organized hierarchy but still have everything available by default without too many imports. The "using" keyword works rather similarly to the same keyword in C++ and now in Ruby 2.0 [1], and aims to give the best of both the "single huge namespace" (C, PHP, Matlab) and many small namespaces approaches (Python, Java).
[1] http://blog.headius.com/2012/11/refining-ruby.html
rohitarondekar · 2012-11-02
(1) Syntax wise Ruby is a lot easier and more expressive than Scala. IMHO I feel that Ruby is an OO language with some functional sprinkles while Scala is a functional language with OO sprinkles.
(2) Ruby has a great ecosystem if you are building web apps. It's also got a lot of testing libraries. :) But in seriousness the number of libraries in non web/tooling space is slowly increasing as faster Ruby implementations have become a focus point. Also JRuby allows you use the vast ecosystem of Java from within JRuby.
(3) Performance wise I'm pretty sure Scala will outperform Ruby. I don't think JRuby will be able to compete either. Charles Nutter, JRuby Core developer wrote this blog post which explains why Ruby is hard to optimize ― http://blog.headius.com/2012/10/so-you-want-to-optimize-ruby.html
Of course take everything I've said with a bag of salt! :)
GlennS · 2011-10-17
I quite enjoy these:
http://ayende.com/blog (.NET centric, writes RavenDB/NHibernate Profiler)
http://blog.headius.com/ (JRuby creator)
dminor · 2011-08-26
Charles Nutter has a great writeup from a few years ago of how invokedynamic is helpful for JRuby:
http://blog.headius.com/2008/09/first-taste-of-invokedynamic.html
devmonk · 2010-10-12
From what I've understood, Sun didn't license everything to IBM (or for that matter, to others as you stated). Charles Nutter had a great post (and it has been updated) on the Oracle suit against Google where he talks about some of the wild claims that Oracle was making:
http://blog.headius.com/2010/08/my-thoughts-on-oracle-v-google.html
My point is that no rational company would attack its own base. Oracle had some wild claims. These will be toned down and they will come to an agreement. Things will move on.
I'm not saying that people shouldn't pay attention to Oracle's antics (even though I just consider Oracle a whining child at this point), but I think this whole thing is overblown.
gtani · 2010-08-02
The load times are an issue, check out nailgun, -Xbootclasspath , java -client, javaRebel. There's a few other tricks i've seen mentioned, anybody else?
http://blog.headius.com/2009/01/my-favorite-hotspot-jvm-flags.html
http://stackoverflow.com/questions/1316056/how-to-reduce-scala-java-st…
http://groups.google.com/group/clojure/browse_frm/thread/33f80f1bb8277…
http://groups.google.com/group/leiningen/browse_thread/thread/66c6c72d…
rortian · 2009-08-28
I'm suprised that no one has mentioned JRuby in this context put here is a great post related to your question:
http://blog.headius.com/2009/04/how-jruby-makes-ruby-fast.html
This post shows how if you turn off certain Ruby language features you can make it much faster. Then he shows how his Ruby-like but static language is much faster.
jimbokun · 2009-04-03
This linked article:
http://blog.headius.com/2009/04/how-jruby-makes-ruby-fast.html
is really outstanding. It shows you exactly why a language like Ruby is inherently slower than a language like Java. Mainly, because Ruby does a lot more work to give you the cool, dynamic capabilities that make people like Ruby in the first place. Of course, much of the cool work on speeding up dynamic languages like Javascript and Ruby is all about analyzing code to find places where you can safely make assumptions about the code (+ is not overridden here, so I can use the built in integer addition operator, etc.).
(I probably oversimplified that, but I hope it captures the general idea.)
The "Duby" language at the end makes me think of Common Lisp and how you can optionally declare types the compiler can use to compile faster code. Would it be worthwhile to add optional typing to Ruby?
stephenjudkins · 2011-10-25
There are a few reasons one might choose to use JRuby.
The most frequently cited reason is to take advantage of JRuby's generally quite excellent Java interoperability. In many cases it may be the best way to introduce Ruby into an organization with a large, legacy Java codebase. Further, despite its oft-maligned reputation, Java still offers the largest number of high-quality, performant FOSS libraries of any platform. In our case, we are developing a Rails application along with a supporting Scala library simultaneously. In my experience, JRuby/Java/Scala integration is largely painless.
Further, JRuby could legitimately be considered the best Ruby implementation. It's very rare to find pure Ruby code that works on any other Ruby implementation but not JRuby. JRuby is, in general, faster than Ruby 1.9 (and in almost all cases much faster than 1.8). Further, upcoming enhancements in JDK 7 may allow some very impressive speed-ups (see http://blog.headius.com/2011/08/jruby-and-java-7-what-to-expect.html).
headius · 2010-07-19
I can comment on the JRuby results.
For the base perf numbers, I'm not surprised. We've known that we're roughly on par with 1.9.2 for some time, and many of the benchmarks in question have started to reach a point of irreducible complexity (e.g. you can only slice and dice strings so fast). It's good to see JRuby remains at or near the front of the pack as far as performance, especially considering we've made no major performance-related changes in almost two years.
The Linux versus Windows numbers are a bit surprising to me. If I were to make a guess, I'd guess that the JVMs used were not identical (perhaps like Isaac Gouy mentions, one platform was 64-bit and the other wasn't) or some other detail altered the performance characteristics of the test. But the performance drop does seem to be in line with other implementations, so perhaps Windows really does suck and there's not much we can do about it.
On the memory issue, I have a few recommendations.
JRuby by default allows the JVM to use up to a 512MB heap (the default is usually 32-64MB, which is rarely enough for most nontrivial apps). The JVM likes to use as much memory as you're willing to give it, to keep GC times low (nearly free) and to give it lots of room to breathe. Almost all these benchmarks could run in far less memory (maybe 1/5 as much or lower) if the JVM were choked down to that level. So it's not surprising to me that the memory sizes for these very object and CPU-intensive benchmarks start to…
jpedrosa · 2009-04-04
Sure... Nice write-up.
From the Hacker News site I have been following the recent controversy and even participated in some discussions. :-) Your Honor, I plead guilty! :-)
I cannot blame them (Twitter) when they seek their goals for a better business with higher quality and performance. I even respect their creative skills. So I don't have a beef with them even when Ruby gets caught in the polemic.
Ruby to this day continues to be an open source project put together by a community that for better or for worse has most core developers being Japanese.
But since about 3 or 4 years ago, Ruby has had other developers seeking to implement compatible Ruby versions... That is, Ruby has outgrown itself and continues to do so. JRuby, MacRuby, Rubinius, IronRuby...
At the end of it, though, Ruby continues being relatively slow when compared to other kinds of languages. But first read the following article to see some reasons why is that:
http://blog.headius.com/2009/04/how-jruby-makes-ruby-fast.html
Since Ruby's beginning, it was not out to reach C level performance. And JRuby for one improves upon some of the shortcomings of the main C implementation of Ruby quite well, not without its own shortcomings though. :-)
So, what do we have in the controversy? Twitter is a little sick of complaints of it letting the ball fall when much more is required of their services, so they go overboard when defining a solid platform for it with Scala. Not to mention that they simply can't go…
twelvechairs · 2017-06-17
JRuby spent years to get to the point where they could run Rails. If you cant do that in ruby you are not capturing the biggest use case of the language. Im not sure any of the alternatives got there
Theres a good list of problems making a proper ruby implementation here http://blog.headius.com/2012/10/so-you-want-to-optimize-ruby.html?m=1
And a list of what remains different in jruby here (mostly c extensions and threads) https://github.com/jruby/jruby/wiki/DifferencesBetweenMriAndJruby
sreque · 2017-03-14
The JVM itself doesn't add a huge memory footprint. I remember Charles Nutter of JRuby fame calling it the "20-30 MB memory tax" (see http://blog.headius.com/2008/11/noise-cancelling.html).
A lot of the extra memory usage of Java apps comes from sloppy programming and from depending on lots of heavyweight libraries and frameworks.
saltvedt · 2016-11-21
Good article explaining complexity of refinements in Ruby: http://blog.headius.com/2012/11/refining-ruby.html
shawn42 · 2013-09-26
Charles Nutter (of JRuby) has said that many of his main complaints on refinements have been resolved. His original rant can be found here: http://blog.headius.com/2012/11/refining-ruby.html
dewind · 2013-09-26
I'll refer to Nutter on this one. Refinements appear to be a method caching nightmare.
http://blog.headius.com/2012/11/refining-ruby.html
jcheng · 2013-09-07
In case you haven't seen this Charles Nutter post from a few months back, you may find it interesting. The TL;DR is that dynamic features in languages come at a cost (but he says "prove me wrong").
http://blog.headius.com/2013/05/on-languages-vms-optimization-and-way.…
tomstuart · 2013-02-24
Charles Nutter does a good job of explaining why you can't just ignore refinements: http://blog.headius.com/2012/11/refining-ruby.html
In summary, they makes the Ruby language harder to implement, and Ruby code harder to understand. You can't pretend they don't exist if their existence compromises the meaning of your code and the performance of your chosen Ruby implementation.
ch0wn · 2013-02-24
There's a really in-depth article on them that also covers concerns about the implementation: http://blog.headius.com/2012/11/refining-ruby.html
pmahoney · 2013-02-09
Here's an article from Headius, JRuby developer: http://blog.headius.com/2012/11/refining-ruby.html
kingkilr · 2013-02-06
One of the major launch criterion was having "enough of Ruby that the performance won't change". What does that mean in practice? We have exceptions, we have bindings, and we have all manner of other obscure corner cases. Charles Nutter (JRuby dev) writes about this: http://blog.headius.com/2012/10/so-you-want-to-optimize-ruby.html
ZitchDog · 2012-10-22
> InvokeDynamic support
This is the big one, in my opinion. See here[1] for some benchmarks of JRuby + invokedynamic. We're talking orders of magnitude for some benchmarks.
[1] http://blog.headius.com/2011/08/invokedynamic-in-jruby-constant-lookup…
thebluesky · 2012-07-24
The point my original post makes is that .NET having concurrent GC is not exactly groundbreaking. This doesn't have anything to do with the so-called expressiveness of C# relative to Ruby.
>The bytecode language is not standardized, and there is no standard assembler language for it
There is a formal spec here:
http://docs.oracle.com/javase/specs/jvms/se7/jvms7.pdf
> New features to the JVM are only added when they are required for Java.
This is another false assumption:
http://blog.headius.com/2008/09/first-taste-of-invokedynamic.html
>I say it does rival [the expressiveness of] ruby, you say it doesn't, good discussion.
Not really, is more like a generally accepted fact. e.g. Ruby typically uses 2-3x less code than C# to do the same thing:
http://shootout.alioth.debian.org/u64q/benchmark.php?test=all&lang…
rue · 2011-10-14
A response from Charlie Nutter (JRuby): http://blog.headius.com/2011/10/why-clojure-doesnt-need-invokedynamic.…
fogus · 2011-08-26
Logic isn't even required in this case (although I suppose it can never hurt). Charles Nutter has shared some numbers for JRuby constant lookups at http://blog.headius.com/2011/08/invokedynamic-in-jruby-constant-lookup…
- JRuby 2
- JRuby with current invokedynamic 35
- JRuby with some dev build that some guy who knows a guy who knows a guy at Oracle gave him: 0.5 [1]
The future might look bright, but a problem with the future is that it comes when it's ready and never before, no matter how much we want it to or might need it.
[1]: I'm just being playful here. I actually have no idea where Charles got that dev build.