Skip to content

Conversation

@FilippoMuschera
Copy link

Changes

Replaced list with slices for busy and idle pools to enhance performance, leveraging memory locality of slices. Consequently, refactored operations for adding, removing, and searching containers.

This change reduces overhead associated with linked lists, improving efficiency in container pool management. Implemented "swap-and-pop" and in-place filtering for container removal and expiration to make these operations efficient with slices.

Benchmark

(made with go test -bench=. -benchmem ... and benchstat):
goos: linux
goarch: amd64
cpu: 12th Gen Intel(R) Core(TM) i7-12700H

Execution Time (sec/op)

Benchmark Lists (sec/op) Slices (sec/op) vs Base
PoolCycle/Size-1-20 837.1n ± 1% 781.3n ± 0% -6.67% (p=0.000 n=10)
PoolCycle/Size-1000-20 2.912µ ± 3% 1.022µ ± 0% -64.90% (p=0.000 n=10)
PoolCycle/Size-5000-20 9.910µ ± 6% 1.933µ ± 1% -80.50% (p=0.000 n=10)
Janitor/Size-5000-20 6.806µ ± 4% 3.074µ ± 1% -54.84% (p=0.000 n=10)
geomean 1.732µ 859.1n -50.40%

Memory Allocations (allocs/op)

Benchmark Lists (allocs/op) Slices (allocs/op) vs Base
PoolCycle/Size-5000-20 14.00 ± 0% 12.00 ± 0% -14.29% (p=0.000 n=10)

Replaced `list` with slices for busy and idle pools to enhance performance leveraging memory locality of slices. Consequently, refactored operations for adding, removing, and searching containers.

This change reduces overhead associated with linked lists, improving efficiency in container management. Implemented "swap-and-pop" and in-place filtering for container removal and expiration to make these operations efficient with slices.

Benchmark (made with `go test -bench=. -benchmem` and benchstat):
goos: linux
goarch: amd64
cpu: 12th Gen Intel(R) Core(TM) i7-12700H

                      │ lists           │            slices                     │
                      │     sec/op      │    sec/op     vs base                 │
PoolCycle/Size-1-20     837.1n ± 1%      781.3n ± 0%   -6.67% (p=0.000 n=10)
PoolCycle/Size-1000-20  2.912µ ± 3%      1.022µ ± 0%  -64.90% (p=0.000 n=10)
PoolCycle/Size-5000-20  9.910µ ± 6%      1.933µ ± 1%  -80.50% (p=0.000 n=10)
Janitor/Size-5000-20    6.806µ ± 4%      3.074µ ± 1%  -54.84% (p=0.000 n=10)
geomean                 1.732µ           859.1n       -50.40%

                      │ lists           │            slices                     │
                      │    allocs/op    │ allocs/op   vs base                   │
PoolCycle/Size-5000-20    14.00 ± 0%       12.00 ± 0%  -14.29% (p=0.000 n=10)
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