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

Write state using compact JSON representation #1647

Merged
merged 4 commits into from
May 21, 2024

Conversation

alexott
Copy link
Contributor

@alexott alexott commented May 13, 2024

This PR changes the writing of the state using compact JSON (non-indented) representation. This significantly improves performance when working with huge states.

For example (on ~450k objects in the state):

  • state size is decreased from 510.1MB to 386.6MB
  • Time to write to S3 decreased from 112 seconds to 94 seconds
  • Time to read from S3 decreased from 87 seconds -> 55 seconds

Resolves #1593

Target Release

1.8.0

Checklist

  • I have read the contribution guide.
  • I have not used an AI coding assistant to create this PR.
  • I have marked any code I have not written myself (including modified code, e.g. copied from other places and then modified) with a comment indicating where it came from.

Go checklist

<-- If your PR contains Go code, please make sure you check off all items on this list: -->

  • I have run golangci-lint on my change and receive no errors relevant to my code.
  • I have run existing tests to ensure my code doesn't break anything.
  • I have added tests for all relevant use cases of my code, and those tests are passing.
  • I have only exported functions, variables and structs that should be used from other packages.
  • I have added meaningful comments to all exported functions, variables, and structs.

Website/documentation checklist

  • I have locally started the website as described here and checked my changes.

This PR allows to write JSON using compact (non-indented) representation if the
`TF_USE_COMPACT_STATE_FORMAT` environment variable is defined.  This significantly
improves performance when working with huge states.

For example (on ~450k objects in state):

* state size is decreased from 510.1MB to 386.6MB
* Time to write to S3 decreased from 112 seconds to 94 seconds
* Time to read from S3 decreased from 87 seconds -> 55 seconds

Signed-off-by: Alex Ott <alexott@gmail.com>
@alexott alexott requested a review from a team as a code owner May 13, 2024 09:59
Copy link

Reminder for the PR assignee: If this is a user-visible change, please update the changelog as part of the PR.

Signed-off-by: Alex Ott <alexott@gmail.com>
@alexott alexott changed the title Allow to write state using compact representation Write state using compact JSON representation May 21, 2024
cam72cam
cam72cam previously approved these changes May 21, 2024
janosdebugs
janosdebugs previously approved these changes May 21, 2024
@cam72cam
Copy link
Contributor

@alexott looks like some test failures to fix before this can be merged

Signed-off-by: Alex Ott <alexott@gmail.com>
@alexott alexott dismissed stale reviews from janosdebugs and cam72cam via 0b3f733 May 21, 2024 13:15
@alexott
Copy link
Contributor Author

alexott commented May 21, 2024

Tests are fixed

@cam72cam
Copy link
Contributor

I had a small heart attack when looking at the LoC totals in the diff, before remembering that it was the whole goal of this PR 😆

cam72cam
cam72cam previously approved these changes May 21, 2024
oh, yes - missed this one

Co-authored-by: Oleksandr Levchenkov  <ollevche@gmail.com>
Signed-off-by: Alex Ott <alexott@gmail.com>
@cam72cam cam72cam merged commit 522a859 into opentofu:main May 21, 2024
11 of 12 checks passed
cam72cam added a commit that referenced this pull request May 22, 2024
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
@cam72cam cam72cam mentioned this pull request May 22, 2024
3 tasks
cam72cam added a commit that referenced this pull request May 22, 2024
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
bunniseng pushed a commit to bunniseng/opentofu that referenced this pull request May 28, 2024
Signed-off-by: Alex Ott <alexott@gmail.com>
Co-authored-by: Oleksandr Levchenkov <ollevche@gmail.com>
bunniseng pushed a commit to bunniseng/opentofu that referenced this pull request May 28, 2024
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
@eduzgun
Copy link
Contributor

eduzgun commented Jun 9, 2024

@cam72cam Some of the testdata in /internal/states/statefile/testdata/roundtrip looks wrong and is causing go test ./internal/states/statefile tests to fail. These files are: v4-cbd.out.tfstate, v4-foreach.out.tfstate, v4-modules.out.tfstate, v4-simple.in.tfstate. Should I create a new issue for this?

@cam72cam
Copy link
Contributor

cam72cam commented Jun 9, 2024

@eduzgun, sure create an issue. I can't reproduce that myself, the tests are passing on main.

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.

Pretty-printed JSON representation of a state increases file size by ~20-25%
6 participants