Speed up reads from binary buffers - #10
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
Reading one number currently asks the generic iodata helper to copy out a tiny slice. Most callers pass a binary, so that general-purpose work is paid for every scalar, offset, and vtable entry.
What changed
binary_part/3.How it works (ELI5)
The old path took every tiny value to a helper that can unpack any nested list shape. The fast path first notices that the buffer is already one flat binary and picks the bytes straight out. Nested iodata still goes to the original helper.
Benchee results
Apple M4 Pro, Elixir 1.19.4, Erlang/OTP 28.
getThe isolated u32 cursor benchmark measured direct binary matching at 29.38 M ops/s versus 13.61 M ops/s for the current iodata slice (2.16x), with 40 B versus 64 B and 1 versus 11 reductions.
Run with:
Verification
mix format --check-formattedMIX_ENV=test mix test(111 tests, 0 failures)