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

ArrayView instead of Array for repeated scalar fields #30

Open
jamesdbrock opened this issue Jun 24, 2021 · 2 comments
Open

ArrayView instead of Array for repeated scalar fields #30

jamesdbrock opened this issue Jun 24, 2021 · 2 comments

Comments

@jamesdbrock
Copy link
Member

I wonder if it would be a worthwhile performance improvement to represent repeated scalar fields with ArrayView instead of Array.

For example a repeated double message field would be type Float64Array instead of Array Number.

We already have special cases for packed repeated scalar fields so maybe this would be easy.

@jamesdbrock
Copy link
Member Author

When deserializing a packed repeated scalar field we don't know how many repeated elements are in the field in advance, so we wouldn't be able to preallocate exactly the right size ArrayView. We would have to make a growable ArrayView buffer like https://pursuit.purescript.org/packages/purescript-dynamic-buffers

@jamesdbrock
Copy link
Member Author

jamesdbrock commented Jul 28, 2021

When deserializing a packed repeated scalar field we don't know how many repeated elements are in the field in advance,

Wait that's not quite true, we know the length of the array, and if the element type is fixed-width (double, float, fixed32, fixed64, sfixed32, sfixed64) then we can just divide by the byte width of the array element type to get the number of repeated elements.

That still leaves the problem of variable-width-type packed repeated fields though.

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