Search 100,000 JSON documents on the GPU
Write the search loop once in JavaScript-style builder code; run it on every document at once on the GPU, with the same answers.
1 The job
You need to search 100,000 JSON documents with a regular expression on every keystroke, and highlight the JSON. In plain JavaScript that is a loop: one document after another, on one thread. On a GPU, you would have to rewrite it all as shaders.
2 Predict
Measure it yourself below: the line under the search box reads “This program: … ms on the GPU. Native RegExp: … ms.”, both timed live in your browser. Try the pattern that makes RegExp backtrack: ([a-z]+)+x. The fixed program takes the same time on any pattern; RegExp can take seconds. Timings vary by machine and GPU, so we don't print a number here.
3 Poke it
Checking for WebGPU…
Embedded unmodified from chenglou/handwired · src/json-search, MIT license, © 2026 Cheng Lou. Open it full screen. Upstream also runs it on chenglou.me/handwired.
4 Is it the same answer?
The counter you'd want is “0 differences from plain JavaScript”. This page doesn't compute that live; upstream's test suite does, comparing the search programs against plain-JavaScript references over edge cases and fuzzed inputs (tests/json-search: search.test.ts, searcher.test.ts, edge-cases.test.ts, writer-fuzz.ts). The CPU toggle in the demo runs the very same programs as generated JavaScript, so you can flip it and see the same matches.
Reach for Handwired when the same small piece of logic has to run on a huge number of inputs at once, and you want to write it once as readable code instead of hand-writing GPU shaders.