Skip to content

Split Buffer's Thue-Morse lastIndexOf stress test out, skip TSan - #8344

Merged
danlapid merged 1 commit into
mainfrom
dlapid/buffer-reverse-search-no-tsan
Nov 10, 2026
Merged

danlapid merged 1 commit into
mainfrom
dlapid/buffer-reverse-search-no-tsan

Conversation

@danlapid

Copy link
Copy Markdown
Collaborator

Under ThreadSanitizer, buffer-nodejs-test took 104–141 s per variant, against 2–3 s in regular builds. Almost all of that time went to the "expensive reverse searches" block: six lastIndexOf calls for long prefixes of a 5 MB Thue-Morse buffer. Each call runs memrchr(3) about 60,000 times, over most of the buffer each time, and finds a match within a few bytes of the end. glibc stops there. Sanitizers' memrchr interceptor checks the whole range before searching, though (its memchr interceptor checks only up to the match), so TSan checks about 960 GB of shadow memory.

This moves that block unchanged into buffer-reverse-search-nodejs-test, tagged no-tsan. The code is single-threaded, so TSan has nothing to find there. Regular and ASan builds still run it.

This replaces #8298, which chunked MemrchrFill to dodge the interceptor. Benchmarked without a sanitizer on -c opt, that change made production lastIndexOf 25–35% slower when the match is 1–4 KiB from the end, and 12–32% slower on inputs with many candidates. The old code was already linear there, so this PR leaves production code alone.

Timings on bazelflare, --runs_per_test=5:

Test TSan before (2 runs) TSan after Regular after ASan after
buffer-nodejs-test@ 114–137 s 4.5–6.7 s 2.0–4.7 s 1.0–3.6 s
buffer-nodejs-test@all-autogates 104 s 3.6–8.4 s 2.4–4.4 s 2.1–5.5 s
buffer-nodejs-test@all-compat-flags 134–141 s 3.1–8.8 s 1.8–4.5 s 1.3–3.8 s
buffer-reverse-search-nodejs-test@ — skipped 0.7–1.6 s 2.2–2.6 s
buffer-reverse-search-nodejs-test@all-autogates — skipped 0.8–1.5 s 2.2–3.4 s
buffer-reverse-search-nodejs-test@all-compat-flags — skipped 0.7–1.2 s 2.3–2.6 s

Under the TSan tag filter, bazel test reports "No test targets were found" for the new test's variants.

A longer-term fix belongs in compiler-rt: the memrchr interceptor could check only [match, end), the way memchr's does.

🤖 Generated with Claude Code

The "expensive reverse searches" in buffer-nodejs-test.js made it
take 104-141 s per variant under ThreadSanitizer, against 2-3 s in
regular builds. Each of the six searches calls memrchr(3) about
60,000 times on most of a 5 MB buffer. glibc's memrchr stops near
the end each time, but sanitizers' memrchr interceptor checks the
whole range before searching, so TSan checks about 960 GB of shadow
memory.

Move those searches unchanged into
buffer-reverse-search-nodejs-test, tagged no-tsan. The code is
single-threaded, so TSan has nothing to find there. Regular and ASan
builds still run it. The remaining buffer-nodejs-test takes about
5 s under TSan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@danlapid
danlapid requested review from a team as code owners November 10, 2026 16:49

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — Test-only change that moves a stress test unchanged into its own target, which TSan builds skip. No issues found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

Test-only change; no security concerns.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

The block is moved unchanged, and buffer-nodejs-test.js has no leftover references to the removed variables. The no-tsan tag works with the existing TSan tag filters, and wd_test still creates the default, all-compat-flags and all-autogates variants for non-TSan builds.


⚡ Performance: ✅ LGTM

No production code changes.


📝 Documentation: ✅ LGTM

The BUILD comment describes the current reason for skipping TSan.


Reviewed commit: cf7a2a3f

@danlapid
danlapid merged commit 4121ac8 into main Nov 10, 2026
22 of 23 checks passed
@danlapid
danlapid deleted the dlapid/buffer-reverse-search-no-tsan branch November 10, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants