Skip to content

Commit 63ae090

Browse files
ldm0hawkw
authored andcommitted
tracing: inline methods to make macro-generated code smaller (#2555)
## Motivation Make `tracing::event!` codegen smaller ## Solution Add `inline` to several functions called by `tracing::event!`. Simple example: https://github.com/ldm0/tracing_test After inlining, executable size drops from 746kb to 697kb (`cargo build --release + strip`), saves 50 bytes per `event!`. Test environment: ``` toolchain: nightly-aarch64-apple-darwin rustc-version: rustc 1.70.0-nightly (88fb1b922 2023-04-10) ``` There are also performance improvements in the benchmarks: ``` event/scoped [-40.689% -40.475% -40.228%] event/scoped_recording [-14.972% -14.685% -14.410%] event/global [-48.412% -48.217% -48.010%] span_fields/scoped [-25.317% -24.876% -24.494%] span_fields/global [-39.695% -39.488% -39.242%] span_repeated/global [-27.514% -26.633% -25.298%] static/baseline_single_threaded [-32.275% -32.032% -31.808%] static/single_threaded [-29.628% -29.376% -29.156%] static/enabled_one [-29.777% -29.544% -29.305%] static/enabled_many [-30.901% -30.504% -30.140%] dynamic/baseline_single_threaded [-20.157% -19.880% -19.603%] ``` I retried benchmark several times and the improvements seem to be fairly stable. raw log: https://gist.github.com/ldm0/6573935f4979d2645fbcf5bde7361386
1 parent 6f7a4b8 commit 63ae090

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

tracing-core/src/field.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ impl FieldSet {
820820
///
821821
/// [`Identifier`]: super::callsite::Identifier
822822
/// [`Callsite`]: super::callsite::Callsite
823+
#[inline]
823824
pub(crate) fn callsite(&self) -> callsite::Identifier {
824825
callsite::Identifier(self.callsite.0)
825826
}
@@ -857,6 +858,7 @@ impl FieldSet {
857858
}
858859

859860
/// Returns an iterator over the `Field`s in this `FieldSet`.
861+
#[inline]
860862
pub fn iter(&self) -> Iter {
861863
let idxs = 0..self.len();
862864
Iter {
@@ -960,6 +962,7 @@ impl PartialEq for FieldSet {
960962

961963
impl Iterator for Iter {
962964
type Item = Field;
965+
#[inline]
963966
fn next(&mut self) -> Option<Field> {
964967
let i = self.idxs.next()?;
965968
Some(Field {

tracing-core/src/metadata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ impl<'a> Metadata<'a> {
273273
}
274274

275275
/// Returns the names of the fields on the described span or event.
276+
#[inline]
276277
pub fn fields(&self) -> &field::FieldSet {
277278
&self.fields
278279
}

tracing/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2311,7 +2311,7 @@ macro_rules! valueset {
23112311
)
23122312
};
23132313

2314-
// Remainder is unparseable, but exists --- must be format args!
2314+
// Remainder is unparsable, but exists --- must be format args!
23152315
(@ { $(,)* $($out:expr),* }, $next:expr, $($rest:tt)+) => {
23162316
$crate::valueset!(@ { (&$next, Some(&format_args!($($rest)+) as &dyn Value)), $($out),* }, $next, )
23172317
};

0 commit comments

Comments
 (0)