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

Backport of Performance: string builder speedup for Module.String() into v1.2 #31307

Merged
merged 3 commits into from Jun 23, 2022

Conversation

teamterraform
Copy link
Contributor

Backport

This PR is auto-generated from #31293 to be assessed for backporting due to the inclusion of the label 1.2-backport.

The below text is copied from the body of the original PR.


After the change:

terraform/internal/addrs$ go test -bench=Module . -benchmem
BenchmarkModuleStringShort-12           15489140                77.80 ns/op           24 B/op          1 allocs/op          
BenchmarkModuleStringLong-12            10807070               111.8 ns/op            80 B/op          1 allocs/op   

before the change:

BenchmarkModuleStringShort-12            3290968               384.2 ns/op           120 B/op          3 allocs/op          
BenchmarkModuleStringLong-12             1859038               668.4 ns/op           304 B/op          4 allocs/op  

About 5x speedup for time, and only single allocation.

Inspiration for this change is perf profiling on a particularly large config which points to memory churn:

  29.34%  terraform  terraform         [.] runtime.scanobject                                                               
  12.31%  terraform  terraform         [.] runtime.findObject                                                               
  11.94%  terraform  terraform         [.] runtime.greyobject                                                               
   8.35%  terraform  terraform         [.] runtime.heapBitsSetType                                                          
   7.25%  terraform  terraform         [.] runtime.mallocgc                                                                 
   5.10%  terraform  terraform         [.] strings.Join                                                                     
   3.12%  terraform  terraform         [.] runtime.memmove                                                                  
   3.02%  terraform  terraform         [.] runtime.gcDrain                                                                  
   2.85%  terraform  terraform         [.] google3/third_party/golang/hashicorp/terraform/addrs/addrs.Module.String         
   2.13%  terraform  terraform         [.] runtime.growslice                                                                
   1.65%  terraform  terraform         [.] google3/third_party/golang/hashicorp/terraform/terraform/terraform.(*nodeExpandMo
   1.02%  terraform  terraform         [.] runtime.sweepone                                                                 
   0.99%  terraform  terraform         [.] runtime.(*sweepLocked).sweep                                                     
   0.77%  terraform  terraform         [.] runtime.(*spanSet).pop                                                           
   0.68%  terraform  terraform         [.] runtime.memclrNoHeapPointers     

@teamterraform teamterraform force-pushed the backport/main/lovely-fleet-bull branch from 00e4d8a to f9ebeb3 Compare June 23, 2022 14:59
@alisdair alisdair merged commit 34a3e6c into v1.2 Jun 23, 2022
@alisdair alisdair deleted the backport/main/lovely-fleet-bull branch June 23, 2022 15:05
@github-actions
Copy link

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants