mirror of https://github.com/hashicorp/terraform
Improve ModuleInstance String() performance (#28246)
* Optimize (m ModuleInstance) String() Optimize (m ModuleInstance) String() to preallocate the buffer and use strings.Builder instead of bytes.Buffer This leads to a common case only doing a single allocation as opposed to a few allocations which the bytes.Buffer is doing. * adding a benchmark test Result: ``` $ go test -bench=String ./addrs -benchmem BenchmarkStringShort-12 18271692 56.52 ns/op 16 B/op 1 allocs/op BenchmarkStringLong-12 8057071 158.5 ns/op 96 B/op 1 allocs/op PASS $ git checkout main addrs/module_instance.go $ go test -bench=String ./addrs -benchmem BenchmarkStringShort-12 7690818 162.0 ns/op 80 B/op 2 allocs/op BenchmarkStringLong-12 2922117 414.1 ns/op 288 B/op 3 allocs/op ``` * Update module_instance_test.go switch spaces to tabspull/28310/head
parent
973ed6eae6
commit
4e42d21837
Loading…
Reference in new issue