mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-06 08:23:19 +08:00
A read site's cache only remembered properties it found on the receiver or its first prototype. Reads of properties an object lacks, which validation libraries make constantly (zod reads ctx.skipChecks, payload.memo, x.aborted and _zod.optin on every check), walked the whole shape chain and then repeated the lookup on the generic path every time: 7.9 million such reads in one zod benchmark run. - Read sites call a new probe, scr_js_get_probe, that answers undefined for a key the receiver and its chain of plain shaped objects (at most one prototype, ending in the default prototype) lack, and caches that answer. The entry holds while the receiver's shape, its prototype link, and that prototype's shape are unchanged. Its tag and placeholder holder make the inline entry-0 test in compiled code miss, so the answer always comes from the probe. Method reads keep scr_js_load_probe, so a missing method still reaches the slow path and its "is not a function" error. Names of Object.prototype members are never cached as absent. - Receivers of one shape with different prototypes (zod's internals objects) each keep an entry instead of replacing one another. - A site whose four-way record is full consults a per-thread table keyed by shape and key before walking shapes, and fills it.