How AI-Assisted Debugging Made jsdom 43% Faster for React Tests
Sentry engineers used AI-assisted debugging to fix three jsdom bottlenecks, making a React Testing Library suite 43% faster without changing any tests.
During Sentry's HackWeek, an engineer used GPT-5.6 via Codex to speed up a slow React Testing Library suite without touching a single test or query. Rather than swapping getByRole for cheaper alternatives, the effort targeted the jsdom and DOMSelector libraries underneath, since accessibility-aware matching is inherently more expensive than raw DOM selectors.
Profiling uncovered three real bottlenecks: jsdom repeatedly rescanning the entire document to find labels for every input, a broken fast-path check in DOMSelector that always fell through to a slow matcher because it compared internal and public document objects with strict equality, and event dispatch code that re-searched the same event path at every step. Fixing label lookup alone yielded roughly a 91x speedup, the selector fix cut matching time by up to 89%, and the event-path fix improved throughput by 12-36%.
Combined, the three fixes made a real Sentry test file 43% faster than an unpatched jsdom 30 setup, and 21% faster than Sentry's current jsdom 26 baseline, while test code and queries stayed identical. Two of the three changes have already merged into jsdom but aren't yet in a release, while the DOMSelector fix remains an open pull request. For engineers, the lesson is that library-level fixes to jsdom, rather than rewriting tests, can meaningfully speed up large, accessibility-heavy suites relying on getByRole, deep DOM trees, or heavy userEvent usage.
This synthesis was produced from its source by AI; there is no human editor or manual review step. How we work