Repository navigation
format: parse schemas lazily - #373
Merged
Merged
Conversation
The package root re-exports `schemas`, which parsed every schema YAML at module load. Consumers that only use the types and guards (such as @ethdebug/pointers) paid for the yaml library, all schema sources, and the parse. Define each entry of `schemas` as a getter that parses on first read and then becomes a plain data property. Mark the package side-effect free so bundlers drop the schema modules when nothing imports them. The generated Schema type no longer comes from a runtime `as const` copy of every parsed schema; the generator writes it as a type instead.
gnidan
force-pushed
the
format-lazy-schemas
branch
from
October 8, 2026 22:43
f9d9172 to
d6bf7b0
Compare
Contributor
|
Freezing or sealing `schemas` made each accessor non-configurable, so the first read threw when it tried to redefine the property. Keep the parsed value in the accessor's closure and redefine the property only while it is still configurable. Load a fresh module for each test so the tests do not share state.
The `#...` imports resolved to `dist/` under vitest, so a stale build could hide a regression. Alias them to their `types` entries, which point at source. Also build the bundle test's plugin paths with a URL relative to the package and skip imports that have no `types` entry.
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.
The package root re-exports
schemas, andschemas/index.tsparsed all of the schema YAML at module load. Every consumer of the root, including@ethdebug/pointers, paid for theyamllibrary, about 144 KB of schema sources, and the parse, even when it never touchedschemas.This keeps the API as it is and moves the cost to first use:
schemasis a getter that parses that one schema on first read, then turns into a plain data property. Keys, enumeration order, values, and the type stay the same, and assignment still works.package.jsondeclares"sideEffects": false, so a bundler drops#schemas,#describe, the YAML sources, andyamlwhen nothing imports them.describeSchemaalready parsed only on call.yamls.tsused to carry a runtimeas constcopy of every parsed schema only to derive theSchema<Id>type. The generator now writes that type directly, so the module holds only the YAML strings.Measured with esbuild (minified ESM, gzipped) and Node 20 import time:
import { isPointer } from "@ethdebug/format"import { dereference } from "@ethdebug/pointers"import { schemas } from "@ethdebug/format"New tests check that importing the root parses no YAML until a schema is read, that every schema equals its parsed YAML, and that an esbuild bundle of the root without
schemasholds noyamlcode or schema sources.