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

Reduce allocations for ID type #185

Merged
merged 2 commits into from Mar 19, 2022

Conversation

azdagron
Copy link
Member

Going from ID to string causes an allocation. This change avoids this allocation by holding onto the original string and instead tracking where the path begins inside of that string. Note that this does not increase memory usage since the backing array of the original string was already being held by the existing code. This change also reduces the struct size of the ID type.

Going from ID to string causes an allocation. This change avoids this
allocation by holding onto the original string and instead tracking
where the path begins inside of that string. Note that this does not
increase memory usage since the backing array of the original string was
already being held by the existing code. This change also reduces the
struct size of the ID type.

Signed-off-by: Andrew Harding <aharding@vmware.com>
Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

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

Thanks @azdagron for this improvement! LGTM.

td TrustDomain
path string
id string
pathidx int
Copy link
Member

Choose a reason for hiding this comment

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

nit: It may be useful to add a comment about the motivation of the need for this, indicating that we need to track where the path begins.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, fixed!

Signed-off-by: Andrew Harding <aharding@vmware.com>
Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

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

🚀

@azdagron azdagron merged commit 3d166bc into spiffe:main Mar 19, 2022
@azdagron azdagron deleted the avoid-allocation-on-id-to-string branch March 19, 2022 22:29
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.

None yet

2 participants