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 package init costs #3717

Closed
moorereason opened this issue Dec 30, 2020 · 2 comments
Closed

Reduce package init costs #3717

moorereason opened this issue Dec 30, 2020 · 2 comments
Labels
feature-request A feature should be added or improved.

Comments

@moorereason
Copy link

Is your feature request related to a problem? Please describe.

While testing the new init cost debugging output in go 1.16, I found that aws/endpoints has the highest package-level memory cost out of Hugo's many dependencies.

$ grep aws-sdk-go go.mod
        github.com/aws/aws-sdk-go v1.35.0
$ GODEBUG=inittrace=1 go run . version 2>&1 | rg aws-sdk-go | tee time.txt
init github.com/aws/aws-sdk-go/internal/ini @30 ms, 0.008 ms clock, 2304 bytes, 22 allocs
init github.com/aws/aws-sdk-go/aws/credentials @30 ms, 0.002 ms clock, 496 bytes, 8 allocs
init github.com/aws/aws-sdk-go/aws/endpoints @30 ms, 0.98 ms clock, 852984 bytes, 5396 allocs
init github.com/aws/aws-sdk-go/aws @31 ms, 0.004 ms clock, 128 bytes, 2 allocs
init github.com/aws/aws-sdk-go/aws/awsutil @31 ms, 0.009 ms clock, 3416 bytes, 31 allocs
init github.com/aws/aws-sdk-go/aws/request @31 ms, 0.003 ms clock, 976 bytes, 9 allocs
init github.com/aws/aws-sdk-go/internal/sdkrand @31 ms, 0.044 ms clock, 5448 bytes, 3 allocs
init github.com/aws/aws-sdk-go/private/protocol @32 ms, 0 ms clock, 0 bytes, 0 allocs
init github.com/aws/aws-sdk-go/private/protocol/rest @32 ms, 0.003 ms clock, 56 bytes, 3 allocs
init github.com/aws/aws-sdk-go/aws/signer/v4 @32 ms, 0.011 ms clock, 1392 bytes, 4 allocs
init github.com/aws/aws-sdk-go/service/sts @32 ms, 0.002 ms clock, 0 bytes, 0 allocs
init github.com/aws/aws-sdk-go/aws/corehandlers @32 ms, 0.017 ms clock, 2184 bytes, 31 allocs
init github.com/aws/aws-sdk-go/private/protocol/json/jsonutil @32 ms, 0.002 ms clock, 112 bytes, 4 allocs
init github.com/aws/aws-sdk-go/aws/session @32 ms, 0.003 ms clock, 320 bytes, 5 allocs
init github.com/aws/aws-sdk-go/private/protocol/eventstream @40 ms, 0 ms clock, 0 bytes, 0 allocs
init github.com/aws/aws-sdk-go/service/s3 @40 ms, 0.057 ms clock, 51584 bytes, 346 allocs
init github.com/aws/aws-sdk-go/service/s3/s3manager @40 ms, 0.004 ms clock, 48 bytes, 2 allocs
$ cat time.txt | awk '$5 > 0 {print $5}' | paste -sd+ | bc
1.149
$ cat time.txt | awk '$5 > 0 {print $8}' | paste -sd+ | bc
921448
$ cat time.txt | awk '$5 > 0 {print $10}' | paste -sd+ | bc
5866

The last 3 commands are summing all packages: 1.149 ms clock, 921448 bytes, and 5866 allocs.

Describe the solution you'd like

Reduce package init costs.

Additional context

I'd recommend using sync.Once to defer creating awsPartition and friends. The Go team uses this technique to defer building a large HTML entities map until it's needed.

@moorereason moorereason added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 30, 2020
@skotambkar
Copy link
Contributor

This issue has been fixed in aws/aws-sdk-go-v2 as we separated the endpoints across modules.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@vudh1 vudh1 removed the needs-triage This issue or PR still needs to be triaged. label Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

3 participants