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

Use Go standard library slices package instead of x/exp/slices #50

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

tklauser
Copy link
Member

@tklauser tklauser commented Sep 5, 2024

The former is available since Go 1.21 and the latter is merely a wrapper around it when using Go ≥ 1.21. Use the standard library package directly.

We cannot yet switch out x/exp/maps for the standard library maps package as the maps.Keys function used in statedb code base is only available in Go ≥ 1.23.

@tklauser tklauser requested a review from a team as a code owner September 5, 2024 13:09
@tklauser tklauser requested review from pippolo84 and removed request for a team September 5, 2024 13:09
@tklauser
Copy link
Member Author

tklauser commented Sep 5, 2024

We cannot yet switch out x/exp/maps for the standard library maps package as the maps.Keys function used in statedb code base is only available in Go ≥ 1.23.

Alternatively, we could also bump go.mod to 1.23 and make that switch as well but I'm not sure what the Go version support policy on this repo is. /cc @joamaki

Copy link

github-actions bot commented Sep 5, 2024

$ make test
go: downloading github.com/mitchellh/mapstructure v1.5.0
go: downloading golang.org/x/term v0.16.0
go: downloading github.com/spf13/cast v1.6.0
go: downloading github.com/fsnotify/fsnotify v1.7.0
go: downloading github.com/sagikazarmark/slog-shim v0.1.0
go: downloading github.com/spf13/afero v1.11.0
go: downloading golang.org/x/sys v0.17.0
go: downloading github.com/subosito/gotenv v1.6.0
go: downloading github.com/hashicorp/hcl v1.0.0
go: downloading gopkg.in/ini.v1 v1.67.0
go: downloading github.com/magiconair/properties v1.8.7
go: downloading github.com/pelletier/go-toml/v2 v2.1.0
go: downloading golang.org/x/text v0.14.0
	github.com/cilium/statedb/reconciler/benchmark		coverage: 0.0% of statements
	github.com/cilium/statedb/reconciler/example		coverage: 0.0% of statements
