Skip to content

Canonical key length - #40

Open
nebkat wants to merge 3 commits into
NeuroJSON:masterfrom
nebkat:spec/canonical-key-length
Open

nebkat wants to merge 3 commits into
NeuroJSON:masterfrom
nebkat:spec/canonical-key-length

Conversation

@nebkat

@nebkat nebkat commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Low-level encoders (C++) can achieve greater performance by pre-encoding object keys together with their corresponding length (e.g. [[] [U] [3] [foo] [T] []] => [U] [3] [foo]) and directly writing this to the output stream instead of generating it on the fly. This method is currently used in glaze to speed up encoding in BEVE.

The decoding side is currently unable to benefit from this because the standard allows key lengths to be encoded using any integer marker, signed or unsigned, right sized or oversized - meaning the decoder must be ready for whatever comes its way even if it is not the most optimal coding.

This proposal introduces restrictions on the type of markers which may be used for a length, namely only the 4 unsigned integer types (uint8, uint16, uint32 and uint64), applicable across strings, arrays, keys, huge numbers.

Object keys are further restricted in that they must use the smallest length marker type that can represent the length of the key. This makes sense because keys are effectively constant values. Keys do not benefit from any in-place modification abilities because they are always directly followed by a value, which must move together with the end of the key - whether it be due to the key length itself changing or the key length marker changing between different sizes.

Arrays/strings/others are not subjected to this restriction as they do benefit from in-place modification, and are not usually storing constants.

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.

1 participant