Hacker News new | ask | show | jobs
by pjungwir 2945 days ago
Congratulations Ruby team! I'm excited to hear about the performance improvements. It seems like JIT could be a huge win since calling a method requires checking all kinds of possibilities that are almost always not used, but might be. I would love to keep all the power & fun of Ruby without worrying so much about performance.

Speaking of optimizing method calls: now that it's been a few years, I wonder what Ruby folks think about refinements. Are you using them? Are they helpful? Horrible?

I remember reading from the JRuby folks that refinements would make Ruby method calls slower---and not just refined calls, but all method calls [1], although it sounds like that changed some before they were released [2]. It seems like people stopped talking about this after they came out, so I'm wondering if refinements are still a challenge when optimizing Ruby? I guess MRI JIT will face the same challenges as the Java implementation?

[1] http://blog.headius.com/2012/11/refining-ruby.html

[2] https://github.com/jruby/jruby/issues/1062

4 comments

As the creator of Ruby Facets, refinements were high on the todo list. Unfortunately the syntax of refinements led to an ugly problem... I would have to support two identical code bases to support both usages (monkey patching and refinement), the only difference being boilerplate code. I could find no way around it. That seemed ludicrous to me, and so I never bothered to add refinement support. Hence, from my perspective, refinements went over like a led balloon.
I've never heard of Ruby Facets but it looks interesting. Just as a heads up, the api document links on http://rubyworks.github.io/facets/learn.html don't work.
I feel refinements are best suited for libraries. E.g. compare this improvement to the CSV gem: https://github.com/ruby/csv/pull/30 which defines it only for itself, compared to ActiveSupport defining it globally: https://github.com/rails/rails/commit/575dbeeefcaafeb566afc0...
Refinements don't add any peak performance overhead in their final implementation.
That is great to hear! I'd love to read the details if you happen to have a link to more information. I've tried Googling for it a few times over the years but never found anything.
I haven't done any work to implement refinements myself, but I do know that basically it came down to something that you could write an inline cache against, guarded against the class version, so a simple word guard that you were doing anyway when you called any method.
Have you tried jruby?