ok  	github.com/cilium/statedb	5.627s	coverage: 88.4% of statements
ok  	github.com/cilium/statedb/index	0.005s	coverage: 44.6% of statements
ok  	github.com/cilium/statedb/internal	0.011s	coverage: 93.3% of statements
ok  	github.com/cilium/statedb/part	2.681s	coverage: 82.8% of statements
ok  	github.com/cilium/statedb/reconciler	2.507s	coverage: 92.9% of statements
-----
$ make bench
go test ./... -bench . -benchmem -test.run xxx
goos: linux
goarch: amd64
pkg: github.com/cilium/statedb
cpu: AMD EPYC 7763 64-Core Processor                
BenchmarkDB_WriteTxn_1-4                    	  455200	      2588 ns/op	    386369 objects/sec	    2800 B/op	      32 allocs/op
BenchmarkDB_WriteTxn_10-4                   	 1209490	      1046 ns/op	    955739 objects/sec	     741 B/op	      10 allocs/op
BenchmarkDB_WriteTxn_100-4                  	 1526876	       784.7 ns/op	   1274444 objects/sec	     596 B/op	       7 allocs/op
BenchmarkDB_WriteTxn_1000-4                 	 1475962	       810.6 ns/op	   1233607 objects/sec	     551 B/op	       7 allocs/op
BenchmarkDB_WriteTxn_100_SecondaryIndex-4   	  517376	      2246 ns/op	    445265 objects/sec	    1489 B/op	      37 allocs/op
BenchmarkDB_Modify-4                        	    1311	    934834 ns/op	   1069710 objects/sec	  773480 B/op	    8462 allocs/op
BenchmarkDB_GetInsert-4                     	    1222	   1005693 ns/op	    994340 objects/sec	  755213 B/op	    8459 allocs/op
BenchmarkDB_RandomInsert-4                  	    2389	    494538 ns/op	   2022090 objects/sec	  402092 B/op	    7097 allocs/op
BenchmarkDB_RandomReplace-4                 	     330	   3659913 ns/op	    273231 objects/sec	 2349510 B/op	   48570 allocs/op
BenchmarkDB_SequentialInsert-4              	    1508	    821537 ns/op	   1217230 objects/sec	  551768 B/op	    7287 allocs/op
BenchmarkDB_Changes_Baseline-4              	    1245	    949597 ns/op	   1053079 objects/sec	  553074 B/op	   10252 allocs/op
BenchmarkDB_Changes-4                       	     709	   1696477 ns/op	    589457 objects/sec	  993253 B/op	   14493 allocs/op
BenchmarkDB_RandomLookup-4                  	   21963	     52939 ns/op	  18889698 objects/sec	     144 B/op	       1 allocs/op
BenchmarkDB_SequentialLookup-4              	   27372	     45718 ns/op	  21873165 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_FullIteration_All-4             	     982	   1275208 ns/op	  78418738 objects/sec	     464 B/op	      12 allocs/op
BenchmarkDB_FullIteration_Get-4             	     218	   5510466 ns/op	  18147314 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_PropagationDelay-4              	  510844	      2314 ns/op	        20.00 50th_µs	        23.00 90th_µs	        86.00 99th_µs	    1585 B/op	      24 allocs/op
PASS
ok  	github.com/cilium/statedb	26.858s
PASS
ok  	github.com/cilium/statedb/index	0.004s
PASS
ok  	github.com/cilium/statedb/internal	0.003s
goos: linux
goarch: amd64
pkg: github.com/cilium/statedb/part
cpu: AMD EPYC 7763 64-Core Processor                
Benchmark_Insert_RootOnlyWatch-4    	    9067	    132492 ns/op	   7547620 objects/sec	  104163 B/op	    2041 allocs/op
Benchmark_Insert-4                  	    6145	    184927 ns/op	   5407549 objects/sec	  219064 B/op	    3065 allocs/op
Benchmark_Modify-4                  	    8134	    142399 ns/op	   7022520 objects/sec	  212303 B/op	    1204 allocs/op
Benchmark_GetInsert-4               	    6615	    177830 ns/op	   5623353 objects/sec	  212351 B/op	    1203 allocs/op
Benchmark_Replace-4                 	27098643	        44.85 ns/op	  22296766 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Replace_RootOnlyWatch-4   	26808273	        44.96 ns/op	  22241443 objects/sec	       0 B/op	       0 allocs/op
Benchmark_txn_1-4                   	 3027760	       405.7 ns/op	   2464726 objects/sec	     448 B/op	       7 allocs/op
Benchmark_txn_10-4                  	 7252398	       163.3 ns/op	   6124082 objects/sec	     154 B/op	       2 allocs/op
Benchmark_txn_100-4                 	 7936075	       152.1 ns/op	   6572923 objects/sec	     224 B/op	       2 allocs/op
Benchmark_txn_1000-4                	 7019612	       173.8 ns/op	   5753185 objects/sec	     216 B/op	       2 allocs/op
Benchmark_txn_delete_1-4            	 3105154	       384.9 ns/op	   2598186 objects/sec	     856 B/op	       6 allocs/op
Benchmark_txn_delete_10-4           	 8487979	       139.4 ns/op	   7174354 objects/sec	     132 B/op	       1 allocs/op
Benchmark_txn_delete_100-4          	10723832	       110.8 ns/op	   9026222 objects/sec	      60 B/op	       1 allocs/op
Benchmark_txn_delete_1000-4         	11331942	       104.8 ns/op	   9544686 objects/sec	      26 B/op	       1 allocs/op
Benchmark_Get-4                     	   38626	     30838 ns/op	  32427940 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Iterate-4                 	  174114	      6934 ns/op	 144211909 objects/sec	      80 B/op	       3 allocs/op
Benchmark_Hashmap_Insert-4          	   15705	     76241 ns/op	  13116400 objects/sec	   86551 B/op	      64 allocs/op
Benchmark_Hashmap_Get_Uint64-4      	  163640	      7382 ns/op	 135460876 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Hashmap_Get_Bytes-4       	  156486	      7674 ns/op	 130314240 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Uint64Map_Random-4        	    1402	    851551 ns/op	   1174329 items/sec	 2702553 B/op	    9022 allocs/op
Benchmark_Uint64Map_Sequential-4    	    1508	    790488 ns/op	   1265041 items/sec	 2492408 B/op	    9749 allocs/op
PASS
ok  	github.com/cilium/statedb/part	28.415s
PASS
ok  	github.com/cilium/statedb/reconciler	0.004s
?   	github.com/cilium/statedb/reconciler/benchmark	[no test files]
?   	github.com/cilium/statedb/reconciler/example	[no test files]
go run ./reconciler/benchmark -quiet
1000000 objects reconciled in 2.95 seconds (batch size 1000)
Throughput 338716.17 objects per second
Allocated 6011279 objects, 424760kB bytes, 517704kB bytes still in use

@joamaki
Copy link
Contributor

joamaki commented Sep 5, 2024

Just merged the range-funcs PR, so cilium/statedb is now at Go v1.23. Could you rebase and switch the maps package too?

EDIT: Did this myself.

Use the standard library packages instead of x/exp/{slices,maps}.
The former is available since Go 1.21 and the latter is merely a wrapper
around it when using Go ≥ 1.21. Use the standard library package
directly.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
Signed-off-by: Jussi Maki <jussi.maki@isovalent.com>
@joamaki joamaki merged commit 271dee5 into main Sep 6, 2024
1 check passed
@joamaki joamaki deleted the stdlib-slices branch September 6, 2024 08:59
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.

3 participants