Skip to content

index: make prefix keys use the canonicalized form#144

Merged
bimmlerd merged 1 commit intomainfrom
pr/bimmlerd/canonical-cidr-keys
Feb 17, 2026
Merged

index: make prefix keys use the canonicalized form#144
bimmlerd merged 1 commit intomainfrom
pr/bimmlerd/canonical-cidr-keys

Conversation

@bimmlerd
Copy link
Copy Markdown
Member

10.0.0.100/8 and 10.0.0.0/8 (the canonical form) are equivalent in what IPs they contain. However, the key bytes produced by NetIPPrefix would retain the (arguably garbage) bytes after the relevant prefix. Let's not.

10.0.0.100/8 and 10.0.0.0/8 (the canonical form) are equivalent in what
IPs they contain. However, the key bytes produced by NetIPPrefix would retain
the (arguably garbage) bytes after the relevant prefix. Let's not.

Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
@bimmlerd bimmlerd requested a review from a team as a code owner February 12, 2026 16:06
@bimmlerd bimmlerd requested review from derailed and removed request for a team February 12, 2026 16:06
@github-actions
Copy link
Copy Markdown

$ make
go build ./...
go: downloading go.yaml.in/yaml/v3 v3.0.3
go: downloading github.com/cilium/hive v0.0.0-20250731144630-28e7a35ed227
go: downloading golang.org/x/time v0.5.0
go: downloading github.com/spf13/cobra v1.8.0
go: downloading github.com/spf13/pflag v1.0.5
go: downloading github.com/cilium/stream v0.0.0-20240209152734-a0792b51812d
go: downloading github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
go: downloading github.com/spf13/viper v1.18.2
go: downloading go.uber.org/dig v1.17.1
go: downloading golang.org/x/term v0.16.0
go: downloading github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
go: downloading github.com/mitchellh/mapstructure v1.5.0
go: downloading golang.org/x/sys v0.17.0
go: downloading golang.org/x/tools v0.17.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 github.com/spf13/cast v1.6.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 gopkg.in/yaml.v3 v3.0.1
go: downloading golang.org/x/text v0.14.0
STATEDB_VALIDATE=1 go test ./... -cover -vet=all -test.count 1
go: downloading github.com/stretchr/testify v1.8.4
go: downloading go.uber.org/goleak v1.3.0
go: downloading golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
go: downloading github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
ok  	github.com/cilium/statedb	420.148s	coverage: 78.6% of statements
ok  	github.com/cilium/statedb/index	0.005s	coverage: 33.7% of statements
ok  	github.com/cilium/statedb/internal	0.014s	coverage: 42.9% of statements
ok  	github.com/cilium/statedb/lpm	4.236s	coverage: 77.9% of statements
ok  	github.com/cilium/statedb/part	67.329s	coverage: 87.2% of statements
ok  	github.com/cilium/statedb/reconciler	0.212s	coverage: 92.3% of statements
	github.com/cilium/statedb/reconciler/benchmark		coverage: 0.0% of statements
	github.com/cilium/statedb/reconciler/example		coverage: 0.0% of statements
