diff options
author | Paulo Gomes <pjbgf@linux.com> | 2022-11-07 14:42:00 +0000 |
---|---|---|
committer | Paulo Gomes <pjbgf@linux.com> | 2022-11-07 14:42:00 +0000 |
commit | ffa7e69efb8c4ba8d4e08ec4c65e49e2228fd88b (patch) | |
tree | a784f0a4b677abc00247638e600f5efef1c44dfc /plumbing/format | |
parent | 123cdde6f2f6282cb779e03745d384833ac1265b (diff) | |
download | go-git-ffa7e69efb8c4ba8d4e08ec4c65e49e2228fd88b.tar.gz |
Optimise Reference.String()
Decreases allocations and bytes per operation by using string builder
with a predefined size.
One additional allocation has been removed by using its own implementation
of Strings(). The reason behind this was due to the fact the calls to
.String() are more recurrent than .Strings() and the performance impact
was worth the code duplication.
Benchmark results:
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
name old time/op new time/op delta
ReferenceStringSymbolic-16 140ns ± 4% 40ns ± 9% -71.19% (p=0.008 n=5+5)
ReferenceStringHash-16 174ns ±14% 85ns ± 4% -51.13% (p=0.008 n=5+5)
ReferenceStringInvalid-16 48.9ns ± 2% 1.5ns ± 3% -96.96% (p=0.008 n=5+5)
name old alloc/op new alloc/op delta
ReferenceStringSymbolic-16 88.0B ± 0% 32.0B ± 0% -63.64% (p=0.008 n=5+5)
ReferenceStringHash-16 176B ± 0% 144B ± 0% -18.18% (p=0.008 n=5+5)
ReferenceStringInvalid-16 0.00B 0.00B ~ (all equal)
name old allocs/op new allocs/op delta
ReferenceStringSymbolic-16 4.00 ± 0% 1.00 ± 0% -75.00% (p=0.008 n=5+5)
ReferenceStringHash-16 5.00 ± 0% 3.00 ± 0% -40.00% (p=0.008 n=5+5)
ReferenceStringInvalid-16 0.00 0.00 ~ (all equal)
Signed-off-by: Paulo Gomes <pjbgf@linux.com>
Diffstat (limited to 'plumbing/format')
0 files changed, 0 insertions, 0 deletions