Repository navigation
Description
Filed on behalf of Mathieu G. (mr-zwets) by Claude Opus 5.5.
Problem
Since 0.14 (#418 for global functions, #426 for constants), each debug.functions frame for an imported callable carries the complete text of its declaring file in frame.source. A contract that uses k distinct constants or functions from one file therefore embeds that file k times, and the artifact grows by roughly k × (file size + 300 bytes).
Minimal repro on 0.14.0-next.5 (and next at 9f7662b, identical output). lib.cash has 20 int constants and a 5 KB comment; the contract uses C0 + … + C(k-1):
| constants used (k) | artifact size | copies of lib.cash |
|---|---|---|
| 0 | 0.8 KB | 0 |
| 1 | 7.0 KB | 1 |
| 5 | 31.6 KB | 5 |
| 10 | 62.4 KB | 10 |
Frames for constants and functions declared in the contract's own file carry no source, and a constant used many times gets one frame, so the cost is per distinct imported callable.
Real-world impact: ParyonUSD V2 (31 contracts) keeps its shared constants in one constants.cash. Naming ~20 single-byte identifiers there took the artifacts from 639 KB to 1.21 MB, and the inferred type of an object exporting them exceeded what tsc will serialize (TS7056). We worked around it by moving the constants to a small separate file (+31%). Bytecode is unaffected; only the debug info grows.
Cause
dependency-resolution.ts:130-137 sets sourceCode = importedSource (the whole file) on every imported function and constant, and buildDebugFrame (GenerateTargetTraversal.ts:274-292) copies it into each frame.
What we'd like
Store each source file once per artifact and let frames refer to it, e.g. debug.sources: { [sourceFile]: string }, with frames keeping only sourceFile. For a contract using 7 constants from constants.cash:
Today Proposed
debug.functions: debug.sources:
DUST_LIMIT source: <constants.cash> "constants.cash": <constants.cash> (once)
MINIMUM_DEBT source: <constants.cash> debug.functions:
... 7 copies DUST_LIMIT sourceFile: "constants.cash"
MINIMUM_DEBT sourceFile: "constants.cash"
Each artifact stays self-contained: a file is still embedded once in every artifact that uses it, so debugging never needs a second file. This preserves every current consumer:
debug-frame.ts:71andbitauth-script.ts:205only need the file's lines, addressed by the file-absolute line numbers already in the source maps, so they resolveframe.source ?? debug.sources?.[frame.sourceFile] ?? artifact.source.bitauth-script.ts:158usesframe.source === undefinedto mean "declared in the contract file"; that check moves tosourceFile === undefined.sourceFileis already unique per canonical path, and imports are deduplicated by it.
With #446 still open, fixing this before 0.14.0 avoids shipping the per-frame layout in the artifact format (utils/src/artifact.ts:34, website/docs/compiler/artifacts.md:74). Older 0.14-next artifacts keep working through the fallback above. The generalised artifact format sketched in a comment on #305 already has a per-artifact sources array.
We will follow up with a PR implementing this, linked here.
Activity
feat: store imported sources once and share import resolution between…
mr-zwets commentedon Sep 28, 2026
closed by #453