Skip to content

Commit 2cea56a

Browse files
committed
[YARR] Enable Boyer-Moore lookahead optimization for Unicode patterns
https://bugs.webkit.org/show_bug.cgi?id=307635 Reviewed by Yusuke Suzuki. The Boyer-Moore lookahead skip optimization in Yarr JIT was disabled for patterns with the /u or /v flags. This change: 1. Removes the eitherUnicode() guard from BoyerMooreInfo collection. The guard is kept only for the multi-pattern SIMD prefilter, which is untouched by this change. 2. Adds readCharacterRaw() which reads raw UTF-16 code units in the BM scan loops instead of tryReadUnicodeChar(), avoiding unnecessary surrogate pair decoding overhead in the prefilter. 3. Ends the BM window at a character class that can match a non-BMP code point (an inverted class, or one with non-BMP members), since such a class consumes one or two code units and makes the offsets of subsequent terms non-fixed (e.g. /(.A)\1/u would otherwise miss a match). TipOfTree Patched regexp-unicode-bm-search 175.9850+-4.8277 ^ 16.2982+-0.8780 ^ definitely 10.7978x faster regexp-unicode-bm-search-nomatch 168.9133+-1.4194 ^ 18.4031+-1.5015 ^ definitely 9.1785x faster regexp-unicode-bm-search-emoji 77.8834+-1.1231 ^ 7.7590+-0.1699 ^ definitely 10.0378x faster Tests: JSTests/microbenchmarks/regexp-unicode-bm-search-emoji.js JSTests/microbenchmarks/regexp-unicode-bm-search-nomatch.js JSTests/microbenchmarks/regexp-unicode-bm-search.js JSTests/stress/regexp-unicode-bm-search.js * JSTests/microbenchmarks/regexp-unicode-bm-search-emoji.js: Added. * JSTests/microbenchmarks/regexp-unicode-bm-search-nomatch.js: Added. * JSTests/microbenchmarks/regexp-unicode-bm-search.js: Added. * JSTests/stress/regexp-unicode-bm-search.js: Added. (shouldBe): (throw.new.Error): * Source/JavaScriptCore/yarr/YarrJIT.cpp: Canonical link: https://commits.webkit.org/317830@main
1 parent 0a9ad7d commit 2cea56a

5 files changed

Lines changed: 876 additions & 29 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(function() {
2+
var post = "";
3+
var emojis = ["\u{1F600}", "\u{1F60D}", "\u{1F525}", "\u{1F389}", "\u{2728}"];
4+
for (var i = 0; i < 60; i++)
5+
post += emojis[i % emojis.length] + "\u3044\u3044\u306D";
6+
post += "#weekend";
7+
8+
var re = /#weekend/u;
9+
var n = 500000;
10+
var result = 0;
11+
for (var i = 0; i < n; i++) {
12+
if (re.test(post))
13+
result++;
14+
}
15+
if (result !== n)
16+
throw "Error: bad result: " + result;
17+
})();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(function() {
2+
var article = "";
3+
var sentences = [
4+
"\u6771\u4EAC\u90FD\u306F\u65E5\u672C\u306E\u9996\u90FD\u3067\u3042\u308B\u3002",
5+
"\u4EBA\u53E3\u306F\u7D041400\u4E07\u4EBA\u3067\u3042\u308B\u3002",
6+
"\u591A\u304F\u306E\u89B3\u5149\u5BA2\u304C\u8A2A\u308C\u308B\u3002",
7+
"\u6D45\u8349\u5BFA\u3084\u6E0B\u8C37\u306F\u6709\u540D\u3067\u3042\u308B\u3002",
8+
];
9+
for (var i = 0; i < 50; i++)
10+
article += sentences[i % sentences.length];
11+
12+
var re = /forbidden/u;
13+
var n = 500000;
14+
var result = 0;
15+
for (var i = 0; i < n; i++) {
16+
if (!re.test(article))
17+
result++;
18+
}
19+
if (result !== n)
20+
throw "Error: bad result: " + result;
21+
})();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(function() {
2+
var article = "";
3+
var sentences = [
4+
"\u6771\u4EAC\u90FD\u306F\u65E5\u672C\u306E\u9996\u90FD\u3067\u3042\u308B\u3002",
5+
"\u4EBA\u53E3\u306F\u7D041400\u4E07\u4EBA\u3067\u3042\u308B\u3002",
6+
"\u591A\u304F\u306E\u89B3\u5149\u5BA2\u304C\u8A2A\u308C\u308B\u3002",
7+
"\u6D45\u8349\u5BFA\u3084\u6E0B\u8C37\u306F\u6709\u540D\u3067\u3042\u308B\u3002",
8+
];
9+
for (var i = 0; i < 50; i++)
10+
article += sentences[i % sentences.length];
11+
article += "information";
12+
13+
var re = /information/u;
14+
var n = 500000;
15+
var result = 0;
16+
for (var i = 0; i < n; i++) {
17+
if (re.test(article))
18+
result++;
19+
}
20+
if (result !== n)
21+
throw "Error: bad result: " + result;
22+
})();

0 commit comments

Comments
 (0)