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

Rename First to Get and Get to List/ListWatch #26

Merged
merged 1 commit into from
May 8, 2024

Conversation

joamaki
Copy link
Contributor

@joamaki joamaki commented May 8, 2024

The First() method name has been an eye sore from the start. This is now a good point to rename it as we're about to switch Cilium to using cilium/statedb and need to refactor a bunch of code anyway.

Before:

  obj, rev, found := table.First(txn, MyIndex.Query("foo"))
  obj, rev, found, watch := table.FirstWatch(txn, MyIndex.Query("foo"))

  iter, watch := table.Get(txn, MyIndex.Query("foo"))

Now:

  obj, rev, found := table.Get(txn, MyIndex.Query("foo"))
  obj, rev, found, watch := table.GetWatch(txn, MyIndex.Query("foo"))

  iter := table.List(txn, MyIndex.Query("foo"))
  iter, watch := table.ListWatch(txn, MyIndex.Query("foo"))

The First() method name has been an eye sore from the start. This is
now a good point to rename it as we're about to switch Cilium to using
cilium/statedb and need to refactor a bunch of code anyway.

Before:

  obj, rev, found := table.First(txn, MyIndex.Query("foo"))
  obj, rev, found, watch := table.FirstWatch(txn, MyIndex.Query("foo"))

  iter, watch := table.Get(txn, MyIndex.Query("foo"))

Now:

  obj, rev, found := table.Get(txn, MyIndex.Query("foo"))
  obj, rev, found, watch := table.GetWatch(txn, MyIndex.Query("foo"))

  iter := table.List(txn, MyIndex.Query("foo"))
  iter, watch := table.ListWatch(txn, MyIndex.Query("foo"))

Signed-off-by: Jussi Maki <[email protected]>
@joamaki joamaki requested a review from bimmlerd May 8, 2024 13:17
Copy link

github-actions bot commented May 8, 2024

