Skip to content

Commit

Permalink
Split stable versus nightly for memory usage tests
Browse files Browse the repository at this point in the history
**Description**
Add a check for the `nightly` feature flag to change the expected sizes
in different tests.

This seems like a short-term solution because the nightly changes will
eventually get promoted to stable and then this change will need to be
removed.

I found a possibly related [rust-lang issue #104807][rust-issue-104807]
, maybe the fix for this will change the nightly enum sizes back to
their previous values

**Motivation**
CI was breaking on the nightly and miri tests

**Testing Done**
 - `cargo +nightly test --features nightly` passes
 - `cargo +nightly miri test` passes
 - `cargo +nightly test` fails

[rust-issue-104807]: rust-lang/rust#104807
  • Loading branch information
declanvk committed Nov 30, 2022
1 parent 195dcdf commit 416e48c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/nodes/representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl<V> fmt::Debug for ConcreteNodePtr<V> {
pub struct NodePtr<N: Node>(NonNull<N>);

impl<N: Node> NodePtr<N> {
/// Create a safe pointer to a Node_.
/// Create a safe pointer to a [`Node`].
///
/// # Safety
///
Expand Down
28 changes: 23 additions & 5 deletions src/nodes/representation/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,39 @@ fn opaque_node_ptr_is_correct() {
#[test]
#[cfg(target_pointer_width = "64")]
fn node_sizes() {
assert_eq!(mem::size_of::<Header>(), 32);
let expected_header_size = if cfg!(any(miri, feature = "nightly")) {
40
} else {
32
};

assert_eq!(mem::size_of::<Header>(), expected_header_size);
// key map: 4 * (1 byte) = 4 bytes
// child map: 4 * (8 bytes (on 64-bit platform)) = 32
//
// 4 bytes of padding are inserted after the `keys` field to align the field to
// an 8 byte boundary.
assert_eq!(mem::size_of::<InnerNode4<usize>>(), 72);
assert_eq!(
mem::size_of::<InnerNode4<usize>>(),
expected_header_size + 40
);
// key map: 16 * (1 byte) = 16 bytes
// child map: 16 * (8 bytes (on 64-bit platform)) = 128
assert_eq!(mem::size_of::<InnerNode16<usize>>(), 176);
assert_eq!(
mem::size_of::<InnerNode16<usize>>(),
expected_header_size + 144
);
// key map: 256 * (1 byte) = 256 bytes
// child map: 48 * (8 bytes (on 64-bit platform)) = 384
assert_eq!(mem::size_of::<InnerNode48<usize>>(), 672);
assert_eq!(
mem::size_of::<InnerNode48<usize>>(),
expected_header_size + 640
);
// child & key map: 256 * (8 bytes (on 64-bit platform)) = 2048
assert_eq!(mem::size_of::<InnerNode256<usize>>(), 2080);
assert_eq!(
mem::size_of::<InnerNode256<usize>>(),
expected_header_size + 2048
);

// Assert that pointer is expected size and has non-null optimization
assert_eq!(mem::size_of::<Option<OpaqueNodePtr<()>>>(), 8);
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/visitor/pretty_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use std::{
io::{self, Write},
};

/// Settings which custom the output of the [`DotPrinter`] visitor.
/// Settings which customize the output of the [`DotPrinter`] visitor.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct DotPrinterSettings {
/// Add node address to output in graphs
pub display_node_address: bool,
}

/// A visitor the the radix trie that will print the tree in "dot" notation.
/// A visitor of the radix trie that will print the tree in "dot" notation.
///
/// See ['DOT Language | Graphviz'](https://graphviz.org/doc/info/lang.html) for
/// information about syntax and example of the language.
Expand Down
6 changes: 5 additions & 1 deletion tests/memory_usage_fixed_length_dense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ fn test_memory_usage() {
dhat::assert_eq!(stats.curr_bytes, 0);

dhat::assert_eq!(stats.max_blocks, 398);
dhat::assert_eq!(stats.max_bytes, 17024);
if cfg!(any(miri, feature = "nightly")) {
dhat::assert_eq!(stats.max_bytes, 18088);
} else {
dhat::assert_eq!(stats.max_bytes, 17024);
}

let num_keys = KEY_LEVEL_WIDTH
.iter()
Expand Down
6 changes: 5 additions & 1 deletion tests/memory_usage_large_prefixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ fn test_memory_usage() {
dhat::assert_eq!(stats.curr_bytes, 0);

dhat::assert_eq!(stats.max_blocks, 360);
dhat::assert_eq!(stats.max_bytes, 17225);
if cfg!(any(miri, feature = "nightly")) {
dhat::assert_eq!(stats.max_bytes, 17681);
} else {
dhat::assert_eq!(stats.max_bytes, 17225);
}

let num_keys = KEY_LEVEL_WIDTH
.iter()
Expand Down
6 changes: 5 additions & 1 deletion tests/memory_usage_skewed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ fn test_memory_usage() {
dhat::assert_eq!(stats.curr_bytes, 0);

dhat::assert_eq!(stats.max_blocks, 511);
dhat::assert_eq!(stats.max_bytes, 25170);
if cfg!(any(miri, feature = "nightly")) {
dhat::assert_eq!(stats.max_bytes, 27202);
} else {
dhat::assert_eq!(stats.max_bytes, 25170);
}

let mean_blocks_per_key = (stats.max_blocks as f64) / (KEY_LENGTH_LIMIT as f64);
let mean_bytes_per_key = (stats.max_bytes as f64) / (KEY_LENGTH_LIMIT as f64);
Expand Down

0 comments on commit 416e48c

Please sign in to comment.