-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Time.parse significantly slower than MRI 2.1.1 #1662
Comments
I should probably note that the joda code doesn't seem to take the timezone into account. I'm not overly familiar with its API, so I got more of a PoC going rather than something that'd be an exact replacement. |
This might also be the underlying cause of jruby/activerecord-jdbc-adapter#540. |
@chrisseaton The methods involved here are heavy Ruby code, running regexps and chopping up strings. Might be a good candidate for Truffle experimentation? |
I did some profiling passes for Time.parse, mainly looking for heavy allocation. I came up with two patches: https://gist.github.com/headius/ca4c8f5c4f70c794950a The first patch improves the performance of Hash#delete_if and #reject by passing arguments straight through if possible, rather than creating a temporary array every time. I have not checked that this passes tests, but I believe it should. The second patch allows the "Bag" class's accessor methods to fill out, avoiding creation of multiple String instances on every access. I have not investigated whether too many methods will be defined using this patch. The remaining big ticket items in an allocation profile were all related to the many little regexp matches going on. Unless there's a way for us to reuse a Joni ByteCodeMachine, these will remain expensive or have to change to non-regexp logic. First hundred entries of allocation profile here: https://gist.github.com/headius/534f5ec7be7821d21e9a Before and after (Time.parse part of @nirvdrum's bench only) numbers are improved, but still not good enough. BEFORE:
AFTER:
I'll add the bench to jruby/rubybench. |
MRI 2.1.1 numbers on my system, for comparison:
|
closing this one in favour of #3640 (same underlying issue) |
In one app, we do a lot of calls like
Time.parse('3PM EDT')
. Not an ideal format, but it's what I have to work with. Parsing here is ~4.4x slower than MRI 2.1.1. Here's the simple benchmark code I'm using. I comparedTime.parse
toTime.strptime
, a version that does app-specific parsing, and one that uses Joda:JRuby 1.7.12:
MRI 2.1.1p76:
The text was updated successfully, but these errors were encountered: