Closed andrew-d closed 2 weeks ago
This can be used to implement a persistent pool (i.e. one that isn't cleared like sync.Pool is) of items–e.g. database connections.
Some benchmarks vs. a naive implementation that uses a single map iteration show a pretty meaningful improvement:
$ benchstat -col /impl ./bench.txt goos: darwin goarch: arm64 pkg: tailscale.com/util/pool │ Pool │ map │ │ sec/op │ sec/op vs base │ Pool_AddDelete-10 10.56n ± 2% 15.11n ± 1% +42.97% (p=0.000 n=10) Pool_TakeRandom-10 56.75n ± 4% 1899.50n ± 20% +3246.84% (p=0.000 n=10) geomean 24.49n 169.4n +591.74%
Updates https://github.com/tailscale/corp/issues/19900
Change-Id: Ie509cb65573c4726cfc3da9a97093e61c216ca18
@bradfitz you may recognize the shape of this as being inspired by your change in database/sql
database/sql
This can be used to implement a persistent pool (i.e. one that isn't cleared like sync.Pool is) of items–e.g. database connections.
Some benchmarks vs. a naive implementation that uses a single map iteration show a pretty meaningful improvement:
Updates https://github.com/tailscale/corp/issues/19900
Change-Id: Ie509cb65573c4726cfc3da9a97093e61c216ca18