GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||
GeezerVison is showing github.com — fix(core): copy models.dev snapshot without structuredClone by kitlangton · Pull Request #46710 · anomalyco/opencode Conversation
|
| per catalog callback run | |
|---|---|
| Before | 39–55 ms (median ≈ 41) |
| After | 6–11 ms (median ≈ 7) |
Measured inside a real opencode serve process with an isolated HOME, five servers per revision, each running the callback twice during startup.
Isolated comparison on the bundled snapshot (6,279 models): structuredClone per model 28.8 ms; whole-snapshot structuredClone 18.0 ms; Object.fromEntries copy 9.7 ms; recursive plain copy with the __proto__ guard 2.9 ms. The cost is data volume, not call overhead, which is why cloning once was not enough.
One file. Catalog semantics are unchanged: every rebuild still gets fresh, independently mutable copies of the snapshot. No public interface changes. Independent of the State materialization stack (#46610 → #46682 → #46631); it reduces catalog rebuild cost under any State design.
# packages/core bun typecheck bun run test test/catalog.test.ts test/plugin/models-dev.test.ts test/provider.test.ts
copies model request bodies without reinterpreting literal __proto__ keys fails on the initial for...in copy and passes with the guard.performance.now() around the callback on both revisions; the timing code is not in the diff.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The models.dev catalog callback cloned each of the ~6,300 snapshot models with structuredClone on every run, costing about 40 ms per catalog rebuild during startup. Snapshot data is plain JSON, so a direct recursive copy preserves the same fresh-copy semantics at roughly 7 ms per run.
Assigning that key into a fresh object sets its prototype instead of an own property, so a second copy hoisted the nested fields into the request body. Define it explicitly and copy own keys only, matching structuredClone. Adds a regression covering both copy stages.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.