terraform/addrs
Dennis Gursky 4e42d21837
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 tabs
2021-04-05 08:44:27 -04:00
..
count_attr.go addrs: All Referenceable implementations support String() 2018-10-16 18:44:26 -07:00
doc.go addrs: new package for representing addresses 2018-10-16 18:44:26 -07:00
for_each_attr.go Resource for_each 2019-07-22 10:51:16 -04:00
input_variable.go Module Expansion: Part 2 (#24154) 2020-02-24 17:42:32 -05:00
instance_key.go Add InstanceKey.Value method 2020-02-19 16:02:40 -05:00
local_value.go addrs: flesh out functionality ready to replace terraform.ResourceAddress 2018-10-16 18:44:26 -07:00
module.go core: Reduce string allocations for addrs Equal 2021-03-05 13:23:32 -05:00
module_call.go Update addrs/module_call.go 2020-04-10 14:45:36 -04:00
module_instance.go Improve ModuleInstance String() performance (#28246) 2021-04-05 08:44:27 -04:00
module_instance_test.go Improve ModuleInstance String() performance (#28246) 2021-04-05 08:44:27 -04:00
module_test.go core: Reduce string allocations for addrs Equal 2021-03-05 13:23:32 -05:00
output_value.go core: Reduce string allocations for addrs Equal 2021-03-05 13:23:32 -05:00
output_value_test.go core: Reduce string allocations for addrs Equal 2021-03-05 13:23:32 -05:00
parse_ref.go parse module references as whole modules 2020-04-12 11:26:44 -04:00
parse_ref_test.go parse module references as whole modules 2020-04-12 11:26:44 -04:00
parse_target.go vendor: switch to HCL 2.0 in the HCL repository 2019-10-02 15:10:21 -07:00
parse_target_test.go implement addrs.ConfigResource 2020-03-12 15:58:25 -04:00
path_attr.go addrs: All Referenceable implementations support String() 2018-10-16 18:44:26 -07:00
provider.go addrs: Fix LegacyString for builtin provider addrs 2020-08-14 14:56:35 -04:00
provider_config.go addrs: detect builtin provider when parsing legacy provider string (#25154) 2020-06-08 08:27:36 -04:00
provider_config_test.go remove LegacyProvider (#26433) 2020-10-05 08:33:49 -04:00
provider_test.go addrs: Fix LegacyString for builtin provider addrs 2020-08-14 14:56:35 -04:00
referenceable.go addrs: All Referenceable implementations support String() 2018-10-16 18:44:26 -07:00
resource.go core: Reduce string allocations for addrs Equal 2021-03-05 13:23:32 -05:00
resource_phase.go core: Produce correct references for destroy nodes 2018-10-16 18:49:20 -07:00
resource_test.go core: Reduce string allocations for addrs Equal 2021-03-05 13:23:32 -05:00
resourcemode_string.go stringer: Regenerate files with latest version 2019-05-13 15:34:27 +01:00
self.go addrs: All Referenceable implementations support String() 2018-10-16 18:44:26 -07:00
target_test.go unkeyed target ModulesInstance can be Modules 2020-06-09 21:58:58 -04:00
targetable.go addrs: flesh out functionality ready to replace terraform.ResourceAddress 2018-10-16 18:44:26 -07:00
terraform_attr.go addrs: All Referenceable implementations support String() 2018-10-16 18:44:26 -07:00