-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Bypass the varint path when encoding InitMask #110343
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
Merged
Merged
Changes from all commits
Commits
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
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 |
---|---|---|
|
@@ -5,7 +5,9 @@ use std::hash; | |
use std::iter; | ||
use std::ops::Range; | ||
|
||
use rustc_serialize::{Decodable, Encodable}; | ||
use rustc_target::abi::Size; | ||
use rustc_type_ir::{TyDecoder, TyEncoder}; | ||
|
||
use super::AllocRange; | ||
|
||
|
@@ -182,11 +184,39 @@ impl InitMask { | |
/// The actual materialized blocks of the bitmask, when we can't keep the `InitMask` lazy. | ||
// Note: for performance reasons when interning, some of the fields can be partially | ||
// hashed. (see the `Hash` impl below for more details), so the impl is not derived. | ||
#[derive(Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable, HashStable)] | ||
#[derive(Clone, Debug, Eq, PartialEq, HashStable)] | ||
struct InitMaskMaterialized { | ||
blocks: Vec<Block>, | ||
} | ||
|
||
// `Block` is a `u64`, but it is a bitmask not a numeric value. If we were to just derive | ||
// Encodable and Decodable we would apply varint encoding to the bitmasks, which is slower | ||
// and also produces more output when the high bits of each `u64` are occupied. | ||
// Note: There is probably a remaining optimization for masks that do not use an entire | ||
// `Block`. | ||
impl<E: TyEncoder> Encodable<E> for InitMaskMaterialized { | ||
fn encode(&self, encoder: &mut E) { | ||
encoder.emit_usize(self.blocks.len()); | ||
for block in &self.blocks { | ||
encoder.emit_raw_bytes(&block.to_le_bytes()); | ||
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. Just wanted to note: I'm not familiar with the endianness rules for encoding/decoding, I had idly wondered before if we should prefer native endianness in incr data, but I think we use LE everywhere so 👍 . |
||
} | ||
} | ||
} | ||
|
||
// This implementation is deliberately not derived, see the matching `Encodable` impl. | ||
impl<D: TyDecoder> Decodable<D> for InitMaskMaterialized { | ||
fn decode(decoder: &mut D) -> Self { | ||
let num_blocks = decoder.read_usize(); | ||
let mut blocks = Vec::with_capacity(num_blocks); | ||
for _ in 0..num_blocks { | ||
let bytes = decoder.read_raw_bytes(8); | ||
let block = u64::from_le_bytes(bytes.try_into().unwrap()); | ||
blocks.push(block); | ||
} | ||
InitMaskMaterialized { blocks } | ||
} | ||
} | ||
|
||
// Const allocations are only hashed for interning. However, they can be large, making the hashing | ||
// expensive especially since it uses `FxHash`: it's better suited to short keys, not potentially | ||
// big buffers like the allocation's init mask. We can partially hash some fields when they're | ||
|
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.