Repository navigation
Conversation
The built-in mismatch walk blocked the event loop for the whole warning: two full renders, two full parses and the walk, about 70 ms on a 7.4 MB value. The warning now returns to the event loop after each native rendering or parse of a side rendered at 65,536 code units or more, and holds the job's shadow slot until it reaches the logger, as Go and Rust do, so warnings in flight stay within shadowMaxInFlight. The walk also does less work for the same output. It skips members and items whose values are identical before sorting, renders a diffJson side only as far as its 1 KiB clamp reads, and, with the default JsonSerializer, reads the decoded cached value instead of parsing its rendering again, comparing a number beyond double range as the null the rendering writes. Refs #248
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #250 +/- ##
=======================================
Coverage 94.67% 94.68%
=======================================
Files 84 84
Lines 13026 13100 +74
Branches 805 829 +24
=======================================
+ Hits 12333 12404 +71
- Misses 627 629 +2
- Partials 66 67 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The TypeScript built-in mismatch walk blocks the event loop for a whole confirmed-mismatch warning: two full
JSON.stringifycalls, two fullJSON.parsecalls and the walk, one after another. On a 7.4 MB value that was oneblock of about 70 ms. #248 asks for a faster walk with identical output, TypeScript first; in session the maintainer
asked to "leverage setImmediete and some other optimizations to make sure we are not taking as long and also we are
not blocking event loop and also that its still correct". Refs #248, which stays open for the other ports.
Change
Change type: Refactor (identical output) with a TypeScript-only capacity change, recorded as a Deviations entry in
design/2026-10-24-shadow-mismatch-paths.md. That record isImplemented, so perdesign/README.mdit gains only theDeviations entry and this pull request in its list.
shadowMismatchLogStepsis a generator that yields after each native rendering or parse of aside whose rendering is at least 65,536 UTF-16 code units long.
warnShadowMismatchawaits an unreferencedsetImmediatebetween steps;renderShadowMismatchLogdrives the same generator synchronously for tests andvectors. Each native call, the walk and the hook still run without a break; native calls cannot be sliced. Short
sides never yield, which avoids hops for typical values and keeps the TypeScript replays working: their harness
drains one zero-time fake tick per input, and an immediate scheduled inside that tick lands 1 ms later.
reaches the logger, as Go and Rust already do, so warnings in flight stay within
shadowMaxInFlight. While one isbuilt, further jobs for the same key and jobs beyond capacity report
dropped. The slot is released whether theverdict settles as
mismatchor as a latetimeout.===before sorting and visiting; sorting a subset keeps itsorder.
diffJsonside is rendered only as far as its 1 KiB clamp reads (jsonPrefix), and a side that fitsis kept as the value with no parse-back. Hook sides keep the old path.
JsonSerializer(RedisCache.loadsParsedJson: the key's serializer hasJsonSerializer.prototype.load), the walk reads the decoded cached value instead of parsing its renderingagain.
jsonLeafcompares a number beyond double range, which another port can write as1e400, as thenullthe rendering writes.
On one Apple-silicon Mac (same process, interleaved, medians of 9; outputs asserted equal), with the default
serializer:
mainatdiff: "paths"The value fields alone took 54 ms on the first row, unchanged. The longest step is now the walk or one native parse.
Narrowing the parse to the differing region, rewriting
JSON.stringifyin JavaScript and capturing the tree with areplacer were also prototyped and verified; they are left out (see Follow-ups).
Open questions
the serializer's
JSON.parseof the payload, which holds the same JSON as a parse of its rendering, so output isunchanged; only a comparator that mutates the cached value, which its contract forbids, can make the diff name
members
cachedValueJsondoes not show, or fail the warning withrender_error. Recommended: treat it as animplementation detail, recorded under Deviations. If you count it as a departure from a confirmed decision,
AGENTS.md needs a new record, and I would drop the reuse from this pull request.
It shows as more
droppedjobs for a key that keeps mismatching with large values.mutations.jsonanchors M62, M67 and M69 moved). Recommended, per yourscoping for port-local work: accept the TypeScript lanes below instead of a
formal-full.yamlReplay or Mutationsdispatch. Say if you want the dispatch.
Ports
Validation
Head:
fdff86d. It differs frombfcc118only in the design record's pull request number, a Markdown-only change,so the runs at
bfcc118cover it.tsc --noEmit,vitest run --coverageatbfcc118: 3,898 passed, 333 skipped; coverage floors hold.pnpm build,test:packageon Node 24 atbfcc118: passed.make docs(docs:build) andmake auditatbfcc118: passed.make formal-generatethenmake formal-tson that fresh corpus atbfcc118: 7,920 replay tests passed.make mutations-ts MUTATION_ONLY=M13,M29,M48,M49,M58,M62,M65,M66,M67,M68,M69,M70,M72,M73,M75atbfcc118: everyrequired detection holds. M69's planted code was updated to the generator's signature, since it no longer compiled.
shadow-log-json.tsagainstmainatbae1e5e: 80,000 iterations on the firstbuild and 30,000 on the file at
bfcc118, over all plans,hooks, exotic values and payloads written the way other ports write them (overflow literals, duplicate and own
__proto__members): 0 mismatches. An independent review fuzzed about 1.2 million more checks, including everyspecial code unit at offsets 990 to 1040 around the side clamp: 0 mismatches.
treating every serializer as JSON, and removing
jsonLeafeach fail a test.Not run:
formal-full.yamlinreplayormutationsmode (open question 3); the Go, Rust and Python lanes, sinceno file they read changed.
Follow-ups
about 165 lines of lexer and slows root-level appends to number-dense arrays by up to 1.5 times. It is left for
Shadow mismatch paths: make the built-in walk faster, TypeScript first #248 if large localized mismatches turn out to be common.