Skip to content

Reduce codegen size - #1430

Merged
adwsingh merged 6 commits into
mainfrom
adwsingh/reduce-codegen-size
Oct 29, 2026
Merged

adwsingh merged 6 commits into
mainfrom
adwsingh/reduce-codegen-size

Conversation

@adwsingh

@adwsingh adwsingh commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What behavior changes?

Generated models share operation and enum logic, use typed collection writers, and replace deserializer helper classes with static methods. SharedSerde follows schema partitions. ApiService adds operation lookup by ShapeId. Unknown enum variants become classes instead of records.

Why is this change needed?

Large models repeat helper code across thousands of shapes. For EC2, the JAR shrinks from 23.35 MB to 15.97 MB (31.60%), with 4,598 fewer classes.

How was this validated?

Added tests cover collection writers across codecs, enum equality, generated deserializers, and operation lookup. The EC2 size workflow and Java 25 tests on macOS passed. Ubuntu tests remain in progress.

What should reviewers focus on?

Review OperationGenerator, EnumGenerator, SharedSerdeGenerator, and the collection writers in each codec. Review how these changes handle sparse collections, unknown enum values, and operation schemas.

Additional Links

EC2 size report.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.


Stack created with GitHub Stacks CLI • Give Feedback 💬

@adwsingh
adwsingh added this pull request to stack #1429 October 27, 2026 13:47
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codegen size report

Code generated for 437 AWS service models (aws-api-models 1.0.337) with modes client server; sizes count client output only. Compiled with javac 25.0.5+10-LTS (--release 21 -g -proc:none -nowarn). Jar size is the size of a jar holding the compiled classes and generated resources at default compression.

Metric Base PR Change
Largest jar increase none
Largest jar decrease: ec2 23.36 MB 15.98 MB -7.38 MB (-31.58%)
Total jar size 595.49 MB 422.91 MB -172.58 MB (-28.98%)
Average jar size 1.37 MB 995.5 KB -406.3 KB (-28.98%)
Median jar size (p50) 843.8 KB 601.7 KB -242.0 KB (-28.68%)
Class bytes 1.39 GB 1.03 GB -360.01 MB (-25.36%)
Classes 377,941 264,538 -113,403 (-30.01%)
Source bytes 916.86 MB 805.81 MB -111.05 MB (-12.11%)
Source files 106,578 107,332 +754 (+0.71%)

Totals cover the 435 services that compile on both base and PR. Known failures excluded: clouddirectory, deadline. Listed as known failures but compiling, so the entries can be removed: timestream-query, timestream-write.

Largest changes by service

435 of 435 services changed jar size.

Service Base PR Change
ec2 23.36 MB 15.98 MB -7.38 MB (-31.58%)
quicksight 14.98 MB 10.48 MB -4.50 MB (-30.04%)
sagemaker 15.54 MB 11.09 MB -4.46 MB (-28.67%)
connect 11.82 MB 8.30 MB -3.52 MB (-29.78%)
glue 9.15 MB 6.37 MB -2.79 MB (-30.45%)
securityhub 8.51 MB 5.72 MB -2.78 MB (-32.72%)
iot 6.17 MB 4.38 MB -1.79 MB (-29.04%)
bedrock-agentcore-control 6.86 MB 5.07 MB -1.79 MB (-26.11%)
medialive 6.64 MB 4.85 MB -1.79 MB (-26.98%)
datazone 6.55 MB 4.79 MB -1.76 MB (-26.83%)
ssm 5.27 MB 3.63 MB -1.65 MB (-31.25%)
rds 4.70 MB 3.28 MB -1.42 MB (-30.30%)
mediaconvert 5.55 MB 4.19 MB -1.37 MB (-24.60%)
cloudfront 4.65 MB 3.32 MB -1.33 MB (-28.51%)
lex-models-v2 4.34 MB 3.04 MB -1.30 MB (-29.94%)
`ec2`: by category
Category Base jar bytes PR jar bytes Change Base files PR files
structure 13.04 MB 9.53 MB -3.52 MB (-26.97%) 7,758 5,172
enum 3.55 MB 2.75 MB -823.0 KB (-22.61%) 5,299 4,815
operation 1.06 MB 695.0 KB -385.5 KB (-35.68%) 807 807
schemas 686.3 KB 547.4 KB -138.9 KB (-20.24%) 43 34
client 135.2 KB 173.1 KB +37.9 KB (+28.00%) 6 7
serde 1.64 MB 168.7 KB -1.48 MB (-89.97%) 1,571 33
resources 605 B 605 B 0 2 2
error 474 B 474 B 0 1 1
`ec2`: largest changes by class

33 top-level classes added, 9 removed. Sizes are deflated jar bytes.

