Rollup merge of #139636 - Zoxc:graph-edges-len-u32, r=compiler-errors
Encode dep node edge count as u32 instead of usize This encodes the dep node edge count as u32 instead of usize. It doesn't need to be usize as the count is limited the the unique number of dep nodes which we use a 32-bit index for. It probably saves some branches for encoding / decoding, but it isn't too hot as the count gets packed in with other fields when it's low. <table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th><td align="right">Physical Memory</td><td align="right">Physical Memory</td><td align="right">%</th><td align="right">Committed Memory</td><td align="right">Committed Memory</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check:unchanged</td><td align="right">0.3343s</td><td align="right">0.3343s</td><td align="right"> -0.00%</td><td align="right">97.02 MiB</td><td align="right">96.89 MiB</td><td align="right"> -0.13%</td><td align="right">167.93 MiB</td><td align="right">167.80 MiB</td><td align="right"> -0.08%</td></tr><tr><td>🟣 <b>hyper</b>:check:unchanged</td><td align="right">0.1353s</td><td align="right">0.1350s</td><td align="right"> -0.19%</td><td align="right">61.91 MiB</td><td align="right">61.83 MiB</td><td align="right"> -0.13%</td><td align="right">124.64 MiB</td><td align="right">124.64 MiB</td><td align="right"> 0.00%</td></tr><tr><td>🟣 <b>regex</b>:check:unchanged</td><td align="right">0.2479s</td><td align="right">0.2481s</td><td align="right"> 0.10%</td><td align="right">78.34 MiB</td><td align="right">78.35 MiB</td><td align="right"> 0.02%</td><td align="right">145.20 MiB</td><td align="right">145.31 MiB</td><td align="right"> 0.08%</td></tr><tr><td>🟣 <b>syn</b>:check:unchanged</td><td align="right">0.5347s</td><td align="right">0.5333s</td><td align="right"> -0.26%</td><td align="right">118.63 MiB</td><td align="right">118.66 MiB</td><td align="right"> 0.02%</td><td align="right">193.05 MiB</td><td align="right">193.11 MiB</td><td align="right"> 0.03%</td></tr><tr><td>Total</td><td align="right">1.2521s</td><td align="right">1.2507s</td><td align="right"> -0.11%</td><td align="right">355.90 MiB</td><td align="right">355.74 MiB</td><td align="right"> -0.05%</td><td align="right">630.83 MiB</td><td align="right">630.87 MiB</td><td align="right"> 0.01%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9991s</td><td align="right"> -0.09%</td><td align="right">1 byte</td><td align="right">1.00 bytes</td><td align="right"> -0.06%</td><td align="right">1 byte</td><td align="right">1.00 bytes</td><td align="right"> 0.01%</td></tr></table>
This commit is contained in:
commit
5c494aa5c8
1 changed files with 10 additions and 8 deletions
|
@ -226,12 +226,12 @@ impl SerializedDepGraph {
|
|||
|
||||
// If the length of this node's edge list is small, the length is stored in the header.
|
||||
// If it is not, we fall back to another decoder call.
|
||||
let num_edges = node_header.len().unwrap_or_else(|| d.read_usize());
|
||||
let num_edges = node_header.len().unwrap_or_else(|| d.read_u32());
|
||||
|
||||
// The edges index list uses the same varint strategy as rmeta tables; we select the
|
||||
// number of byte elements per-array not per-element. This lets us read the whole edge
|
||||
// list for a node with one decoder call and also use the on-disk format in memory.
|
||||
let edges_len_bytes = node_header.bytes_per_index() * num_edges;
|
||||
let edges_len_bytes = node_header.bytes_per_index() * (num_edges as usize);
|
||||
// The in-memory structure for the edges list stores the byte width of the edges on
|
||||
// this node with the offset into the global edge data array.
|
||||
let edges_header = node_header.edges_header(&edge_list_data);
|
||||
|
@ -296,7 +296,7 @@ struct SerializedNodeHeader<D> {
|
|||
// The fields of a `SerializedNodeHeader`, this struct is an implementation detail and exists only
|
||||
// to make the implementation of `SerializedNodeHeader` simpler.
|
||||
struct Unpacked {
|
||||
len: Option<usize>,
|
||||
len: Option<u32>,
|
||||
bytes_per_index: usize,
|
||||
kind: DepKind,
|
||||
hash: PackedFingerprint,
|
||||
|
@ -352,7 +352,7 @@ impl<D: Deps> SerializedNodeHeader<D> {
|
|||
assert_eq!(fingerprint, res.fingerprint());
|
||||
assert_eq!(node, res.node());
|
||||
if let Some(len) = res.len() {
|
||||
assert_eq!(edge_count, len);
|
||||
assert_eq!(edge_count, len as usize);
|
||||
}
|
||||
}
|
||||
Self { bytes, _marker: PhantomData }
|
||||
|
@ -366,7 +366,7 @@ impl<D: Deps> SerializedNodeHeader<D> {
|
|||
|
||||
let kind = head & mask(Self::KIND_BITS) as u16;
|
||||
let bytes_per_index = (head >> Self::KIND_BITS) & mask(Self::WIDTH_BITS) as u16;
|
||||
let len = (head as usize) >> (Self::WIDTH_BITS + Self::KIND_BITS);
|
||||
let len = (head as u32) >> (Self::WIDTH_BITS + Self::KIND_BITS);
|
||||
|
||||
Unpacked {
|
||||
len: len.checked_sub(1),
|
||||
|
@ -378,7 +378,7 @@ impl<D: Deps> SerializedNodeHeader<D> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn len(&self) -> Option<usize> {
|
||||
fn len(&self) -> Option<u32> {
|
||||
self.unpack().len
|
||||
}
|
||||
|
||||
|
@ -421,7 +421,8 @@ impl NodeInfo {
|
|||
e.write_array(header.bytes);
|
||||
|
||||
if header.len().is_none() {
|
||||
e.emit_usize(edges.len());
|
||||
// The edges are all unique and the number of unique indices is less than u32::MAX.
|
||||
e.emit_u32(edges.len().try_into().unwrap());
|
||||
}
|
||||
|
||||
let bytes_per_index = header.bytes_per_index();
|
||||
|
@ -456,7 +457,8 @@ impl NodeInfo {
|
|||
e.write_array(header.bytes);
|
||||
|
||||
if header.len().is_none() {
|
||||
e.emit_usize(edge_count);
|
||||
// The edges are all unique and the number of unique indices is less than u32::MAX.
|
||||
e.emit_u32(edge_count.try_into().unwrap());
|
||||
}
|
||||
|
||||
let bytes_per_index = header.bytes_per_index();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue