-
-
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
Cache RubyDateParser object in ThreadContext to reduce the cost of object creations #4675
Conversation
first we should understand why its still min 5x slower than MRI. hane nothing against this but it might be optimization done in the wrong end ... |
@kares Thank you for your comment. I'm closing this PR. and will reopen it if needed. |
I have been looking at this a bit this afternoon and caching the parser 3x the current results on HEAD. I believe the cost is object creation and initialization overhead for somethign which runs short. Making stateless lexer/parser (e.g. single result values with inputs passed as params) or other patterns could reduce this allocation cost but at the moment it seems pretty big. With the current state we are now down to about 6x slower so things are getting a little closer. The caching makes us only like 40% slower but I think we can get this cost down other ways first before thinking about it. A lexer which used ByteList+Joni would be decent. Another one interesting is not creating a linked list of patterns. A smaller one is eliminating bag and populating the hash directly. A tiny one is not re-retrieving all symbols out of the symbol cache but making them fields somewhere. |
@enebo Thank you for your comment. Make sense. I will take a profile later. |
@enebo looking good, maybe I would not count on most apps being reasonable much, guess we'll see 😉 |
@enebo Great, looks good 👍 My application, Embulk, should get big benefits from your change. It usually receives a dozen of format strings during I'm not sure (I haven't seen) but, if there would be actual applications that need to parse timestamp strings by a lot of types of formats, this logic might be slower than MRI's. A kind of cache size limit (like |
@muga the memory size of this cache probably scales into 10k-100k without a lot of memory. A linked list of strings for format values seems like it should take very little memory? Although we may end up adding a cache size in the future if anyone reports this as a leak... |
@enebo Ah I see. The linked lists might not consume a lot of memory because the number of elements in one linked list is about 10 or 20 usually. Your change should be OK. |
To improve performance of Java strptime implemented on #4635, this PR caches a
RubyDateParser
object inThreadContext
to reduce the cost ofRubyDateParser
object creations. The cache is basically similar approach toRubyDateFormatter
inThreadContext
.The following is my micro benchmark based on https://github.com/macournoyer/tinyrb. The performance by this PR is 1.5 times faster maximumly.
The raw test data: https://gist.github.com/muga/b83262ed03009d2f765f8fd0c5319e54