Skip to content

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Aug 30, 2025

Context

In the implementation of Schema serde #1600, the schema objects, corresponding roughly 1-1 with modeled shapes, expand linearly with the model size.

Initially, all schemas were generated into a single file called /schema/schemas.ts. Because schema objects call factory functions, they are not tree shaken correctly. Even adding @__PURE__ etc. annotations in the source code did not work, with both webpack and esbuild failing to tree shake correctly (rollup did fine).

PR

Here we have a bucketing system to generate schema objects into separate files.

  • Generating a single file per schema object would be excessive: this creates too many files, which is destructive to our package size measurements and to the file-&-build-systems that would be handling our packages.
  • The question was then, how do we logically bucket schemas into separate files?

Solution / heuristic

We can't arbitrarily put e.g. 100 schemas per file into multiple bucketing files. Schema objects form a dependency tree, and random bucketing would create poor tree-shaking outcomes.

The solution in the PR buckets schema objects into a logical operation group. For example, in the AWS S3 model, the following schema objects are grouped together in a file called schemas_Payment.ts

export var GetBucketRequestPaymentOutput = struct()
export var GetBucketRequestPaymentRequest = struct()
export var PutBucketRequestPaymentRequest = struct()
export var RequestPaymentConfiguration = struct()
export var GetBucketRequestPayment = op()
export var PutBucketRequestPayment = op()

Although the bucketing doesn't create the absolute minimum import graph as individual files would, it balances the file count with importing a significantly and logically reduced subset of the schema tree.

The graph partitioning details are in the PR code.

@kuhe kuhe requested a review from a team as a code owner August 30, 2025 16:58
@kuhe kuhe changed the title export pure feat: schema codegen bucketing to help with tree-shaking Aug 30, 2025
@kuhe kuhe mentioned this pull request Aug 29, 2025
2 tasks
@kuhe kuhe merged commit 5334f29 into smithy-lang:main Sep 2, 2025
11 checks passed
@kuhe kuhe deleted the export-pure branch September 2, 2025 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants