fix(codegen): use literal string keys in SchemaTraitWriter to fix esbuild tree-shaking#1889
Open
TrevorBurnham wants to merge 1 commit intosmithy-lang:mainfrom
Open
fix(codegen): use literal string keys in SchemaTraitWriter to fix esbuild tree-shaking#1889TrevorBurnham wants to merge 1 commit intosmithy-lang:mainfrom
TrevorBurnham wants to merge 1 commit intosmithy-lang:mainfrom
Conversation
…uild tree-shaking
SchemaTraitWriter.writeTraitsObject() previously emitted computed property
keys using StringStore variable references (e.g. { [_e]: _c }). esbuild
treats computed keys as potentially side-effectful and refuses to
tree-shake the containing statements, causing severe bundle size
regressions for SDK users (30KB -> 492KB for minimal imports).
Changed to emit literal string keys instead (e.g. { "error": _c }).
Trait key names are short strings ("error", "httpError", etc.) so the
size cost of inlining them is negligible, while StringStore abbreviations
are preserved for trait values where they still save bytes.
Fixes aws/aws-sdk-js-v3#7607
Contributor
|
With the availability of other bundlers for optimization-interested applications, and anticipated release of rolldown, I don't want to deoptimize code for esbuild at this time. We can reevaluate when there is more interest. |
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.
Fixes aws/aws-sdk-js-v3#7607
Problem
Since aws-sdk-js-v3 v3.930.0, ESBuild users have seen significant bundle size regressions when importing only a few commands from a client. For example, importing
EC2Clientand 3 commands grew from ~30KB to ~492KB.SchemaTraitWriter.writeTraitsObject()emits computed property keys usingStringStorevariable references as object keys:ESBuild treats computed property keys (
[expr]) as potentially having side effects because the expression could invoke a getter ortoString(), so it marks the entire containing statement as non-tree-shakeable. This affects all ~416 generated AWS SDK clients.Solution
This PR changes
SchemaTraitWriter.writeTraitsObject()to emit literal string keys instead of computed ones:Trait key names are short strings (
"error","httpError","httpQuery","streaming", etc.) so the size cost of inlining them is negligible.StringStoreabbreviations are preserved for trait values where they continue to save bytes without affecting tree-shaking.Changes
SchemaTraitWriter.writeTraitsObject()— format string changed from[%s]: %s,(withstringStore.var()) to"%s": %s,(withshapeId.getName())SchemaTraitWriterTest— updated assertion to match new literal key output