go test -race ./... -test.count 1
ok  	github.com/cilium/statedb	38.873s
ok  	github.com/cilium/statedb/index	1.015s
ok  	github.com/cilium/statedb/internal	1.026s
ok  	github.com/cilium/statedb/lpm	2.828s
ok  	github.com/cilium/statedb/part	36.092s
ok  	github.com/cilium/statedb/reconciler	1.349s
?   	github.com/cilium/statedb/reconciler/benchmark	[no test files]
?   	github.com/cilium/statedb/reconciler/example	[no test files]
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                      	  682494	      1682 ns/op	    594519 objects/sec	    1000 B/op	      16 allocs/op
BenchmarkDB_WriteTxn_10-4                     	 1706425	       695.4 ns/op	   1437999 objects/sec	     520 B/op	       8 allocs/op
BenchmarkDB_WriteTxn_100-4                    	 2142108	       605.7 ns/op	   1650917 objects/sec	     490 B/op	       7 allocs/op
BenchmarkDB_WriteTxn_1000-4                   	 1932518	       622.8 ns/op	   1605745 objects/sec	     447 B/op	       7 allocs/op
BenchmarkDB_WriteTxn_100_SecondaryIndex-4     	  835593	      1301 ns/op	    768642 objects/sec	    1007 B/op	      20 allocs/op
BenchmarkDB_WriteTxn_CommitOnly_100Tables-4   	  902656	      1166 ns/op	    1112 B/op	       5 allocs/op
BenchmarkDB_WriteTxn_CommitOnly_1Table-4      	 1614201	       744.4 ns/op	     224 B/op	       5 allocs/op
BenchmarkDB_NewWriteTxn-4                     	 1780054	       676.1 ns/op	     200 B/op	       4 allocs/op
BenchmarkDB_WriteTxnCommit100-4               	 1000000	      1155 ns/op	    1096 B/op	       5 allocs/op
BenchmarkDB_NewReadTxn-4                      	549939481	         2.180 ns/op	       0 B/op	       0 allocs/op
BenchmarkDB_Modify-4                          	    1732	    676133 ns/op	   1479000 objects/sec	  471644 B/op	    8072 allocs/op
BenchmarkDB_GetInsert-4                       	    1597	    757924 ns/op	   1319394 objects/sec	  455643 B/op	    8072 allocs/op
BenchmarkDB_RandomInsert-4                    	    1878	    633311 ns/op	   1579002 objects/sec	  447630 B/op	    7072 allocs/op
BenchmarkDB_RandomReplace-4                   	     478	   2500850 ns/op	    399864 objects/sec	 1924781 B/op	   29102 allocs/op
BenchmarkDB_SequentialInsert-4                	    1938	    618722 ns/op	   1616236 objects/sec	  447631 B/op	    7072 allocs/op
BenchmarkDB_SequentialInsert_Prefix-4         	     490	   2447238 ns/op	    408624 objects/sec	 3562711 B/op	   45541 allocs/op
BenchmarkDB_Changes_Baseline-4                	    1579	    748911 ns/op	   1335273 objects/sec	  507774 B/op	    9163 allocs/op
BenchmarkDB_Changes-4                         	     937	   1274898 ns/op	    784376 objects/sec	  709038 B/op	   12314 allocs/op
BenchmarkDB_RandomLookup-4                    	   22326	     53940 ns/op	  18539104 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_SequentialLookup-4                	   26701	     44857 ns/op	  22293147 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_Prefix_SecondaryIndex-4           	    6986	    163146 ns/op	   6129485 objects/sec	  124920 B/op	    1025 allocs/op
BenchmarkDB_FullIteration_All-4               	    1026	   1160417 ns/op	  86175936 objects/sec	     104 B/op	       4 allocs/op
BenchmarkDB_FullIteration_Prefix-4            	    1092	   1082304 ns/op	  92395472 objects/sec	     136 B/op	       5 allocs/op
BenchmarkDB_FullIteration_Get-4               	     205	   5735106 ns/op	  17436469 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_FullIteration_Get_Secondary-4     	      81	  12833274 ns/op	   7792244 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_FullIteration_ReadTxnGet-4        	     181	   6444265 ns/op	  15517674 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_PropagationDelay-4                	  637102	      1712 ns/op	        14.00 50th_µs	        17.00 90th_µs	        68.00 99th_µs	    1120 B/op	      19 allocs/op
BenchmarkDB_WriteTxn_100_LPMIndex-4           	  498894	      2390 ns/op	    418417 objects/sec	    1778 B/op	      37 allocs/op
BenchmarkDB_WriteTxn_1_LPMIndex-4             	  129612	     14674 ns/op	     68146 objects/sec	   15738 B/op	      81 allocs/op
BenchmarkDB_LPMIndex_Get-4                    	     381	   3070648 ns/op	   3256642 objects/sec	       0 B/op	       0 allocs/op
BenchmarkWatchSet_4-4                         	 2213486	       537.8 ns/op	     296 B/op	       4 allocs/op
BenchmarkWatchSet_16-4                        	  796792	      1539 ns/op	    1096 B/op	       5 allocs/op
BenchmarkWatchSet_128-4                       	   89749	     13440 ns/op	    8904 B/op	       5 allocs/op
BenchmarkWatchSet_1024-4                      	    9193	    131835 ns/op	   73743 B/op	       5 allocs/op
PASS
ok  	github.com/cilium/statedb	43.635s
PASS
ok  	github.com/cilium/statedb/index	0.004s
goos: linux
goarch: amd64
pkg: github.com/cilium/statedb/internal
cpu: AMD EPYC 7763 64-Core Processor                
Benchmark_SortableMutex-4   	 6228066	       193.4 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/cilium/statedb/internal	1.209s
goos: linux
goarch: amd64
pkg: github.com/cilium/statedb/lpm
cpu: AMD EPYC 7763 64-Core Processor                
Benchmark_txn_insert/batchSize=1-4         	    1875	    635317 ns/op	   1574019 objects/sec	  838409 B/op	   13975 allocs/op
Benchmark_txn_insert/batchSize=10-4        	    3067	    391378 ns/op	   2555076 objects/sec	  385195 B/op	    6668 allocs/op
Benchmark_txn_insert/batchSize=100-4       	    3225	    368214 ns/op	   2715811 objects/sec	  345613 B/op	    6027 allocs/op
Benchmark_txn_delete/batchSize=1-4         	    1550	    759536 ns/op	   1316593 objects/sec	 1286474 B/op	   13976 allocs/op
Benchmark_txn_delete/batchSize=10-4        	    3223	    380705 ns/op	   2626704 objects/sec	  372418 B/op	    5769 allocs/op
Benchmark_txn_delete/batchSize=100-4       	    3357	    343869 ns/op	   2908088 objects/sec	  286753 B/op	    5038 allocs/op
Benchmark_LPM_Lookup-4                     	    7882	    151489 ns/op	   6601125 objects/sec	       0 B/op	       0 allocs/op
Benchmark_LPM_All-4                        	  132793	      9088 ns/op	 110040411 objects/sec	      32 B/op	       1 allocs/op
Benchmark_LPM_Prefix-4                     	  132682	      9035 ns/op	 110679200 objects/sec	      32 B/op	       1 allocs/op
Benchmark_LPM_LowerBound-4                 	  240600	      4896 ns/op	 102133742 objects/sec	     288 B/op	       2 allocs/op
PASS
ok  	github.com/cilium/statedb/lpm	11.928s
goos: linux
goarch: amd64
pkg: github.com/cilium/statedb/part
cpu: AMD EPYC 7763 64-Core Processor                
Benchmark_Uint64Map_Random-4                  	    1580	    733940 ns/op	   1362509 items/sec	 2527751 B/op	    6039 allocs/op
Benchmark_Uint64Map_Sequential-4              	    1968	    610860 ns/op	   1637037 items/sec	 2216724 B/op	    5754 allocs/op
Benchmark_Uint64Map_Sequential_Insert-4       	    2204	    553717 ns/op	   1805975 items/sec	 2208718 B/op	    4753 allocs/op
Benchmark_Uint64Map_Sequential_Txn_Insert-4   	   10000	    102739 ns/op	   9733446 items/sec	   86352 B/op	    2028 allocs/op
Benchmark_Uint64Map_Random_Insert-4           	    1779	    662171 ns/op	   1510183 items/sec	 2521603 B/op	    5035 allocs/op
Benchmark_Uint64Map_Random_Txn_Insert-4       	    7057	    165613 ns/op	   6038188 items/sec	  117621 B/op	    2398 allocs/op
Benchmark_Insert_RootOnlyWatch-4              	   10000	    108694 ns/op	   9200158 objects/sec	   71504 B/op	    2033 allocs/op
Benchmark_Insert-4                            	    7773	    163954 ns/op	   6099267 objects/sec	  186937 B/op	    3060 allocs/op
Benchmark_Modify-4                            	   12172	     98590 ns/op	  10143037 objects/sec	   58224 B/op	    1007 allocs/op
Benchmark_GetInsert-4                         	    8571	    131403 ns/op	   7610178 objects/sec	   58224 B/op	    1007 allocs/op
Benchmark_Replace-4                           	31702269	        37.69 ns/op	  26534735 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Replace_RootOnlyWatch-4             	31836411	        37.42 ns/op	  26720559 objects/sec	       0 B/op	       0 allocs/op
Benchmark_txn_1-4                             	 5855600	       201.4 ns/op	   4965076 objects/sec	     168 B/op	       3 allocs/op
Benchmark_txn_10-4                            	10479952	       114.3 ns/op	   8745750 objects/sec	      86 B/op	       2 allocs/op
Benchmark_txn_100-4                           	12030153	        96.81 ns/op	  10329500 objects/sec	      80 B/op	       2 allocs/op
Benchmark_txn_1000-4                          	10292589	       115.8 ns/op	   8635763 objects/sec	      65 B/op	       2 allocs/op
Benchmark_txn_delete_1-4                      	 4984347	       238.6 ns/op	   4191961 objects/sec	     664 B/op	       4 allocs/op
Benchmark_txn_delete_10-4                     	10922080	       108.3 ns/op	   9235141 objects/sec	     106 B/op	       1 allocs/op
Benchmark_txn_delete_100-4                    	11919824	        99.31 ns/op	  10069858 objects/sec	      47 B/op	       1 allocs/op
Benchmark_txn_delete_1000-4                   	14401293	        82.50 ns/op	  12121237 objects/sec	      24 B/op	       1 allocs/op
Benchmark_Get-4                               	   45546	     26311 ns/op	  38007347 objects/sec	       0 B/op	       0 allocs/op
Benchmark_All-4                               	  117382	     10454 ns/op	  95656017 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Iterator_All-4                      	  142668	      9975 ns/op	 100251065 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Iterator_Next-4                     	  159315	      7493 ns/op	 133453913 objects/sec	     896 B/op	       1 allocs/op
Benchmark_Hashmap_Insert-4                    	   14844	     80731 ns/op	  12386753 objects/sec	   74264 B/op	      20 allocs/op
Benchmark_Hashmap_Get_Uint64-4                	  136520	      8788 ns/op	 113789194 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Hashmap_Get_Bytes-4                 	  110618	     10806 ns/op	  92544453 objects/sec	       0 B/op	       0 allocs/op
Benchmark_Delete_Random-4                     	      79	  15360275 ns/op	   6510300 objects/sec	 2111844 B/op	  102364 allocs/op
Benchmark_find16-4                            	226564375	         5.295 ns/op	       0 B/op	       0 allocs/op
Benchmark_findIndex16-4                       	100000000	        10.27 ns/op	       0 B/op	       0 allocs/op
Benchmark_find4-4                             	424733254	         2.826 ns/op	       0 B/op	       0 allocs/op
Benchmark_findIndex4-4                        	349754172	         3.428 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/cilium/statedb/part	39.334s
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 2.07 seconds (batch size 1000)
Throughput 482169.95 objects per second
817MB total allocated, 6015194 in-use objects, 338MB bytes in use

Copy link
Copy Markdown

@derailed derailed left a comment

Choose a reason for hiding this comment

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

@bimmlerd Nice catch David!

Comment thread index/netip_test.go
)

func TestNetIPPrefix(t *testing.T) {
k1 := NetIPPrefix(netip.MustParsePrefix("10.0.0.100/8"))
Copy link
Copy Markdown

@derailed derailed Feb 13, 2026

Choose a reason for hiding this comment

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

Might be good to set this up as a table test so we can add more tests in the future and also test non equality.

@bimmlerd bimmlerd merged commit a8365e4 into main Feb 17, 2026
1 check passed
@bimmlerd bimmlerd deleted the pr/bimmlerd/canonical-cidr-keys branch February 17, 2026 13:49
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