-
-
Notifications
You must be signed in to change notification settings - Fork 922
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
match? should be faster than match #5256
Comments
good find, definitely makes sense to look into "optimizing" |
MRI has separate internal implementation for that which passes region as NULL so we'd have to make something similar in joni. |
@lopex and I looked at this one today. Removing creating internal regions in joni and then deleting a bunch of code on JRuby side (since we don't need to deal with captures) MRI (2.5.1) was like 5.2M i/s and we were like 4.7-4.9M i/s from like 1.9-2.1M i/s before patching. If I removed interruptible support we went up to about 5.5M i/s. If I tried bench with those changes using graal ce rc4 we get about 7.2M i/s. @lopex plans on doing a cleaner version of my changes to joni and we will at least close the gap quite a bit. Even without removing regions we discovered we were calling search instead of match (which we had to call based on the current version of what match? calls through; but we ended up finding two bottlenecks overall so this was somewhat satisfying. |
We are closer but still not quite there (numbers from my MBP):
|
FWIW here's an allocation profile of the
|
Since we might be beaten by GC pressure here and MRI just mallocs/frees stack and repeat stack (we're allocating matcher and repeat stack) Is there possibly a mix of thread local / dynamic scope place where we could reuse the matcher instance ? |
@lopex it would be interesting as a test to see how much difference that makes...like just cheat with the impl to cache matcher and see if we get considerably faster. |
I have experimented with resetting and reusing the matcher, but the machine itself still constructed a lot of state. If we could reuse the entire thing I'm sure it would have an impact, but I was never able to measure that. |
But it shouldnt though, Matcher should be all state there is |
Environment
jruby 9.2.1.0-SNAPSHOT (2.5.0) 2018-07-20 a2bc9a3 Java HotSpot(TM) 64-Bit Server VM 9.0.4+11 on 9.0.4+11 +jit [linux-x86_64]
ruby 2.6.0dev (2018-07-20 trunk 64004) [x86_64-linux]
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]
ruby 2.5.0
ruby master
ruby master + jit
jruby master
jruby master + indy
match? should perform better https://bugs.ruby-lang.org/issues/8110
but jruby implement it just like match, without setting a back-reference on a ruby level
ruby has a specialized method for it and it looks like there has been some improvements recently
https://github.com/ruby/ruby/blob/trunk/re.c#L3324
I found match? pattern very useful on many places, so I think it's worth investigating if there's a way to improve it.
The text was updated successfully, but these errors were encountered: