Skip to content

Proposal: Split into multiple Go modules#154

Draft
joamaki wants to merge 1 commit intomainfrom
pr/joamaki/mod-reorg
Draft

Proposal: Split into multiple Go modules#154
joamaki wants to merge 1 commit intomainfrom
pr/joamaki/mod-reorg

Conversation

@joamaki
Copy link
Copy Markdown
Contributor

@joamaki joamaki commented Mar 13, 2026

This is a proof-of-concept for showing how we could split the StateDB repo into multiple modules so we can have a core StateDB module with minimal dependencies. Only statedb/hive and statedb/reconciler depend on cilium/hive and cilium/stream.

TODO: This commit needs to be split into multiple commits as it does too much.

This is a proof-of-concept for showing how we could split the StateDB
repo into multiple modules so we can have a core StateDB module with
minimal dependencies. Only statedb/hive and statedb/reconciler depend
on cilium/hive and cilium/stream.

TODO: This commit needs to be split into multiple commits as it does too much.

Signed-off-by: Jussi Maki <jussi.maki@isovalent.com>
@github-actions
Copy link
Copy Markdown

$ make
go build ./...
go: downloading go.yaml.in/yaml/v3 v3.0.3
go: downloading golang.org/x/time v0.5.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 gopkg.in/yaml.v3 v3.0.1
go: downloading github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
go: downloading github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
ok  	github.com/cilium/statedb	388.979s	coverage: 79.5% of statements
ok  	github.com/cilium/statedb/index	0.005s	coverage: 33.7% of statements
ok  	github.com/cilium/statedb/internal	0.015s	coverage: 42.9% of statements
ok  	github.com/cilium/statedb/lpm	1.788s	coverage: 77.9% of statements
go test -race ./... -test.count 1
ok  	github.com/cilium/statedb	30.630s
ok  	github.com/cilium/statedb/index	1.015s
ok  	github.com/cilium/statedb/internal	1.028s
ok  	github.com/cilium/statedb/lpm	2.264s
go test ./... -bench . -benchmem -test.run xxx
goos: linux
goarch: amd64
pkg: github.com/cilium/statedb
cpu: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
BenchmarkDB_WriteTxn_1-4                      	  754753	      1557 ns/op	    642060 objects/sec	    1000 B/op	      16 allocs/op
BenchmarkDB_WriteTxn_10-4                     	 1790995	       722.7 ns/op	   1383758 objects/sec	     520 B/op	       8 allocs/op
BenchmarkDB_WriteTxn_100-4                    	 2071911	       575.5 ns/op	   1737563 objects/sec	     536 B/op	       7 allocs/op
BenchmarkDB_WriteTxn_1000-4                   	 1793887	       664.0 ns/op	   1506125 objects/sec	     522 B/op	       7 allocs/op
BenchmarkDB_WriteTxn_100_SecondaryIndex-4     	  814782	      1347 ns/op	    742267 objects/sec	    1100 B/op	      20 allocs/op
BenchmarkDB_WriteTxn_CommitOnly_100Tables-4   	 1000000	      1132 ns/op	    1112 B/op	       5 allocs/op
BenchmarkDB_WriteTxn_CommitOnly_1Table-4      	 1680832	       710.5 ns/op	     224 B/op	       5 allocs/op
BenchmarkDB_NewWriteTxn-4                     	 1897478	       631.1 ns/op	     200 B/op	       4 allocs/op
BenchmarkDB_WriteTxnCommit100-4               	  981070	      1120 ns/op	    1096 B/op	       5 allocs/op
BenchmarkDB_NewReadTxn-4                      	657887092	         1.828 ns/op	       0 B/op	       0 allocs/op
BenchmarkDB_Modify-4                          	    1688	    711638 ns/op	   1405209 objects/sec	  546068 B/op	    8094 allocs/op
BenchmarkDB_GetInsert-4                       	    1524	    798887 ns/op	   1251742 objects/sec	  530070 B/op	    8094 allocs/op
BenchmarkDB_RandomInsert-4                    	    1762	    705194 ns/op	   1418050 objects/sec	  522020 B/op	    7094 allocs/op
BenchmarkDB_RandomReplace-4                   	     386	   2972882 ns/op	    336374 objects/sec	 2073373 B/op	   29146 allocs/op
BenchmarkDB_SequentialInsert-4                	    1772	    668252 ns/op	   1496441 objects/sec	  522023 B/op	    7094 allocs/op
BenchmarkDB_SequentialInsert_Prefix-4         	     484	   2490844 ns/op	    401470 objects/sec	 3562562 B/op	   45541 allocs/op
BenchmarkDB_Changes_Baseline-4                	    1562	    771078 ns/op	   1296886 objects/sec	  582199 B/op	    9185 allocs/op
BenchmarkDB_Changes-4                         	     909	   1295926 ns/op	    771649 objects/sec	  783448 B/op	   12336 allocs/op
BenchmarkDB_RandomLookup-4                    	   22296	     53777 ns/op	  18595429 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_SequentialLookup-4                	   28270	     41958 ns/op	  23833376 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_Prefix_SecondaryIndex-4           	    8482	    136244 ns/op	   7339777 objects/sec	  124920 B/op	    1025 allocs/op
BenchmarkDB_FullIteration_All-4               	     978	   1275593 ns/op	  78394935 objects/sec	     104 B/op	       4 allocs/op
BenchmarkDB_FullIteration_Prefix-4            	     855	   1420525 ns/op	  70396510 objects/sec	     136 B/op	       5 allocs/op
BenchmarkDB_FullIteration_Get-4               	     225	   5295038 ns/op	  18885607 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_FullIteration_Get_Secondary-4     	     120	   9908832 ns/op	  10092006 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_FullIteration_ReadTxnGet-4        	     230	   5184630 ns/op	  19287779 objects/sec	       0 B/op	       0 allocs/op
BenchmarkDB_PropagationDelay-4                	  657074	      1684 ns/op	        14.00 50th_µs	        18.00 90th_µs	        40.00 99th_µs	    1120 B/op	      19 allocs/op
BenchmarkDB_WriteTxn_100_LPMIndex-4           	  528465	      2370 ns/op	    421918 objects/sec	    1825 B/op	      37 allocs/op
BenchmarkDB_WriteTxn_1_LPMIndex-4             	  125420	     16281 ns/op	     61420 objects/sec	   15682 B/op	      81 allocs/op
BenchmarkDB_LPMIndex_Get-4                    	     242	   4676924 ns/op	   2138157 objects/sec	       0 B/op	       0 allocs/op
BenchmarkWatchSet_4-4                         	 2216755	       531.3 ns/op	     296 B/op	       4 allocs/op
BenchmarkWatchSet_16-4                        	  710178	      1582 ns/op	    1096 B/op	       5 allocs/op
BenchmarkWatchSet_128-4                       	   86082	     13827 ns/op	    8904 B/op	       5 allocs/op
BenchmarkWatchSet_1024-4                      	    8820	    136217 ns/op	   73743 B/op	       5 allocs/op
PASS
ok  	github.com/cilium/statedb	44.087s
PASS
ok  	github.com/cilium/statedb/index	0.003s
goos: linux
goarch: amd64
pkg: github.com/cilium/statedb/internal
cpu: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
Benchmark_SortableMutex-4   	 8342701	       143.5 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/cilium/statedb/internal	1.201s
goos: linux
goarch: amd64
pkg: github.com/cilium/statedb/lpm
cpu: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
Benchmark_txn_insert/batchSize=1-4         	    2002	    586515 ns/op	   1704987 objects/sec	  838413 B/op	   13975 allocs/op
Benchmark_txn_insert/batchSize=10-4        	    3405	    355185 ns/op	   2815435 objects/sec	  385197 B/op	    6668 allocs/op
Benchmark_txn_insert/batchSize=100-4       	    3544	    337240 ns/op	   2965248 objects/sec	  345615 B/op	    6027 allocs/op
Benchmark_txn_delete/batchSize=1-4         	    1554	    762543 ns/op	   1311402 objects/sec	 1286470 B/op	   13976 allocs/op
Benchmark_txn_delete/batchSize=10-4        	    3171	    383043 ns/op	   2610671 objects/sec	  372417 B/op	    5769 allocs/op
Benchmark_txn_delete/batchSize=100-4       	    3546	    342058 ns/op	   2923484 objects/sec	  286752 B/op	    5038 allocs/op
Benchmark_LPM_Lookup-4                     	    8276	    144328 ns/op	   6928649 objects/sec	       0 B/op	       0 allocs/op
Benchmark_LPM_All-4                        	  137437	      8701 ns/op	 114935264 objects/sec	      32 B/op	       1 allocs/op
Benchmark_LPM_Prefix-4                     	  138574	      8656 ns/op	 115520340 objects/sec	      32 B/op	       1 allocs/op
Benchmark_LPM_LowerBound-4                 	  264475	      4536 ns/op	 110225516 objects/sec	     288 B/op	       2 allocs/op
PASS
ok  	github.com/cilium/statedb/lpm	11.993s
go run ./reconciler/benchmark -quiet
go: downloading github.com/cilium/hive v1.0.0
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/pflag v1.0.5
go: downloading github.com/spf13/cobra v1.8.0
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.15.0
go: downloading github.com/mitchellh/mapstructure v1.5.0
go: downloading golang.org/x/sys v0.15.0
go: downloading golang.org/x/tools 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 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
1000000 objects reconciled in 1.94 seconds (batch size 1000)
Throughput 515879.04 objects per second
888MB total allocated, 6015194 in-use objects, 338MB bytes in use

@joamaki joamaki mentioned this pull request Mar 16, 2026
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.

1 participant