Every year on the Christmas Eve there's a new Ruby release. This year it's Ruby 2.5. While many blog posts are covering major features like yield_self
, I wanted to bring your attention to something in the bottom of CHANGELOG, which I think deserves mention.
Thread.report_on_exception
t = Thread.new do raise "omg" end sleep 0.5 puts t.status.inspect
Would you guess the output of this script? On Rubies before 2.5, it's nil
. This happens because Thread.report_on_exception
is set to false
by default, which means that you could waste quite some time before you realize that a thread was crashing. To avoid that mistake, I always had to call Thread.raise_on_exception = true
before spawning any threads.
Ruby 2.5 sets Thread.report_on_exception
to true
by default. In my opinion, this is a great decision that could improve developer experience of threads.
There's a great post by Benoit Daloze, a contributor behind this change, where he explains the background and the reasoning behind the new default.
Updated: As Janko Marohnić poined out in comments, there's Thread#abort_on_exception
and Thread#report_on_exception
. The first makes the thread raise the exception to the parent thread, and it is false
by default. The latter only prints the error to stdout, and that's the parameter that got the new default.
ERB's rendering performance
In a Rails app with a large number of views, it's not unusual to see a half of the request time being spent on rendering ERB templates. Faster ERB rendering is a great news!
Takashi Kokubun improved the ERB performance in a series of commits: r58735, r58916, r58905, r58904, r58842. All of them are related to frozen strings or string encoding.
The announcement says that it's "twice as fast as Ruby 2.4". That's BIG, and I wanted to see it myself. I run a benchmark from Ruby repo:
$ ruby benchmark/run.rb --matzruby=ruby -m bm_app_erb
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17] app_erb: 1.237 ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17] app_erb: 1.642 ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-darwin16] app_erb: 1.129
While I could see 30% boost between 2.5.0 and 2.4.3 on my machine, 2.3.4 still produced a better result. Maybe it's my hardware?
Standard gems
Before, when you wanted to make a change to a standard library like FileUtils or CSV, you had to send a patch to ruby/ruby
and go through the complete review process.
In Ruby 2.5, a number of standard libraries were promoted to default gems: cmath, csv, date, dbm, etc, fcntl, fiddle, fileutils, gdbm, ipaddr, scanf, sdbm, stringio, strscan, webrick, zlib.
Now if you want to make a change to something like StringIO
, it's as simple as sending a PR to the GitHub repository.
Thanks to Javier Honduco for sharing these updates with me.