From ae46dcae2a177f839692b05b96afd8ca9dd0717f Mon Sep 17 00:00:00 2001 From: patrick-immometrica Date: Sun, 15 Nov 2026 19:16:39 +0100 Subject: [PATCH 1/2] Keep log_impl out of callsites Since the logger param was added log_impl is generic, so it's compiled in the calling crate and inlined there. Every log statement then builds the whole Record itself. --- src/__private_api.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/__private_api.rs b/src/__private_api.rs index 09e7a7ed6..4c88c1df2 100644 --- a/src/__private_api.rs +++ b/src/__private_api.rs @@ -54,7 +54,9 @@ impl Log for GlobalLogger { } } -// Split from `log` to reduce generics and code size +// Split from `log` to reduce generics and code size. +// Being generic over the logger, it gets inlined into callsites without the attribute +#[inline(never)] fn log_impl( logger: L, args: Arguments, From 03b22ad75fff6a568cc3998fa6b9a6b3caa5f10c Mon Sep 17 00:00:00 2001 From: patrick-immometrica Date: Sun, 15 Nov 2026 19:16:39 +0100 Subject: [PATCH 2/2] Pass the callsite location as its own argument A tuple holding the result of loc() can't be promoted to a static, so it was written to the stack before each call. Without it the target and module path are a constant again whenever the target is one. --- src/__private_api.rs | 9 ++++++--- src/macros.rs | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/__private_api.rs b/src/__private_api.rs index 4c88c1df2..20a7c8770 100644 --- a/src/__private_api.rs +++ b/src/__private_api.rs @@ -61,7 +61,8 @@ fn log_impl( logger: L, args: Arguments, level: Level, - &(target, module_path, loc): &(&str, &'static str, &'static Location), + &(target, module_path): &(&str, &'static str), + loc: &'static Location, kvs: Option<&[(Key, Value)]>, ) { #[cfg(not(feature = "kv"))] @@ -89,7 +90,8 @@ pub fn log<'a, K, L>( logger: L, args: Arguments, level: Level, - target_module_path_and_loc: &(&str, &'static str, &'static Location), + target_and_module_path: &(&str, &'static str), + loc: &'static Location, kvs: K, ) where K: KVs<'a>, @@ -99,7 +101,8 @@ pub fn log<'a, K, L>( logger, args, level, - target_module_path_and_loc, + target_and_module_path, + loc, kvs.into_kvs(), ) } diff --git a/src/macros.rs b/src/macros.rs index 1e766997b..bef7f45d7 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -125,7 +125,8 @@ macro_rules! __log { $logger, $crate::__private_api::format_args!($($arg)+), lvl, - &($target, $crate::__private_api::module_path!(), $crate::__private_api::loc()), + &($target, $crate::__private_api::module_path!()), + $crate::__private_api::loc(), &[$(($crate::__log_key!($key), $crate::__log_value!($key $(:$capture)* = $($value)*))),+] as &[_], ); } @@ -139,7 +140,8 @@ macro_rules! __log { $logger, $crate::__private_api::format_args!($($arg)+), lvl, - &($target, $crate::__private_api::module_path!(), $crate::__private_api::loc()), + &($target, $crate::__private_api::module_path!()), + $crate::__private_api::loc(), (), ); }