Skip to content

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

Description

@egonelbre

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions