I was doing some work profiling the ‘assets:precompile’ Rake task in a
JRuby on Rails app, and I discovered some interesting performance
issues
related to doing things like this:
begin
file.actions()
rescue Errno::ENOENT
# ignore or do something
end
instead of this:
if File.exists?(file)
file.actions()
else
# ignore or do something
end
I started submitting a few small patches, but already met with pushback
because the issue was perceived to only affect JRuby and assumed
to lower performance in MRI.
I wrote up a simple benchmark testing counting directory entries for
directories that may or may not exist. I would appreciate any feedback
on this specific benchmark and on the general idioms of exception
handlers
vs. explicit test, neither of which are “free”.
I’m still working on patches to stdlib/fileutils, but got a little
discouraged.
I’m hoping now that I have data that shows MRI suffers a similar
performance
hit (even if of a smaller magnitude) with the exceptions vs. extra
stat(),
there will be less objection.
P.S. I get a 404 for you blog post and don’t see it referenced from
the
front page of your blog.
How embarrassing! I guess I didn’t click “publish”. Should be working
now.
Do you have any statistics on how many exists/!exists happen in your
typical assets:precompile. Based on the fact that a exists is 9x
faster on a miss and only 10% slower on a hit for MRI, it should be
fairly easy with typical usage statistics to show that MRI will
generally always be faster.
That is assuming your assets represent a reasonable workload?
-Tom
PS- The quickness of the resolution is a little disturbing. I
suspect your patch will be a net gain in MRI and a huge one for JRuby.
On Thu, Oct 25, 2012 at 10:45 PM, Patrick M. [email protected]
wrote: