3 ms·
I don't know the authors reason but I've personally always avoided refinements after first reading about their performance hit for JRuby code[0]. I read somewh
by Lio 5y ago
I don't know the authors reason but I've personally always avoided refinements after first reading about their performance hit for JRuby code[0].
I read somewhere recently that even for MRI ruby you can take a 40% hit when using refinements (but please take that with a big pinch of salt as I can't find the source right now).
0. http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/33487 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/...
- byroot 5y agoThe source is me: https://gist.github.com/casperisfine/1c46f05cccfa945cd156f445f0d3d6fa https://gist.github.com/casperisfine/1c46f05cccfa945cd156f44... Note that this overhead apply as soon as a refinement is defined for a method regardless of wether it's ever active. That 40% figure is for an empty method. So for "big" methods that are infrequently called it's probably fine, but it should really be avoided in hotspots.
- Lio 5y agoAha! Excellent, thank you. For me refinements are a bit like meta-programming; I'm glad they exist but I think there's other ways to get the same result which are easier to live with.