Force inlining source and target node id lookup in candidate hops
authorMatt Corallo <git@bluematt.me>
Sat, 9 Dec 2023 21:12:30 +0000 (21:12 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 10 Dec 2023 16:38:35 +0000 (16:38 +0000)
Because our router is rather large, LLVM doesn't always decide to
inline small functions in it, opting instead for a call. This is
somewhat wasteful when we do repeated `match`es on the same data,
so here we force inlining of the `source` and `target` `NodeId`
lookups.

lightning/src/routing/router.rs

index e847c001b167f7799cccae0bb356ae4324b7ec22..57efd9f7812d49c6c11ee5bdcacf079e610d0b39 100644 (file)
@@ -1260,7 +1260,7 @@ impl<'a> CandidateRouteHop<'a> {
        /// Source node id refers to the node forwarding the HTLC through this hop.
        ///
        /// For [`Self::FirstHop`] we return payer's node id.
-       #[inline]
+       #[inline(always)]
        pub fn source(&self) -> NodeId {
                match self {
                        CandidateRouteHop::FirstHop { payer_node_id, .. } => **payer_node_id,
@@ -1279,7 +1279,7 @@ impl<'a> CandidateRouteHop<'a> {
        ///
        /// For [`Self::OneHopBlinded`] we return `None` because the target is the same as the source,
        /// and such a return value would be somewhat nonsensical.
-       #[inline]
+       #[inline(always)]
        pub fn target(&self) -> Option<NodeId> {
                match self {
                        CandidateRouteHop::FirstHop { details, .. } => Some(details.counterparty.node_id.into()),