Firefox bad RegEx performance

前端 未结 1 1976
被撕碎了的回忆
被撕碎了的回忆 2021-02-19 22:05

I use the JavaScript parser generator JISON to create a parser for some scripts that my users create. Lately I\'ve noticed that the parsing process on Firefox is by a large fact

1条回答
  •  [愿得一人]
    2021-02-19 22:42

    It is the RegExp capturing grouping that got you:

    /^[0-9]+/ and/or /^(?:[0-9])+/ and/or /^([0-9]+)/ are orders of magnitude faster than /^([0-9])+/. And they should be viable alternatives.

    I would expect it to be slightly slower with capturing groups, but that it is that much slower surprises me. However the slow version has the potential to create lots and lots of captures, while the other versions do not, so that seems to be an important difference.

    Unscientific jsperf.

    You may want to file a bug.

    0 讨论(0)
提交回复
热议问题