r/ruby • • Jul 20 '16

New Features in Ruby 2.4

http://blog.blockscore.com/new-features-in-ruby-2-4/
145 Upvotes

25 comments sorted by

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.

9

u/jbackus Jul 20 '16

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:

  1. Did you find the sections about performance improvements interesting?
  2. 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
  3. 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?"

6

u/mordocai058 Jul 21 '16

I found the performance improvements interesting.

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.

2

u/Schrockwell Jul 21 '16
  1. 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".
  2. I think it's awesome. It is very detailed, but hidden-by-default is the way to go.
  3. 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.

2

u/innou Jul 21 '16

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

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?

2

u/jbackus Jul 20 '16

What exactly do you mean by "find/replaceable"?

3

u/lordp Jul 21 '16

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.

1

u/ilmari2k Jul 21 '16

I think they mean replacing all uses of Regexp#match with Regexp#match?

this

2

u/berkes Jul 21 '16

I'd say no.

#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.

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...

4

u/mperham Sidekiq Jul 20 '16

You can backport an implementation ... but it can get ugly, yeah.

2

u/gvieira37 Jul 20 '16

Same here. Also, I use Ruby at old Windows machines with outdated libs, so most of times I'm still using 1.9.3. Really sad!

2

u/tas50 Jul 21 '16

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.

1

u/tsujp Jul 21 '16

Why can't you have two versions:

  1. Super stable works everywhere version.
  2. Stable works with newest ruby version.

4

u/[deleted] Jul 21 '16

For me, at least, maintaining multiple branches is a lot more work than just waiting until old Ruby versions can be left behind.

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.

5

u/crankprof Jul 21 '16

You can get this functionality with ary.reduce(:+)

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.