$ make test
go: downloading github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
go: downloading gopkg.in/yaml.v3 v3.0.1
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 github.com/spf13/cast v1.6.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 golang.org/x/text v0.14.0
go: downloading github.com/pelletier/go-toml/v2 v2.1.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.640s	coverage: 88.0% of statements
ok  	github.com/cilium/statedb/index	0.005s	coverage: 25.5% of statements
ok  	github.com/cilium/statedb/internal	0.008s	coverage: 93.3% of statements
ok  	github.com/cilium/statedb/part	1.861s	coverage: 85.9% of statements
ok  	github.com/cilium/statedb/reconciler	5.093s	coverage: 89.7% 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                    	  472584	      2523 ns/op	    396304 objects/sec	    2688 B/op	      32 allocs/op
BenchmarkDB_WriteTxn_10-4                   	 1235761	       966.5 ns/op	   1034691 objects/sec	     713 B/op	      10 allocs/op
BenchmarkDB_WriteTxn_100-4                  	 1520452	       773.1 ns/op	   1293413 objects/sec	     580 B/op	       7 allocs/op
BenchmarkDB_WriteTxn_1000-4                 	 1529749	       788.7 ns/op	   1267974 objects/sec	     532 B/op	       7 allocs/op
BenchmarkDB_WriteTxn_10000-4                	 1200286	      1013 ns/op	    986845 objects/sec	     551 B/op	       7 allocs/op
BenchmarkDB_WriteTxn_100_SecondaryIndex-4   	  535803	      2207 ns/op	    453039 objects/sec	    1670 B/op	      30 allocs/op
BenchmarkDB_RandomInsert-4                  	    2470	    480697 ns/op	   2080313 objects/sec	  385922 B/op	    7098 allocs/op
BenchmarkDB_RandomReplace-4                 	     429	   2786882 ns/op	    358824 objects/sec	 1863448 B/op	   31564 allocs/op
BenchmarkDB_SequentialInsert-4              	    1581	    785130 ns/op	   1273674 objects/sec	  533531 B/op	    7287 allocs/op
BenchmarkDB_Changes_Baseline-4              	    1251	    950204 ns/op	   1052408 objects/sec	  536139 B/op	   10246 allocs/op
BenchmarkDB_Changes-4                       	     686	   1699980 ns/op	    588242 objects/sec	  963954 B/op	   14539 allocs/op
BenchmarkDB_RandomLookup-4                  	   20919	     58487 ns/op	  17097965 objects/sec	     144 B/op	       1 allocs/op
BenchmarkDB_SequentialLookup-4              	   23767	     50734 ns/op	  19710816 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_FullIteration_All-4             	     716	   1769127 ns/op	  56525156 objects/sec	     360 B/op	       7 allocs/op
BenchmarkDB_FullIteration_Get-4             	     194	   6144751 ns/op	  16274088 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_PropagationDelay-4              	  500124	      2243 ns/op	        19.00 50th_µs	        22.00 90th_µs	       101.0 99th_µs	    1504 B/op	      24 allocs/op
PASS
ok  	github.com/cilium/statedb	26.367s
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    	    9897	    123857 ns/op	   8073798 objects/sec	  104127 B/op	    2041 allocs/op
Benchmark_Insert-4                  	    6406	    170795 ns/op	   5854961 objects/sec	  202684 B/op	    3065 allocs/op
Benchmark_Replace-4                 	29426510	        40.88 ns/op	  24460192 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Replace_RootOnlyWatch-4   	29572134	        40.82 ns/op	  24496949 objects/sec	       0 B/op	       0 allocs/op
Benchmark_txn_1-4                   	 3003064	       398.8 ns/op	   2507351 objects/sec	     432 B/op	       7 allocs/op
Benchmark_txn_10-4                  	 7361182	       159.2 ns/op	   6283051 objects/sec	     152 B/op	       2 allocs/op
Benchmark_txn_100-4                 	 6272565	       178.0 ns/op	   5619037 objects/sec	     223 B/op	       2 allocs/op
Benchmark_txn_1000-4                	 7397023	       162.7 ns/op	   6147799 objects/sec	     215 B/op	       2 allocs/op
Benchmark_txn_10000-4               	 5273307	       226.1 ns/op	   4423365 objects/sec	     237 B/op	       2 allocs/op
Benchmark_txn_100000-4              	 3691851	       293.2 ns/op	   3410163 objects/sec	     337 B/op	       2 allocs/op
Benchmark_txn_delete_1-4            	 3337540	       362.5 ns/op	   2758925 objects/sec	     840 B/op	       6 allocs/op
Benchmark_txn_delete_10-4           	 8296760	       144.1 ns/op	   6941706 objects/sec	     131 B/op	       1 allocs/op
Benchmark_txn_delete_100-4          	10868623	       111.7 ns/op	   8955537 objects/sec	      60 B/op	       1 allocs/op
Benchmark_txn_delete_1000-4         	11867900	       100.8 ns/op	   9919941 objects/sec	      26 B/op	       1 allocs/op
Benchmark_txn_delete_10000-4        	 9942074	       120.1 ns/op	   8325635 objects/sec	      25 B/op	       1 allocs/op
Benchmark_txn_delete_100000-4       	 7769179	       136.7 ns/op	   7314112 objects/sec	      26 B/op	       1 allocs/op
Benchmark_Get-4                     	   39244	     31276 ns/op	  31973190 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Iterate-4                 	  163147	      7512 ns/op	 133112223 objects/sec	      80 B/op	       3 allocs/op
Benchmark_Hashmap_Insert-4          	   15382	     78120 ns/op	  12800822 objects/sec	   86558 B/op	      64 allocs/op
Benchmark_Hashmap_Get_Uint64-4      	  148689	      8127 ns/op	 123039633 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Hashmap_Get_Bytes-4       	  148470	      8078 ns/op	 123797303 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Uint64Map_Random-4        	    1350	    892335 ns/op	   1120656 items/sec	 2684598 B/op	    9028 allocs/op
Benchmark_Uint64Map_Sequential-4    	    1432	    841620 ns/op	   1188187 items/sec	 2476394 B/op	    9749 allocs/op
PASS
ok  	github.com/cilium/statedb/part	32.493s
PASS
ok  	github.com/cilium/statedb/reconciler	0.005s
?   	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 3.03 seconds (batch size 1000)
Throughput 329651.16 objects per second
Allocated 6011384 objects, 393440kB bytes, 551488kB bytes still in use

Copy link
Member

@bimmlerd bimmlerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@joamaki joamaki merged commit 814f9a1 into main May 8, 2024
1 check passed
@joamaki joamaki deleted the pr/joamaki/api-tweaks branch May 8, 2024 14:22
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.

2 participants