Skip to content

Commit ef7f001

Browse files
committed
Reorder PathBuildingHop fields somewhat
Given `PathBuildingHop` is now an even multiple of cache lines, we can pick which fields "fall off" the cache line we have visible when dealing with hops, which we do here.
1 parent 2fc2bbc commit ef7f001

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

lightning/src/routing/router.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,15 +1308,15 @@ fn iter_equal<I1: Iterator, I2: Iterator>(mut iter_a: I1, mut iter_b: I2)
13081308
/// Fee values should be updated only in the context of the whole path, see update_value_and_recompute_fees.
13091309
/// These fee values are useful to choose hops as we traverse the graph "payee-to-payer".
13101310
#[derive(Clone)]
1311+
#[repr(C)] // Force fields to appear in the order we define them.
13111312
struct PathBuildingHop<'a> {
13121313
candidate: CandidateRouteHop<'a>,
1313-
fee_msat: u64,
1314-
1315-
/// All the fees paid *after* this channel on the way to the destination
1316-
next_hops_fee_msat: u64,
1317-
/// Fee paid for the use of the current channel (see candidate.fees()).
1318-
/// The value will be actually deducted from the counterparty balance on the previous link.
1319-
hop_use_fee_msat: u64,
1314+
/// If we've already processed a node as the best node, we shouldn't process it again. Normally
1315+
/// we'd just ignore it if we did as all channels would have a higher new fee, but because we
1316+
/// may decrease the amounts in use as we walk the graph, the actual calculated fee may
1317+
/// decrease as well. Thus, we have to explicitly track which nodes have been processed and
1318+
/// avoid processing them again.
1319+
was_processed: bool,
13201320
/// Used to compare channels when choosing the for routing.
13211321
/// Includes paying for the use of a hop and the following hops, as well as
13221322
/// an estimated cost of reaching this hop.
@@ -1328,12 +1328,20 @@ struct PathBuildingHop<'a> {
13281328
/// All penalties incurred from this channel on the way to the destination, as calculated using
13291329
/// channel scoring.
13301330
path_penalty_msat: u64,
1331-
/// If we've already processed a node as the best node, we shouldn't process it again. Normally
1332-
/// we'd just ignore it if we did as all channels would have a higher new fee, but because we
1333-
/// may decrease the amounts in use as we walk the graph, the actual calculated fee may
1334-
/// decrease as well. Thus, we have to explicitly track which nodes have been processed and
1335-
/// avoid processing them again.
1336-
was_processed: bool,
1331+
1332+
// The last 16 bytes are on the next cache line by default in glibc's malloc. Thus, we should
1333+
// only place fields which are not hot there. Luckily, the next three fields are only read if
1334+
// we end up on the selected path, and only in the final path layout phase, so we don't care
1335+
// too much if reading them is slow.
1336+
1337+
fee_msat: u64,
1338+
1339+
/// All the fees paid *after* this channel on the way to the destination
1340+
next_hops_fee_msat: u64,
1341+
/// Fee paid for the use of the current channel (see candidate.fees()).
1342+
/// The value will be actually deducted from the counterparty balance on the previous link.
1343+
hop_use_fee_msat: u64,
1344+
13371345
#[cfg(all(not(ldk_bench), any(test, fuzzing)))]
13381346
// In tests, we apply further sanity checks on cases where we skip nodes we already processed
13391347
// to ensure it is specifically in cases where the fee has gone down because of a decrease in

0 commit comments

Comments
 (0)