Batch inline vector writes - #11
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
The writer treats inline vectors (numbers, enums, and structs) like vectors of tables or strings. It wraps every element, saves the wrappers in reverse order, and rebuilds the writer state once per element. Inline values do not need that offset bookkeeping because their bytes are already final.
What changed
How it works (ELI5)
The old code boxed every item, stacked the boxes backward, then unpacked them one by one. Inline values can be put in one ordered tray and handed to the writer together. Tables and strings still use the careful one-by-one offset path because they need directions to where their data lives.
Benchee results
Apple M4 Pro, Elixir 1.19.4, Erlang/OTP 28.
to_binary, 100to_binary, 1,000to_iolist, 100to_iolist, 1,000I also tested flattening the batched payload to a binary inside the writer. It was effectively tied for
to_binary, used slightly more memory, and forcedto_iolistto copy, so this PR keeps the payload as iodata.Run with:
Verification
mix format --check-formattedMIX_ENV=test mix test --include flatc(113 tests, 0 failures)