Skip to content

typed version of WhereCache, with 3X speed up and 99% memory reduce#418

Open
halfcrazy wants to merge 1 commit into
ovn-kubernetes:mainfrom
halfcrazy:wherecachetyped
Open

typed version of WhereCache, with 3X speed up and 99% memory reduce#418
halfcrazy wants to merge 1 commit into
ovn-kubernetes:mainfrom
halfcrazy:wherecachetyped

Conversation

@halfcrazy

@halfcrazy halfcrazy commented Jul 16, 2025

Copy link
Copy Markdown
Contributor

typed version of WhereCache, fix #366 #365

Usage

    lsList := []LogicalSwitch{}
    client.WhereCacheTyped(ovs, func(ls *MyLogicalSwitch) bool {
        return strings.HasPrefix(ls.Name, "ext_")
    }).List(&lsList)

bench report

goos: linux
goarch: amd64
pkg: github.com/ovn-kubernetes/libovsdb/client
cpu: Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz
BenchmarkWhereCacheTypedList/predicate_returns_none-4         	     289	   4079307 ns/op	  906546 B/op	   20040 allocs/op
BenchmarkWhereCacheTypedList/predicate_returns_all-4          	       7	 148840727 ns/op	17648513 B/op	  210132 allocs/op
BenchmarkWhereCacheTypedList/predicate_on_an_arbitrary_condition-4         	      51	  21615530 ns/op	 2783326 B/op	   41172 allocs/op
BenchmarkWhereCacheTypedList/predicate_matches_name-4                      	     255	   4666906 ns/op	  908429 B/op	   20061 allocs/op
BenchmarkWhereCacheTypedList/typed:_predicate_returns_none-4               	    1186	    950534 ns/op	  656529 B/op	      40 allocs/op
BenchmarkWhereCacheTypedList/typed:_predicate_returns_all-4                	       7	 150332743 ns/op	17408165 B/op	  190130 allocs/op
BenchmarkWhereCacheTypedList/typed:_predicate_on_an_arbitrary_condition-4  	      67	  17703972 ns/op	 2533008 B/op	   21172 allocs/op
BenchmarkWhereCacheTypedList/typed:_predicate_matches_name-4               	     937	   1147315 ns/op	  658396 B/op	      61 allocs/op
PASS
ok  	github.com/ovn-kubernetes/libovsdb/client	22.232s
Benchmark Group Implementation Iterations Time per Operation Memory per Operation Allocations per Operation
Predicate Returns None Regular 289 4079307 ns/op 906546 B/op 20040 allocs/op
  Typed 1186 (+310%) 950534 ns/op (-76.7%) 656529 B/op (-27.6%) 40 allocs/op (-99.8%)
Predicate Returns All Regular 7 148840727 ns/op 17648513 B/op 210132 allocs/op
  Typed 7 (+0%) 150332743 ns/op (+1.0%) 17408165 B/op (-1.4%) 190130 allocs/op (-9.5%)
Arbitrary Condition Regular 51 21615530 ns/op 2783326 B/op 41172 allocs/op
  Typed 67 (+31.4%) 17703972 ns/op (-18.1%) 2533008 B/op (-9.0%) 21172 allocs/op (-48.6%)
Matches Name Regular 255 4666906 ns/op 908429 B/op 20061 allocs/op
  Typed 937 (+267.5%) 1147315 ns/op (-75.4%) 658396 B/op (-27.5%) 61 allocs/op (-99.7%)

@halfcrazy halfcrazy changed the title typed version of WhereCache, with 4X speed up and 99% memory reduce typed version of WhereCache, with 3X speed up and 99% memory reduce Jul 20, 2025
Signed-off-by: Yan Zhu <hackzhuyan@gmail.com>
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