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

Benchmark batch lookups vs. MapIterator, remove MapIterator.prevKey #1077

Merged
merged 2 commits into from
Jun 28, 2023

Commits on Jun 27, 2023

  1. map: add BenchmarkIterate for comparing Map.Iterate against BatchLookup

    Benchmark results at time of writing:
    
    BenchmarkIterate/MapIterator-16         	             866	   1457681 ns/op	   64126 B/op	    4004 allocs/op
    BenchmarkIterate/MapIteratorDelete-16   	             408	   2526392 ns/op	   80210 B/op	    6004 allocs/op
    BenchmarkIterate/BatchLookup-16         	           59647	     19974 ns/op	   32851 B/op	       8 allocs/op
    BenchmarkIterate/BatchLookupAndDelete-16         	   10000	    154757 ns/op	   32872 B/op	       8 allocs/op
    BenchmarkIterate/BatchDelete-16                  	    8306	    136770 ns/op	   16416 B/op	       3 allocs/op
    
    Signed-off-by: Timo Beckers <timo@isovalent.com>
    ti-mo committed Jun 27, 2023
    Configuration menu
    Copy the full SHA
    2c0997b View commit details
    Browse the repository at this point in the history
  2. map: MapIterator: remove double bookkeeping with prevKey

    Change the terminology used in the iterator to revolve around the 'current'
    and the 'next' key instead of considering the 'previous' key.
    
    I found the behaviour after passing a nil `mi.prevKey` to NextKeyBytes a little
    subtle. If the interface value passed to NextKeyBytes contains a nil 'any', it
    will successfully detect nilness and not try to marshal the key. If the caller
    passes a []byte(nil), the nil check will fail and nextKey() will try to marshal
    the key.
    
    Perform a nil check on mi.curKey instead and explicitly pass an untyped nil to
    NextKeyBytes if the Map's first key needs to be looked up. This means prevKey
    can be eliminated.
    
    Signed-off-by: Timo Beckers <timo@isovalent.com>
    ti-mo committed Jun 27, 2023
    Configuration menu
    Copy the full SHA
    452a683 View commit details
    Browse the repository at this point in the history