Class Base PR Change
model.SharedSerde 1.64 MB 6.1 KB -1.64 MB (-99.64%)
model.InstanceType 791.8 KB 597.6 KB -194.2 KB (-24.52%)
model.GeneratedSchemaIndex 95.5 KB 13.8 KB -81.8 KB (-85.60%)
model.AmazonEC2ApiService 764 B 41.7 KB +41.0 KB (+5491.49%)
model.ResourceType 69.3 KB 52.1 KB -17.2 KB (-24.87%)
model.Schemas36 15.9 KB removed -15.9 KB (-100.00%)
model.Schemas39 15.7 KB removed -15.7 KB (-100.00%)
model.Schemas35 15.7 KB removed -15.7 KB (-100.00%)
model.Schemas38 15.5 KB removed -15.5 KB (-100.00%)
model.Schemas37 15.4 KB removed -15.4 KB (-100.00%)
model.Schemas40 15.3 KB removed -15.3 KB (-100.00%)
model.Schemas34 13.9 KB removed -13.9 KB (-100.00%)
model.Schemas33 12.6 KB removed -12.6 KB (-100.00%)
model.SharedSerde19 added 8.8 KB +8.8 KB
model.SharedSerde22 added 8.0 KB +8.0 KB

Base: main at a03ea18. PR: 58d182a merged into the base. Workflow run.

@adwsingh
adwsingh requested a review from mtdowling October 27, 2026 14:41
Base automatically changed from adwsingh/stable-waiter-order to main October 27, 2026 16:55
@adwsingh
adwsingh force-pushed the adwsingh/reduce-codegen-size branch from ddd6c1a to c34a6e5 Compare October 27, 2026 16:55
@Override
public Void listShape(ListShape listShape) {
var kind = CodegenUtils.collectionWriterKind(model, listShape.getMember());
if (kind != null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this kinda contradicts with an ability to override the type via symbol provider for a given shape - e.g. if in a symbol provider you say "this shape has to be a list of LocalDate objects" whilst on the model level it is still a string, the code will be generated correctly, but now because the list generation is based on the smithy model alone (without accounting for the codegen symbol provider) this gets out of sync. Is this expected?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it feels like it should fine as soon as the codegen integration also overrides the codegen for lists and maps now (previously when overriding the codegen for a specific "string" shape e.g. with a trait it was automatically applied to both lists and maps of such shape, but now it has to be done additionally). So I guess it should be fine 🙏

@adwsingh
adwsingh force-pushed the adwsingh/reduce-codegen-size branch 3 times, most recently from a3409d2 to bc2e96b Compare October 28, 2026 12:49
@adwsingh
adwsingh requested a review from mtdowling October 28, 2026 12:54
@adwsingh

Copy link
Copy Markdown
Contributor Author

@mtdowling I added back Unknown enum as a record. It adds about 170 KB but preserves backward compatibility for unknown record deconstruction.

@adwsingh
adwsingh force-pushed the adwsingh/reduce-codegen-size branch from b342571 to 63590db Compare October 28, 2026 19:25
timocov and others added 5 commits October 28, 2026 13:23
Wrap failures raised during deserialization (e.g. a union builder
rejecting a payload with no members or more than one member set) into
SerializationException at the top-level entry points: Codec and
JsonCodec deserializeShape, and the HTTP binding request/response
deserializers. This makes malformed input surface consistently across
codecs instead of leaking NullPointerException/IllegalArgumentException
from generated builders.
Replace generated structure and collection deserializer callback classes with static method references. Keep serializer singleton classes to preserve cold serialization performance, and shard SharedSerde content alongside schema partitions.

EC2 benchmark (811 operations), relative to the prior per-operation output:
- JAR: 25,020,471 -> 21,431,175 bytes (-14.35%)
- Classes: 15,335 -> 12,034 (-21.53%)
- First serialization: 8.6 -> 7.9 ms
- First deserialization: 15.5 -> 4.9 ms
- Steady serialization: 106.2 -> 106.2 ns/op
- Steady deserialization: 2,077.4 -> 2,031.4 ns/op

Timing values are medians from three fresh JVM runs.

Tests: ./gradlew :codegen:codegen-core:check :codegen:codegen-plugin:check
@adwsingh
adwsingh force-pushed the adwsingh/reduce-codegen-size branch from 63590db to c07f500 Compare October 28, 2026 20:23
@adwsingh
adwsingh force-pushed the adwsingh/reduce-codegen-size branch from c07f500 to 58d182a Compare October 28, 2026 20:38
@adwsingh
adwsingh merged commit 6f940ab into main Oct 29, 2026
9 checks passed
@adwsingh
adwsingh deleted the adwsingh/reduce-codegen-size branch October 29, 2026 07:28
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.

3 participants