mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-05 08:13:06 +08:00
JSON.stringify of a value reached through `unknown` walks native records and arrays through their live capsules. The protocol walk built a key-string array for every record and formatted every array index with snprintf into a fresh string, only to look the member up again by that key. A JSON API response of a few records spent most of its serialization time there. Without a replacer, walk a live record by field index over a snapshot of its present fields (its keys are the immortal field names) and a live array by element index, forming an index string only for a toJSON call that receives it. Members are still read as scr_json_member reads them, so callbacks that mutate or materialize the container see the same results. Index keys elsewhere use the integer formatter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>