From c13591c17cdf9111e7a3b0559fa7b13e511ca3d8 Mon Sep 17 00:00:00 2001 From: Paul1365972 Date: Tue, 7 Oct 2025 01:34:53 +0200 Subject: [PATCH] redpiler: document and adjust node struct size for better padding usage --- crates/redpiler/src/backend/direct/node.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/redpiler/src/backend/direct/node.rs b/crates/redpiler/src/backend/direct/node.rs index efbe1ecd..28a64cfc 100644 --- a/crates/redpiler/src/backend/direct/node.rs +++ b/crates/redpiler/src/backend/direct/node.rs @@ -149,12 +149,19 @@ impl NonMaxU8 { } } +// The size of `Node` is 96 bytes (aligned to 16 bytes boundaries). +// This means 4 nodes fit into 3 cache lines (assuming 128 byte long cache lines). +// For the best possbile memory layout adjust the inline array capacity of `updates: SmallVec<_>` as follows: +// 1. The capacity should be always be odd as one entry is always used internally as discriminant +// 2. Optionally increase or decrease the capacity by 2 to eleminate `Node` padding +// 3. Finally increase or decrease the capacity by multiples of 4 until satisfied +// There are currently 6 bytes unused due to alignment/padding. #[derive(Debug, Clone)] pub struct Node { pub ty: NodeType, pub default_inputs: NodeInput, pub side_inputs: NodeInput, - pub updates: SmallVec<[ForwardLink; 10]>, + pub updates: SmallVec<[ForwardLink; 9]>, pub is_io: bool, /// Powered or lit