Skip to content

Add benchmark and optimize performance of common functions#8

Merged
AkihiroSuda merged 3 commits intocontainerd:mainfrom
dmcgowan:perf-optimization
Nov 27, 2025
Merged

Add benchmark and optimize performance of common functions#8
AkihiroSuda merged 3 commits intocontainerd:mainfrom
dmcgowan:perf-optimization

Conversation

@dmcgowan
Copy link
Copy Markdown
Member

Currently we use URI() for comparison checks which causes unnecessary allocations. Directly comparing the values or pointers greatly improves performance.

Another additional speedup is achieved by doing the disabled set check after the other checks, which are faster and often false when scanning over the whole registry.

Locally, I see a 20x speed improvement on graph and 40x on uniqueness check and allocations drop to zero or near zero. Its harder to measure due to init across 50+ plugins in containerd, but with this change I see a 25% speedup in containerd startup on the same machine (20ms to 15ms avg)

benchmark              old ns/op     new ns/op     delta
BenchmarkGraph-14      645422        28617         -95.57%
BenchmarkUnique-14     895           23.8          -97.34%

benchmark              old allocs     new allocs     delta
BenchmarkGraph-14      15020          8              -99.95%
BenchmarkUnique-14     14             0              -100.00%

benchmark              old bytes     new bytes     delta
BenchmarkGraph-14      725768        5192          -99.28%
BenchmarkUnique-14     672           0             -100.00%

Signed-off-by: Derek McGowan <derek@mcg.dev>
Replace the URI comparison with pointer comparison, this removes all
allocations during the children comparison. The register already
guarantees that multiple URIs are not registered.

Change the ordering of the comparison first check the most likely
filter and do the set check last.

Signed-off-by: Derek McGowan <derek@mcg.dev>
The URI generation is slow and unnecessary just to compare two fields.
This reduces extra allocations down to 0 during registration.

Signed-off-by: Derek McGowan <derek@mcg.dev>
@AkihiroSuda AkihiroSuda merged commit 4f0df13 into containerd:main Nov 27, 2025
4 checks passed
@dmcgowan dmcgowan deleted the perf-optimization branch November 27, 2025 14:13
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.

3 participants