RegExp Backtracking (ReDoS) and Unicode Modes vs Prioritized Task Scheduling and scheduler.yield()
scheduler.yield() pauses between loop iterations, whereas catastrophic regex backtracking stalls a single synchronous call frame.
Structured Comparison Matrix
| Dimension | RegExp Backtracking (ReDoS) and Unicode Modes | Prioritized Task Scheduling and scheduler.yield() |
|---|---|---|
| Mental Model | Prevent catastrophic O(2^n) main-thread ReDoS freezes and broken 16-bit emoji splits—understand Irregexp's backtracking NFA and use /u or /v Unicode modes. | Cooperative main-thread yielding primitive that pauses long JS work for input and rendering, then resumes in a prioritized continuation queue. |
| Maturity & Domain | Baseline · Widely · JS Runtime Chrome 112+ · Firefox 116+ · Safari 17+ | Experimental · JS Runtime Chrome 129+ · Firefox In development · Safari No |
| Prerequisites | ||
| When Not to Use | When not to use RegExp: Never parse nested HTML, JSON, or balanced parentheses with regular expressions, use a proper parser or DOMParser. | When not to use scheduler.yield(): Never run heavy pure computation (image encoding, crypto, AST parsing, or catastrophic RegExp backtracking) on the main thread at all; move it to a Web Worker, and track remaining stalls via PerformanceObserver RUM. |
Engine Mechanics & Trade-Offs
JS RegExp engines use backtracking NFA execution; nested quantifiers like (a+)+ trigger exponential O(2^n) backtracking on non-matching suffixes.
Key Pitfalls: Stateful /g lastIndex Bug: Calling .test() repeatedly on a /g regex mutates lastIndex, causing alternating true/false results on identical strings. ReDoS on User-Supplied Inputs: Validating email or Markdown with nested +/* groups opens a client-side freeze vector.
scheduler.yield() suspends an async task and places its continuation in a priority-inherited continuation queue ahead of normal third-party tasks.
Key Pitfalls: Yielding Every Iteration: Calling await yieldMain() on every loop step adds massive async overhead; gate it with a 12ms–16ms performance.now() budget. Missing Fallback: Safari and older Firefox versions lack scheduler.yield(); always feature-detect before calling.