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: specify the size of slice when the slice is created #6

Merged
merged 1 commit into from
Jan 26, 2021
Merged

perf: specify the size of slice when the slice is created #6

merged 1 commit into from
Jan 26, 2021

Conversation

suzuki-shunsuke
Copy link
Contributor

@suzuki-shunsuke suzuki-shunsuke commented Jan 26, 2021

If the size of slice is known in advance, we should specify the size when we create the slice.
Otherwise the performance becomes worse due to allocation.

@suzuki-shunsuke suzuki-shunsuke marked this pull request as ready for review January 26, 2021 14:36
Copy link
Owner

@chaspy chaspy left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

What I learned:

  • slice internally refers to an array
  • If the size is fixed, it is better to allocate it from the beginning than to expand it by append.

@chaspy chaspy merged commit 647e66e into chaspy:main Jan 26, 2021
@suzuki-shunsuke suzuki-shunsuke deleted the perf/fix-slice-size branch January 26, 2021 22:39
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.

2 participants