Skip to content

Commit aa4785c

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 da50bd0 commit aa4785c

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

0 commit comments

Comments
 (0)