Skip to content

Conversation

@copybara-service
Copy link

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_MiniTableField now contains a byte offset to where the upb_MiniTable* or upb_MiniTableEnum* can be found.

The new design offers several benefits:

  1. The sub-table requires fewer pointer-chasing indirections to find.
  2. We no longer need the upb_MiniTable* to find the sub-MiniTable -- the upb_MiniTableField* is enough now. So APIs like upb_MiniTable_GetSubMessageTable() now require fewer parameters.
  3. This unifies fields and extensions -- both can now find a sub-table using exactly the same code, with no need to distinguish between them.

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 of upb_MiniTableField from 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.

…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_MiniTableField` now contains a byte offset to where the `upb_MiniTable*` or `upb_MiniTableEnum*` can be found.

The new design offers several benefits:

1. The sub-table requires fewer pointer-chasing indirections to find.
2. We no longer need the `upb_MiniTable*` to find the sub-MiniTable -- the `upb_MiniTableField*` is enough now.  So APIs like `upb_MiniTable_GetSubMessageTable()` now require fewer parameters.
3. This unifies fields and extensions -- both can now find a sub-table using exactly the same code, with no need to distinguish between them.

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 of `upb_MiniTableField` from 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.

PiperOrigin-RevId: 824275694
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.

2 participants