-
Notifications
You must be signed in to change notification settings - Fork 160
perf: optimize varbinview construction #8146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joseph-isaacs
wants to merge
6
commits into
develop
Choose a base branch
from
claude/avx512-decode-benchmark-wRhkZ
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+352
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
50b0e93
Speed up VarBinView build_views single-buffer canonicalization
joseph-isaacs 76e17aa
Optimize build_views single-buffer hot loop write path
claude 84159af
test: cover build_views single-buffer fast path
claude a95257e
test: verify build_views fast path large u32 offsets
claude 10f6f01
test: slow gated FSST canonicalize offsets-overflow regression
claude fc6b839
test: replace FSST overflow test with direct build_views rollover test
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,6 +170,27 @@ impl BinaryView { | |
| Self { le_bytes: [0; 16] } | ||
| } | ||
|
|
||
| /// Create a reference view directly from its components, without inspecting the value. | ||
| /// | ||
| /// `size` must be greater than [`MAX_INLINED_SIZE`], and `prefix` must hold the first four | ||
| /// bytes of the value. This is the fast path for bulk view construction where the caller has | ||
| /// already established that the value is too long to inline; it assembles the 16-byte view as a | ||
| /// single `u128` so the compiler can emit one wide store per view. | ||
| /// | ||
| /// [`MAX_INLINED_SIZE`]: Self::MAX_INLINED_SIZE | ||
| #[inline] | ||
| pub fn new_ref(size: u32, prefix: [u8; 4], buffer_index: u32, offset: u32) -> Self { | ||
| debug_assert!(size as usize > Self::MAX_INLINED_SIZE); | ||
| // Matches the little-endian field order of `Ref` (size, prefix, buffer_index, offset), | ||
| // consistent with `le_bytes` and the `From<u128>`/`as_u128` representation. | ||
| Self::from( | ||
| u128::from(size) | ||
| | (u128::from(u32::from_le_bytes(prefix)) << 32) | ||
| | (u128::from(buffer_index) << 64) | ||
| | (u128::from(offset) << 96), | ||
| ) | ||
| } | ||
|
|
||
| /// Create a new inlined binary view | ||
| /// | ||
| /// # Panics | ||
|
|
@@ -278,3 +299,31 @@ impl fmt::Debug for BinaryView { | |
| s.finish() | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| #[expect( | ||
| clippy::cast_possible_truncation, | ||
| reason = "test values are bounded well within the target types" | ||
| )] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn new_ref_matches_make_view() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any more test cases you can come up with? Is the change sufficiently covered? |
||
| // `new_ref` assembles the reference view as a `u128`; it must be byte-identical to the | ||
| // value-inspecting `make_view` for any value longer than the inline limit. | ||
| for &len in &[13usize, 20, 255, 4096] { | ||
| let value: Vec<u8> = (0..len).map(|i| (i % 251) as u8).collect(); | ||
| let prefix = [value[0], value[1], value[2], value[3]]; | ||
| let made = BinaryView::make_view(&value, 7, 42); | ||
| let built = BinaryView::new_ref(len as u32, prefix, 7, 42); | ||
| assert_eq!(made.as_u128(), built.as_u128(), "mismatch at len {len}"); | ||
| assert!(!built.is_inlined()); | ||
| let r = built.as_view(); | ||
| assert_eq!(r.size, len as u32); | ||
| assert_eq!(r.prefix, prefix); | ||
| assert_eq!(r.buffer_index, 7); | ||
| assert_eq!(r.offset, 42); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
offset.as_()can implicitly truncate?