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".
http://polycrystal.org/2012/10/25/comparing_ruby_e...
Thanks!
--
Patrick Mahoney
on 2012-10-26 05:46
on 2012-10-26 12:21
In general, exceptions are a bad choice for flow control. http://c2.com/cgi/wiki?DontUseExceptionsForFlowControl talks about the problem across several languages. http://www.coffeepowered.net/2011/06/17/jruby-perf... is great for tracking down excessive exceptions in JRuby code. My team has used these techniques several times to speed up our production code. It hadn't occurred to me that our slow Rails asset precompilation might be partly caused by exceptions as flow control. I'd love to see asset precompilation go faster under JRuby. I'd like to help promote your proposed changes. Where have you been submitting patches? - Bruce P.S. I get a 404 for you blog post and don't see it referenced from the front page of your blog.
on 2012-10-26 14:31
On 26.10.2012 05:20, Bruce Adams wrote: > I'd love to see asset precompilation go faster under JRuby. I'd like > to > help promote your proposed changes. Where have you been submitting > patches? So far just this one https://github.com/sstephenson/hike/pull/21 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. -- Patrick Mahoney
on 2012-10-26 18:25
Patrick, 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 Mahoney <pat@polycrystal.org> wrote: > instead of this: > > Patrick Mahoney > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > -- blog: http://blog.enebo.com twitter: tom_enebo mail: tom.enebo@gmail.com
on 2012-10-26 20:09
I replied with my support and posted an additional set of numbers showing GC counts with the various mechanisms: https://gist.github.com/3960364 Clearly a big GC win here. - Charlie
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.