Pack the field array and the subs array into one block of contiguous memory. #24308
+344
−365
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pack the field array and the subs array into one block of contiguous memory.
Instead of giving every MiniTable two parallel arrays (fields and subs), we now have one block of memory that contains both lists.
For sub-message or enum fields, the
upb_MiniTableFieldnow contains a byte offset to where theupb_MiniTable*orupb_MiniTableEnum*can be found.The new design offers several benefits:
upb_MiniTable*to find the sub-MiniTable -- theupb_MiniTableField*is enough now. So APIs likeupb_MiniTable_GetSubMessageTable()now require fewer parameters.We still benefit from having two lists. If we tried to put the sub-table pointer directly into
upb_MiniTableField, it would double the size ofupb_MiniTableFieldfrom 12 to 24 bytes, due to alignment. Using the current design, sub-message fields only take 20 bytes, while others take 12, so this design is an improvement even if 100% of fields are sub-message fields.