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

perf: preallocate slice with known length to optimize Mem Allocs #3768

Closed
wants to merge 1 commit into from

Conversation

anazcodes
Copy link
Contributor

No description provided.

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🔧 golang labels Dec 31, 2024
@kyleconroy
Copy link
Collaborator

I'm skeptical that this one change is causing much of a performance problem, so going to close this for now.

@kyleconroy kyleconroy closed this Jan 9, 2025
@anazcodes
Copy link
Contributor Author

anazcodes commented Jan 10, 2025

I'm skeptical that this one change is causing much of a performance problem, so going to close this for now.

It may not provide much observable effect in a few iterations, but it significantly improves performance with frequent iterations, and pre-allocating memory for the slice reduces the processes that occur internally when calling append in a loop.

This PR was intended to write the better version of the noticed line of code.

@anazcodes anazcodes deleted the anaz/alloc-optimization branch January 14, 2025 07:26
@anazcodes anazcodes restored the anaz/alloc-optimization branch January 14, 2025 07:27
@anazcodes anazcodes deleted the anaz/alloc-optimization branch January 15, 2025 09:08
@anazcodes anazcodes restored the anaz/alloc-optimization branch January 15, 2025 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XS This PR changes 0-9 lines, ignoring generated files. 🔧 golang
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants