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

manifest: LayerInfos: preallocate the slice #2499

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

kolyshkin
Copy link
Contributor

No description provided.

@rhatdan
Copy link
Member

rhatdan commented Aug 3, 2024

LGTM

Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

WDYT about make(…, 0, len(…)) + continuing to use append?

I think that achieves the primary optimization goal (not over-allocating, and not calling an allocation function in the loop) without giving up on safety WRT hypothetical future logic changes — at some performance cost, 2 conditional jumps per loop instead of one (sadly, per https://godbolt.org/z/Gbo98a74K , Go can optimize out the range check in [i], but not the capacity check in append).

@kolyshkin
Copy link
Contributor Author

WDYT about make(…, 0, len(…)) + continuing to use append?

I thought about that, but since we don't do any filtering inside the loop here I went another way.

Changed.

Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

Thanks!

@mtrmac mtrmac merged commit 7847869 into containers:main Aug 5, 2024
10 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