prebid-server icon indicating copy to clipboard operation
prebid-server copied to clipboard

Optimize BuildBidderNameHashSet

Open linux019 opened this issue 1 year ago • 3 comments

Pprof identified big amount of allocations caused by each call to CoreBidderNames on each auction request By storing result of CoreBidderNames into a single variable number of allocations reduced 4x

go test -benchmem -v -bench=Bench ./openrtb_ext/. |prettybench

Before:

BenchmarkBuildBidderNameHashSet
PASS
benchmark                             iter      time/iter   bytes alloc         allocs
---------                             ----      ---------   -----------         ------
BenchmarkBuildBidderNameHashSet-18   50244    22.66 μs/op    21333 B/op   12 allocs/op
ok      github.com/prebid/prebid-server/v2/openrtb_ext  1.415s

After:

BenchmarkBuildBidderNameHashSet
PASS
benchmark                              iter       time/iter   bytes alloc        allocs
---------                              ----       ---------   -----------        ------
BenchmarkBuildBidderNameHashSet-18   152774   7813.00 ns/op    10312 B/op   3 allocs/op
ok      github.com/prebid/prebid-server/v2/openrtb_ext  1.309s

linux019 avatar Oct 30 '24 15:10 linux019

The coreBidderNames slice can be altered by calls to SetAliasBidderName during startup. Could you please confirm all calls to the optimized BuildBidderNameHashSet occur after any potenital call to SetAliasBidderName ?

.. or to be safe, is it possible for SetAliasBidderName to reset the state of the optimized builder?

SyntaxNode avatar Oct 30 '24 22:10 SyntaxNode

main() calls LoadBidderInfoFromDisk https://github.com/prebid/prebid-server/blob/5b11f59bdde56d7b22678efb4b3dfb2da9c62a7f/main.go#L35 Next is creates a HTTP server where a call to auction endpoint triggers BuildBidderNameHashSet Yes if new changes will call SetAliasBidderName this cached set needs to be rebuilt.

linux019 avatar Oct 31 '24 13:10 linux019

Tagging as blocked. Another PR is in flight that will address the raised concerns.

bsardo avatar Jan 23 '25 15:01 bsardo