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

fix: replace static buffer allocation on growth #7

Merged
merged 1 commit into from
Jan 31, 2025

Conversation

smira
Copy link
Member

@smira smira commented Jan 30, 2025

Use slices.Grow and follow whatever algorithm it uses internally to pick the next size of the buffer.

So the growth might not be exactly what we asked for, but it should be optimal from Go runtime point of view.

Use `slices.Grow` and follow whatever algorithm it uses internally to
pick the next size of the buffer.

So the growth might not be exactly what we asked for, but it should be
optimal from Go runtime point of view.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
@smira smira force-pushed the fix/use-slices-grow branch from 13559d6 to 015a398 Compare January 30, 2025 13:22
Copy link
Member

@DmitriyMV DmitriyMV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆒

@smira
Copy link
Member Author

smira commented Jan 31, 2025

No real changes with the benchmark:

name                     old time/op    new time/op    delta
Write/defaults-32           152ns ± 3%     153ns ± 5%    ~     (p=0.841 n=5+5)
Write/growing_buffer-32     154ns ± 5%     152ns ± 3%    ~     (p=0.690 n=5+5)
Write/compression-32        425ns ± 3%     423ns ± 2%    ~     (p=1.000 n=5+5)
Read/defaults-32           11.9µs ± 3%    11.9µs ± 2%    ~     (p=0.841 n=5+5)
Read/growing_buffer-32     11.7µs ± 3%    11.9µs ± 2%    ~     (p=0.310 n=5+5)
Read/compression-32         338µs ± 1%     342µs ± 2%    ~     (p=0.151 n=5+5)

name                     old alloc/op   new alloc/op   delta
Write/defaults-32           0.00B          0.00B         ~     (all equal)
Write/growing_buffer-32     0.00B          0.00B         ~     (all equal)
Write/compression-32       1.02kB ± 0%    1.02kB ± 0%    ~     (all equal)
Read/defaults-32             128B ± 0%      128B ± 0%    ~     (all equal)
Read/growing_buffer-32       128B ± 0%      128B ± 0%    ~     (all equal)
Read/compression-32         139kB ± 0%     139kB ± 0%  -0.00%  (p=0.016 n=5+4)

name                     old allocs/op  new allocs/op  delta
Write/defaults-32            0.00           0.00         ~     (all equal)
Write/growing_buffer-32      0.00           0.00         ~     (all equal)
Write/compression-32         0.00           0.00         ~     (all equal)
Read/defaults-32             1.00 ± 0%      1.00 ± 0%    ~     (all equal)
Read/growing_buffer-32       1.00 ± 0%      1.00 ± 0%    ~     (all equal)
Read/compression-32          2.00 ± 0%      2.00 ± 0%    ~     (all equal)

@smira
Copy link
Member Author

smira commented Jan 31, 2025

/m

@talos-bot talos-bot merged commit 015a398 into siderolabs:main Jan 31, 2025
14 checks passed
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