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

Preallocate slices rather than incrementing one-by-one #21

Open
egonelbre opened this issue Nov 29, 2023 · 0 comments
Open

Preallocate slices rather than incrementing one-by-one #21

egonelbre opened this issue Nov 29, 2023 · 0 comments

Comments

@egonelbre
Copy link
Member

Currently during serialization we use:

c.RepeatedMessage(1, func(c *picobuf.Decoder) {
	m.Values = append(m.Values, Value{})
	c.Loop(m.Values[len(m.Values)-1].Decode)
})

However, this can cause significant reallocations. It might be useful to lookahead and try to either estimate or count the exact number of values that need to be unserialized and preallocate m.Values to be sufficient.

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

No branches or pull requests

1 participant