Bug 152578
| Summary: | RegExp with anchor negation and grouping performance | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | shahar.soel |
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
| Status: | NEW | ||
| Severity: | Normal | CC: | barraclough, ggaren, msaboff, org.webkit |
| Priority: | P2 | ||
| Version: | Safari 9 | ||
| Hardware: | Mac | ||
| OS: | OS X 10.10 | ||
shahar.soel
reproduced here:
https://jsperf.com/regexp-negation-in-group/5
Expected:
* Similar performance for these two regExps
* Performance for these RegExp.test should be independent of input size as they anchor to the start of the input.
var noGroup = /^"[^\\"]+"/;
var oneGroup = /^"(:?[^\\"])+"/;
Actual:
* for oneGroup regExp the performance is much worse.
anywhere from x30 slower for a single line input
to 5 orders of magnitude for a 10000 lines input.
When running the benchmark on other browsers (chrome/firefox)
The input size does not affect the performance.
Thanks.
Shahar.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
shahar.soel
fixed the jsperf example (was using wrong syntax for none capturing groups)
http://jsperf.com/regexp-negation-in-group/6
shahar.soel
JSPerf is down so I've added a reproducing jsfiddle instead.
https://jsfiddle.net/cbepLyum/2/
(open the console to see the results).
Pierre-Yves Gérardy
There is still a slowdown when using groups, but it is now by a constant factor of ~4, rather than dependent on the subject length.
Surprisingly, the RegExp with two non-capturing groups is 10-20% faster than the one with only one.