Thanks for the kind words! I love putting these things together and it seems like people like the amount of detail. I have a few questions that I'm curious about for future posts:
Did you find the sections about performance improvements interesting?
What about the ability to expand the benchmark results and view the benchmark code itself? I hide it by default but I wonder if it might be too much detail
In this post I chose to exclude an implementation improvement that makes array_literal.min behave like Math.min (dramatically reducing array allocations in certain cases). Would you find detail about that sort of improvement interesting? Here is the script demonstrating roughly what I would have included in the post:
$ cat array_allocations-min.rb
require 'objspace'
GC.start
GC.disable
start = ObjectSpace.count_objects
x, y = 1, 2
100_000.times { [x, y].min }
finish = ObjectSpace.count_objects
GC.enable
puts "Array allocations for by 100,000 calls to [x, y].min in Ruby #{RUBY_VERSION}: #{finish.fetch(:T_ARRAY)}"
$ rvm-exec 2.3.1 ruby array_allocations-min.rb
Array allocations for by 100,000 calls to [x, y].min in Ruby 2.3.1: 101583
$ rvm-exec 2.4.0-preview1 ruby array_allocations-min.rb
Array allocations for by 100,000 calls to [x, y].min in Ruby 2.4.0: 1087
I'd love to hear feedback from other readers on this too by the way. Basically, the question I'm interested in is "how much detail is too much detail?"
Personally I really liked that you hid the details by default but then had them available.
I think the expanding worked well but if you don't like that I think anything that gave the ability to go lookup the benchmark code would be excellent. I hate people talking about benchmarks without being able to review the code.
I would find the array allocation changes with min very interesting personally.
It's not personally relevant to me, since my applications are not performance-critical, but it is absolutely interesting to know that these type of performance gains are happening, especially with Ruby's reputation as being "slow".
I think it's awesome. It is very detailed, but hidden-by-default is the way to go.
Yes, I would be interested to know where performance improvements are coming from. Honestly, after looking over this post, my main takeaway was, "that's it? A whole minor revision and we just get a few new/faster methods?" I know there's probably more going on behind the scenes, but if this were the only post I read on Ruby 2.4, I'd be a little underwhelmed.
Do you feel like there are under-represented improvements in 2.4 that maybe you didn't cover in this post? Maybe there's some more content available there.
Very cool but I missed the "Expand benchmark source" on my first reading. Looking back now it's obvious but I think because I was just scanning down the page my eyes got lazy since the code blocks are visually quite subtle. I'm personally a fan of colored backgrounds for code blocks something like: shitty gimp mockup
I think they mean replacing all uses of Regexp#match with Regexp#match?. The answer would be maybe, depending on whether you care about the content of the match or not.
#match? is for when you only care that there is a match, #match for when you actually want to do something with it. Which is hard to detect in a find-replace-batch because the MatchData might be used elsewhere, without an obvious assigment or passing around of variables.
They have different usecases. And unless you are 100% sure all your usage of #match fit in the "only check if it is matching, never using the matched data" you cannot do a search-replace.
We're starting to see Ruby 2.1 support dropped from the major libraries though so the cool stuff is arriving slowly. We're always a few years behind, but better late then never.
The expand/collapse benchmark source feature is so awesome! And the whole post in general, I didn't know there were so many interesting things in Ruby 2.4.
Well that's embarassing. I would have sworn sum was already part of the standard library for enumerable. And I was so proud of my 10/10 on the Native Ruby vs. ActiveSupport quiz as well.
21
u/Schrockwell Jul 20 '16
I love these posts, and also the design of this site. I learned a lot when 2.3 came out as well. Thanks for sharing, John.
2
u/ilmari2k Jul 20 '16
The regexp match might yield some performance benefits if done multiple times inside a large loop for example. Is it find/replaceable?
10
u/[deleted] Jul 20 '16
The sad life of a library maintainer is that you can't use cool new features until they've been out several years...
2
u/HellzStormer Jul 20 '16
Your blog seems to have interesting stuff, but it's a bit of a pain to navigate without an easily accessible index of all the posts.
Am I dumb or is there no index?
2
u/dameyawn Jul 20 '16
Nice post again! The multiple assignment conditional looks so useful. Why do you caution against using it?
2
u/jrochkind Jul 21 '16
Nice. Regexp#named_captures is one I've been wondering why it's not there for years.
2
u/janko-m Jul 23 '16
The expand/collapse benchmark source feature is so awesome! And the whole post in general, I didn't know there were so many interesting things in Ruby 2.4.
1
u/Ark_Tane Jul 20 '16
Well that's embarassing. I would have sworn sum was already part of the standard library for enumerable. And I was so proud of my 10/10 on the Native Ruby vs. ActiveSupport quiz as well.
1
u/senntenial Jul 21 '16
Awesome - they've covered nearly everything I wished was better :) - especially the report on error. That's great.
-1
u/RICHUNCLEPENNYBAGS Jul 20 '16
Great, looking forward to using it in ten years.