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

Further improvements in runtime metadata loading #1524

Merged
merged 4 commits into from
Nov 16, 2023

Conversation

mjeffryes
Copy link
Member

@mjeffryes mjeffryes commented Nov 15, 2023

Two changes to further reduce metadata load times for large providers:

  1. Use segmentio/encoding/json in zero-copy mode
  2. Generate a trimmed, runtime-only copy of metadata

In particular, removing extra whitespace contributed the most improvement suggesting that we may be able to obtain further savings just by shortening or eliminating frequently repeated strings.

This change is equivalent to the first codegen option described in pulumi/pulumi-aws#2799 (comment) (and combining the two yields no further improvement).

Generation of the runtime-only metadata is controlled via a flag in the ProviderInfo to allow providers to opt in individually.

Benchmarks from AWS:

Before changes

BenchmarkProviderGen
BenchmarkProviderGen-12             	       6	 189483917 ns/op	331080480 B/op	 2222893 allocs/op
BenchmarkProviderNoGen
BenchmarkProviderNoGen-12           	       7	 160893363 ns/op	287969720 B/op	 1850232 allocs/op

With zero-copy deserializer

BenchmarkProviderGen
BenchmarkProviderGen-12             	       6	 179858674 ns/op	331078597 B/op	 2222880 allocs/op
BenchmarkProviderNoGen
BenchmarkProviderNoGen-12           	       7	 155430929 ns/op	287963872 B/op	 1850211 allocs/op

With zero-copy deserializer and trimmed runtime only metadata

BenchmarkRuntimeProviderGen
BenchmarkRuntimeProviderGen-12      	       8	 132763682 ns/op	331080280 B/op	 2222892 allocs/op
BenchmarkRuntimeProviderNoGen
BenchmarkRuntimeProviderNoGen-12    	      10	 108300512 ns/op	287966743 B/op	 1850214 allocs/op

Copy link

codecov bot commented Nov 15, 2023

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (6e919a0) 57.94% compared to head (6a98a47) 57.97%.

Files Patch % Lines
unstable/metadata/metadata.go 84.21% 5 Missing and 1 partial ⚠️
pkg/tfgen/generate.go 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1524      +/-   ##
==========================================
+ Coverage   57.94%   57.97%   +0.03%     
==========================================
  Files         286      286              
  Lines       39670    39687      +17     
==========================================
+ Hits        22988    23010      +22     
+ Misses      15342    15336       -6     
- Partials     1340     1341       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mjeffryes mjeffryes force-pushed the mjeffryes/two-pass-max-items-one branch from 85a5a62 to 0eb4188 Compare November 15, 2023 17:54
@mjeffryes mjeffryes changed the title Draft: Mjeffryes/two pass max items one Further improvements in runtime metadata loading Nov 15, 2023
@mjeffryes mjeffryes requested a review from a team November 15, 2023 18:39
@mjeffryes mjeffryes marked this pull request as ready for review November 15, 2023 18:41
@mjeffryes mjeffryes force-pushed the mjeffryes/two-pass-max-items-one branch from 0eb4188 to 34fc389 Compare November 15, 2023 18:49
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

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

This looks like a good incremental step in load performance. LGTM

// to help reduce resource plugin start time
//
// See also pulumi/pulumi-terraform-bridge#1524
GenerateRuntimeMetadata bool
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason why a provider would not want this flag enabled?

Put another way, if we were 100% confident that this would work as intended, would we enable it for all of our providers?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's not a lot of value for smaller providers, the data in the runtime config is strictly redundant with bridge-metadata.json (while being harder to read/edite) and it requires changing up the init a bit to use the runtime file for the runtime binary. So for now, I don't think it's worthwhile to try to enable this everywhere, lots of little frictions for minimal benefit on most providers.

We might revisit this as part of a larger effort to distinguish gentime/runtime though.

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense to me.

pkg/tfbridge/metadata.go Outdated Show resolved Hide resolved
Co-authored-by: Ian Wahbe <[email protected]>
@mjeffryes mjeffryes enabled auto-merge (rebase) November 16, 2023 04:25
@mjeffryes mjeffryes merged commit 89a4965 into master Nov 16, 2023
9 checks passed
@mjeffryes mjeffryes deleted the mjeffryes/two-pass-max-items-one branch November 16, 2023 04:38
mjeffryes added a commit to pulumi/pulumi-aws that referenced this pull request Nov 20, 2023
Enable the trimmed metadata from
pulumi/pulumi-terraform-bridge#1524 to squeeze
some milliseconds out of the provider init.



### Benchmarks 
```
❯ go test -bench "Provider$" -run "^$" -v -benchmem
goos: darwin
goarch: arm64
pkg: github.com/pulumi/pulumi-aws/provider/v6
BenchmarkProvider
BenchmarkProvider-12           	       6	 188479375 ns/op	331332504 B/op	 2225300 allocs/op
BenchmarkRuntimeProvider
BenchmarkRuntimeProvider-12    	       8	 141554162 ns/op	331336897 B/op	 2225309 allocs/op
```
Note that these benchmarks are run with aliasing history generation
enabled (we don't expose an api for disabling it to the provider), so
they are slower than actual runtime performance.
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