Generate schema-specialized binary writers - #16
Merged
Conversation
jallum
force-pushed
the
perf/generated-writer
branch
from
August 31, 2026 20:07
0475f6d to
b6c0e4f
Compare
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.
Stacked on #14 (and #13).
Summary
use FlatbufferexpansionFlatbuffer.Writer: final framing, string pooling, vector materialization, scalar validation, aligned pushes, and vtable constructionto_iolist/1andto_binary/1, compact/shared vtables, shared strings, atom/binary input keys, safe schemas, recursive tables, and existing error tuplesThe shared-runtime refactor removed 291 lines (about 30%) from the writer generator; generated code now contains only the schema-specialized control flow and measurements.
TDD and verification
The first test traced
Flatbuffer.to_iolist/2andFlatbuffer.to_binary/2; it failed on the original macro delegation and passes only when both calls use generated code.mix deps.unlock --check-unusedmix compile --warnings-as-errorsmix format --check-formattedgit diff --checkBenchee
M4 Pro, Elixir 1.19.4, OTP 28.3, 100 integers and 20 child tables, after shared-runtime extraction:
The generated writer remains about 10% faster, allocates 17.4% less memory, and uses 22.9% fewer reductions. Both produce a 1,384-byte representative buffer.
flatc review and alignment ordering
flatc generates fixed
add_*calls and groups scalar emission by wire size/alignment. The Elixir generator follows the same useful property, but computes true schema alignment for structs as well. Reference objects are prepared first; inline fields are emitted by descending alignment with a deterministic field-ID tiebreaker. Each emitted location has its own generated local, so the vtable is assembled in ID order without a runtime sort. This is why alignment-friendly ordering is practical in either implementation but only wins here after the ordering work itself is moved to compile time.Adversarial review