Bug 152578 - RegExp with anchor negation and grouping performance
Summary: RegExp with anchor negation and grouping performance
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 9
Hardware: Mac OS X 10.10
: P2 Normal
Assignee: Nobody
Depends on:
Reported: 2015-12-28 16:41 PST by shahar.soel
Modified: 2020-02-12 06:02 PST (History)
4 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description shahar.soel 2015-12-28 16:41:19 PST
reproduced here:


* 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 = /^"(:?[^\\"])+"/;

* 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.

Comment 1 shahar.soel 2015-12-30 07:28:58 PST
fixed the jsperf example (was using wrong syntax for none capturing groups)
Comment 2 shahar.soel 2016-08-08 00:35:49 PDT
JSPerf is down so I've added a reproducing jsfiddle instead.


(open the console to see the results).
Comment 3 Pierre-Yves Gérardy 2020-02-12 06:02:05 PST
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.