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

Reduce memory use for PULUMI_OPTIMIZED_CHECKPOINT_PATCH #11666

Merged
merged 6 commits into from Dec 15, 2022

Conversation

t0yv0
Copy link
Member

@t0yv0 t0yv0 commented Dec 15, 2022

Description

Fixes #11653

Inject fewer newlines, and per @blampe suggestion do not inject more than 1024 newlines even if we have more than 1024 resources. This limits Myers matrix to 1024x1024 max size which should be 8MB or so.

Promotes jsoniter from indirect to direct dependency. It's easier to work with for preserving indents and doing newline injection.

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • I have run make changelog and committed the changelog/pending/<file> documenting my change
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

@pulumi-bot
Copy link
Contributor

pulumi-bot commented Dec 15, 2022

Changelog

[uncommitted] (2022-12-15)

Bug Fixes

  • [backend/service] Fixes out-of-memory issues when using PULUMI_OPTIMIZED_CHECKPOINT_PATCH protocol
    #11666

Copy link
Contributor

@RobbieMcKinstry RobbieMcKinstry left a comment

Choose a reason for hiding this comment

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

Nice! Looks good to me! Sorry I'm a menace with pedantic nits :( They're non-blocking though.

cp.UntypedDeployment = sentinel
pattern, err := json.Marshal(cp)
if err != nil {
var jsonIterConfig = jsoniter.Config{SortMapKeys: true}.Froze()
Copy link
Contributor

Choose a reason for hiding this comment

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

I could go either way on this.

My gut says unless jsonIterConfig is mutable (Froze() indicates to me it isn't), I'd throw it in a function so no one tries to mutate it.

On the other hand, Froze() will make it apparent the minute anyone tries to mutate it (as long as they test their change), and putting this in a function will create 1 unnecessary allocation each time Write is called. Probably better to leave it as is.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a strange lib. Froze() allocates state/cache/pools. This needs to be a module-level var I think for best results (reuse of the pools).

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM! IMO module level variables is typically an anti-pattern, except when it isn't. Which is Golang in a nutshell... :\

This is a good example of when it isn't.

pkg/backend/httpstate/client/marshal.go Outdated Show resolved Hide resolved
return err
}

func (c *marshalUntypedDeployment) writeToStream(stream *jsoniter.Stream) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have no comprehension of the incantation order here 😅 For example, what does WriteMore() do? Why is it necessary? Maybe a single line comment somewhere at the top of the method would help? Not a big deal either way, I feel like someone coming across this is going to have to read the API docs anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

WriteMore writes a "," .. this is a pretty low-level API.

Copy link
Contributor

Choose a reason for hiding this comment

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

😆

pkg/backend/httpstate/client/marshal.go Outdated Show resolved Hide resolved
pkg/backend/httpstate/client/marshal.go Outdated Show resolved Hide resolved
pkg/backend/httpstate/snapshot.go Show resolved Hide resolved
pkg/backend/httpstate/snapshot_test.go Show resolved Hide resolved
t0yv0 and others added 3 commits December 15, 2022 12:08
Co-authored-by: Robbie McKinstry <thesnowmancometh@gmail.com>
@t0yv0
Copy link
Member Author

t0yv0 commented Dec 15, 2022

bors merge

@bors
Copy link
Contributor

bors bot commented Dec 15, 2022

Build succeeded:

@bors bors bot merged commit ad74c80 into master Dec 15, 2022
@bors bors bot deleted the t0yv0/fix-optimized-patch-json-leak branch December 15, 2022 17:59
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.

PULUMI_OPTIMIZED_CHECKPOINT_PATCH temporarily allocates 100x the checkpoint memory
3 participants