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

chore: use a single buffer for field checks #16

Merged
1 commit merged into from
Aug 26, 2024
Merged

chore: use a single buffer for field checks #16

1 commit merged into from
Aug 26, 2024

Conversation

ghost
Copy link

@ghost ghost commented Aug 26, 2024

Instead of creating a new string every for each possible version of a field we now (re-)use a single byte array to do the same.

Benchmark comparison is:

goos: linux
goarch: amd64
pkg: github.com/terramate-io/tfjson/v2/sanitize
cpu: 13th Gen Intel(R) Core(TM) i7-13620H
                  │   v2.txt    │              v2_pr.txt              │
                  │   sec/op    │   sec/op     vs base                │
LargeChangeset-16   24.55µ ± 6%   13.01µ ± 2%  -46.99% (p=0.000 n=10)

                  │   v2.txt    │             v2_pr.txt              │
                  │    B/op     │    B/op     vs base                │
LargeChangeset-16   7672.0 ± 0%   784.0 ± 0%  -89.78% (p=0.000 n=10)

                  │   v2.txt    │             v2_pr.txt              │
                  │  allocs/op  │ allocs/op   vs base                │
LargeChangeset-16   368.00 ± 0%   42.00 ± 0%  -88.59% (p=0.000 n=10)

Before:

goos: linux
goarch: amd64
pkg: github.com/terramate-io/tfjson/v2/sanitize
cpu: 13th Gen Intel(R) Core(TM) i7-13620H
BenchmarkLargeChangeset
BenchmarkLargeChangeset-16    	   46780	     22959 ns/op	    7672 B/op	     368 allocs/op
BenchmarkLargeChangeset-16    	   45748	     23622 ns/op	    7672 B/op	     368 allocs/op
BenchmarkLargeChangeset-16    	   51043	     24620 ns/op	    7672 B/op	     368 allocs/op
BenchmarkLargeChangeset-16    	   48404	     23003 ns/op	    7672 B/op	     368 allocs/op
BenchmarkLargeChangeset-16    	   44822	     25041 ns/op	    7672 B/op	     368 allocs/op
BenchmarkLargeChangeset-16    	   46743	     24831 ns/op	    7672 B/op	     368 allocs/op
BenchmarkLargeChangeset-16    	   51252	     25010 ns/op	    7672 B/op	     368 allocs/op
BenchmarkLargeChangeset-16    	   48674	     23974 ns/op	    7672 B/op	     368 allocs/op
BenchmarkLargeChangeset-16    	   45248	     24541 ns/op	    7672 B/op	     368 allocs/op
BenchmarkLargeChangeset-16    	   50532	     24560 ns/op	    7672 B/op	     368 allocs/op
PASS
ok  	github.com/terramate-io/tfjson/v2/sanitize	14.217s

With PR:

goos: linux
goarch: amd64
pkg: github.com/terramate-io/tfjson/v2/sanitize
cpu: 13th Gen Intel(R) Core(TM) i7-13620H
BenchmarkLargeChangeset
BenchmarkLargeChangeset-16    	   88532	     12938 ns/op	     784 B/op	      42 allocs/op
BenchmarkLargeChangeset-16    	   88912	     13293 ns/op	     784 B/op	      42 allocs/op
BenchmarkLargeChangeset-16    	   91579	     13061 ns/op	     784 B/op	      42 allocs/op
BenchmarkLargeChangeset-16    	   91285	     12980 ns/op	     784 B/op	      42 allocs/op
BenchmarkLargeChangeset-16    	   91048	     13062 ns/op	     784 B/op	      42 allocs/op
BenchmarkLargeChangeset-16    	   91712	     12895 ns/op	     784 B/op	      42 allocs/op
BenchmarkLargeChangeset-16    	   91569	     12948 ns/op	     784 B/op	      42 allocs/op
BenchmarkLargeChangeset-16    	   91477	     13012 ns/op	     784 B/op	      42 allocs/op
BenchmarkLargeChangeset-16    	   91344	     13227 ns/op	     784 B/op	      42 allocs/op
BenchmarkLargeChangeset-16    	   91731	     13015 ns/op	     784 B/op	      42 allocs/op
PASS
ok  	github.com/terramate-io/tfjson/v2/sanitize	13.270s

@ghost ghost marked this pull request as ready for review August 26, 2024 08:22
@ghost ghost self-requested a review as a code owner August 26, 2024 08:22
Base automatically changed from v2 to main August 26, 2024 08:23
Instead of creating a new string every for each possible version of a field we now (re-)use a single byte array to do the same.

Benchmark comparison is:
```
goos: linux
goarch: amd64
pkg: github.com/terramate-io/tfjson/v2/sanitize
cpu: 13th Gen Intel(R) Core(TM) i7-13620H
                  │   v2.txt    │              v2_pr.txt              │
                  │   sec/op    │   sec/op     vs base                │
LargeChangeset-16   24.55µ ± 6%   13.01µ ± 2%  -46.99% (p=0.000 n=10)

                  │   v2.txt    │             v2_pr.txt              │
                  │    B/op     │    B/op     vs base                │
LargeChangeset-16   7672.0 ± 0%   784.0 ± 0%  -89.78% (p=0.000 n=10)

                  │   v2.txt    │             v2_pr.txt              │
                  │  allocs/op  │ allocs/op   vs base                │
LargeChangeset-16   368.00 ± 0%   42.00 ± 0%  -88.59% (p=0.000 n=10)
```
@ghost ghost force-pushed the byte-arr branch from f248d59 to 887768c Compare August 26, 2024 08:24
@ghost ghost merged commit df0dd23 into main Aug 26, 2024
5 checks passed
@ghost ghost deleted the byte-arr branch August 26, 2024 09:20
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant