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

Typed arrays #64

Open
dvzubarev opened this issue Jan 17, 2020 · 3 comments
Open

Typed arrays #64

dvzubarev opened this issue Jan 17, 2020 · 3 comments

Comments

@dvzubarev
Copy link

dvzubarev commented Jan 17, 2020

Is it possible to support typed arrays (packed arrays). Each element of an array is of known type and is not preceded by the byte of its type. It will reduce the size of large homogeneous arrays.

It is implemented in cbor, see https://tools.ietf.org/html/draft-ietf-cbor-array-tags-00

@jsteemann
Copy link
Contributor

There is an optimization in VelocyPack for arrays in which all array members have the same size. This is the array types 0x02 to 0x05 (including). As mentioned, this only works when all array members have the same size, not the same type.

It is not looking for member types, because members with the same type can still have different sizes, e.g. two strings (same type) can have different lengths (different sizes). That said, in VelocyPack two strings with different lengths will also be two different VelocyPack types, at least if the strings are longer than 127 bytes.

The optimization will be pulled off automatically when it is detected that array members are homogenous in size.

@dvzubarev
Copy link
Author

Thank you, for your reply.
I'm aware of this optimization. It doesn't work well for my use case. I need to pass around large arrays of floats and uint64 (large values, so cant benefit from varint). In case of uint64, I cant always benefit from this optimization, since even if only one value has size 7bytes, than its not possible to use types 0x02 to 0x05. I'd like to specify fixed size for all elements of this array like fixed_array_64.

@jsteemann
Copy link
Contributor

VelocyPack currently doesn't support this.
Note that there are also compact Arrays which use the least possible storage space. Values will be added one after the other without any padding. Iterating over the values in this array should be fast (just a linear scan), but random access to a specific array element will have O(n) complexity.

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

2 participants