Closed
Bug 876976
Opened 11 years ago
Closed 11 years ago
Speed up array creation for global regexp matches
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
FIXED
mozilla24
People
(Reporter: sstangl, Unassigned)
References
Details
Attachments
(2 files, 2 obsolete files)
1.41 KB,
application/javascript
|
Details | |
5.22 KB,
patch
|
h4writer
:
review+
|
Details | Diff | Splinter Review |
Array creation currently calls defineElement() immediately after each match. Instead, we could accumulate the elements and use the very fast NewDenseCopiedArray() constructor. The attached patch does so.
Note that this work is only now possible because of the recent refactoring work done by Matt Stults in Bug 841615.
I haven't measured on the jQuery benchmark attached in Bug 876846 (browser will take a long time to build), but in a local microbenchmark, the patch shows promising results.
Note that I first tried to accumulate StringRanges so that js_NewDependentString() could be called in a separate tight loop, but doing so wound up significantly slower than just calling js_NewDependentString() in the body of the match loop.
The patch is pretty much good to go, but I'd like to see the results on the jQuery test before putting it up for review.
Reporter | ||
Comment 1•11 years ago
|
||
Attachment #755091 -
Attachment is obsolete: true
Reporter | ||
Comment 2•11 years ago
|
||
Microbenchmark used for testing. The scores on x64 are:
SM (unpatched): 5.4s
SM (patched): 1.8s
V8 (release): 2.2s
Reporter | ||
Comment 3•11 years ago
|
||
Oops! I made the wrong thing fast. The jQuery benchmark actually builds matches using .exec(), not .match(), which uses a similar but disjoint code path, so this isn't any use in beating v8 on that particular benchmark.
On the plus side, .match() is fast now.
No longer blocks: 876846
Reporter | ||
Comment 4•11 years ago
|
||
Attachment #755092 -
Attachment is obsolete: true
Attachment #755121 -
Flags: review?(hv1989)
Comment 5•11 years ago
|
||
> return NULL;
Should be "return false;" to get this to compile on clang over here. ;)
Comment 6•11 years ago
|
||
Comment on attachment 755121 [details] [diff] [review]
Speed up global regexp match
Review of attachment 755121 [details] [diff] [review]:
-----------------------------------------------------------------
Nice (both patches ;))
::: js/src/jsstr.cpp
@@ +1702,3 @@
> size_t i = 0;
> ScopedMatchPairs matches(&cx->tempLifoAlloc());
> + RegExpRunStatus status = re.execute(cx, input->chars(), charsLen, &i, matches);
I assume you wanted to use "chars" instead of "input->chars()" here?
@@ +1745,5 @@
> +
> + /* Extract the matched substring, root it, and remember it for later. */
> + JSLinearString *str = js_NewDependentString(cx, input, match.start, match.length());
> + if (!str)
> + return NULL;
return false;
@@ +1747,5 @@
> + JSLinearString *str = js_NewDependentString(cx, input, match.start, match.length());
> + if (!str)
> + return NULL;
> + if (!elements.append(StringValue(str)))
> + return NULL;
return false;
Attachment #755121 -
Flags: review?(hv1989) → review+
Reporter | ||
Comment 7•11 years ago
|
||
Comment 8•11 years ago
|
||
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla24
You need to log in
before you can comment on or make changes to this bug.
Description
•