Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pacmak): greatly reduce go code-gen memory footprint #3362

Merged
merged 2 commits into from
Feb 1, 2022

Conversation

RomainMuller
Copy link
Contributor

The go code generator was previously holding multiple copies of the
RootModule objects for dependencies (one for the generated package's
own RootModule, and one for each submodule that uses a type from that
dependency), including their entire type hierarchy, methods and
properties.

On large packages, especially with many submodules, this results in an
extremely large resident set size. Pathological cases have required
heaps as big as 6 GiB.

De-duplicating the RootModule instances, and not retaining GoTypeRef
instances (which are stateless, and cheap to construct), allows reducing
those pathological modules to only occupy around 300 to 400 MiB worth of
heap, which is a very significant improvement.

The reduction of duplication also has significant performance benefits
on affected code-bases. The go bindings generate significantly faster on
top of needing significantly less memory.


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

The go code generator was previously holding multiple copies of the
`RootModule` objects for dependencies (one for the generated package's
own `RootModule`, and one for each submodule that uses a type from that
dependency), including their entire type hierarchy, methods and
properties.

On large packages, especially with many submodules, this results in an
extremely large resident set size. Pathological cases have required
heaps as big as 6 GiB.

De-duplicating the `RootModule` instances, and not retaining `GoTypeRef`
instances (which are stateless, and cheap to construct), allows reducing
those pathological modules to only occupy around 300 to 400 MiB worth of
heap, which is a very significant improvement.

The reduction of duplication also has significant performance benefits
on affected code-bases. The go bindings generate significantly faster on
top of needing significantly less memory.
@RomainMuller RomainMuller added the language/go Regarding GoLang bindings label Feb 1, 2022
@RomainMuller RomainMuller requested a review from a team February 1, 2022 14:16
@RomainMuller RomainMuller self-assigned this Feb 1, 2022
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Feb 1, 2022
Copy link
Contributor

@MrArnoldPalmer MrArnoldPalmer left a comment

Choose a reason for hiding this comment

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

🔥

@mergify
Copy link
Contributor

mergify bot commented Feb 1, 2022

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Feb 1, 2022
@mergify
Copy link
Contributor

mergify bot commented Feb 1, 2022

Merging (with squash)...

@mergify mergify bot merged commit 77b520f into main Feb 1, 2022
@mergify mergify bot deleted the rmuller/go-codegen-memory branch February 1, 2022 16:17
@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Feb 1, 2022
@ansgarm
Copy link
Contributor

ansgarm commented Feb 1, 2022

Thank you so much 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. language/go Regarding GoLang bindings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants