Skip to content

chore: Convert Schema to class (2nd attempt)#1105

Merged
jbelkins merged 16 commits into
mainfrom
jbe/kinder_gentler_reference_schema
Jun 24, 2026
Merged

chore: Convert Schema to class (2nd attempt)#1105
jbelkins merged 16 commits into
mainfrom
jbe/kinder_gentler_reference_schema

Conversation

@jbelkins

@jbelkins jbelkins commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Description of changes

In the original PR #1082, schemas were converted from value types that are created on demand using computed properties, to lazy globals that are created and retained on first use, then reused.

However, the change started causing compiler OOMs in the build system. That change was reverted in #1104 so that we could determine the cause of the OOMs and try the feature over again.

The cause was found to be that: member schemas were previously declared inline in the members array property of the parent schema. Sometimes (i.e. in the case of enums with hundreds of cases), this resulted in code-generated Swift literal expressions that were thousands of lines long. When these expressions were used in computed properties, they were handled by the compiler without problems.

However, when we instead tried to use these same large literal expressions as the RHS of an assignment, they started to consume a lot of time and RAM at type checking time. It has been noted before that very large arrays of complex literal expressions (i.e. structures like our schemas) cause high times & memory usage to type-check. See: swiftlang/swift#60549

Member schemas are now declared as their own separate schemas, assigned to a variable in the global namespace, and included by reference in the parent schema's members instead of being declared inline. This breaks up large composite schemas into much smaller expressions that are type-checked much easier.

Another change from the first attempt is that the schema global vars have explicit typing of Swift.Schema. Not providing explicit type info causes the compiler to incorrectly detect a circular reference when schema targets form a reference cycle. This discovery allows us to avoid the extra code-generated getters that we were using before, reducing the volume of code-generated expressions. (In reality, the circular reference chain is broken by the use of @autoclosure on the schema's target property, so the compiler is correct to not flag the reference.)

Scope

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

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

@jbelkins jbelkins changed the title Revert "chore: revert "Convert Schema to class (#1082)" (#1104)" chore:Convert Schema to class (2nd attempt) Jun 23, 2026
@jbelkins jbelkins changed the title chore:Convert Schema to class (2nd attempt) chore: Convert Schema to class (2nd attempt) Jun 23, 2026
}

private var _containerType: ShapeType?
private let _containerType: ShapeType?

@jbelkins jbelkins Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

it was an oversight for this property to be mutable, changed to let

Comment thread Sources/SmithyCodegenCore/Deserialize/DeserializeCodegen.swift Outdated
Comment thread Sources/SmithyCodegenCore/Deserialize/DeserializeCodegen.swift Outdated
Comment thread Sources/SmithyCodegenCore/Schemas/SchemasCodegen.swift
Comment thread Sources/SmithyCodegenCore/Serialize/SerializeCodegen.swift Outdated
Comment thread Sources/SmithyCodegenCore/Serialize/SerializeCodegen.swift Outdated
Comment thread Sources/SmithyCodegenCore/SymbolProvider/SymbolProvider.swift Outdated
@jbelkins jbelkins marked this pull request as ready for review June 24, 2026 15:24
@jbelkins jbelkins requested a review from a team as a code owner June 24, 2026 15:24
@jbelkins jbelkins merged commit 5a5ab77 into main Jun 24, 2026
45 checks passed
@jbelkins jbelkins deleted the jbe/kinder_gentler_reference_schema branch June 24, 2026 18:40
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