Repository navigation
Description
Context
Each logforth_core logging macro invocation (info!, debug!, etc.) checks Logger::enabled(level) and passes &LOC to the non-generic helper __private::log (core/src/macros.rs), where LOC is a per-callsite static Location descriptor:
Location (40 bytes, align = 8 on 64-bit targets):
+--------------------+--------------------+----------+----------+
| module_path (16 B) | file (16 B) | line(4B) | col (4B) |
+--------------------+--------------------+----------+----------+
Two structural properties stand out when comparing against log (see rust-lang/log#569, rust-lang/log#575, and rust-lang/log#705):
- Per-callsite
.rodataduplication & alignment padding: Becauselineandcolumndiffer on each line, the compiler cannot mergestatic LOCinstances within the same file or module, duplicating the 32-byte(module_path, file)fat pointers in.rodataat every callsite. Simply droppingcolumn: u32alone does not shrink.rodataon 64-bit targets because 8-byte struct alignment pads16 + 16 + 4 = 36back up to40bytes (4 Btail padding), whereas splitting a module-shared(module_path, file)constant from a per-callsitelineargument allows constant merging. Meanwhile, across built-in components, onlylogforth-append-opentelemetrycurrently readsRecord::column. - Non-generic callsite
.textvs. compile-time level stripping: Because__private::logis non-generic, LLVM does not inlineRecordconstruction into every callsite underopt-level = 3, keeping.textsmaller thanlogwhen all levels remain compiled. Underopt-level = "z",logsaves ~16 B/call in.rodataviaLocation::caller()(24 B) while spending ~10 B/call more in.textto assemble&(target, module_path, loc)on the stack (net ~6 B/call difference). However,logforth-coredoes not currently offer compile-timemax_level_*/release_max_level_*feature gates to dead-code-eliminate verbose callsites altogether.
Preliminary Measurements
Binary section deltas follow a linear model C_0: fixed runtime code, N: compiled callsites, P: format arguments, K: key-value pairs). Sample numbers for N = 1,000 calls across 20 modules (50 calls/module, 1 format argument, aarch64-apple-darwin, -C strip=symbols):
Configuration (N = 1,000) |
log v0.4 (.text + .rodata = total) |
logforth-core (.text + .rodata = total) |
Marginal slope (log vs. logforth) |
|---|---|---|---|
opt-level = "z", 1 format arg |
43.0 KB + 25.3 KB = 68.3 KB |
37.2 KB + 42.1 KB = 79.4 KB |
~68 B/call vs. ~74 B/call |
opt-level = "z", + 2 KV pairs |
55.2 KB + 25.6 KB = 80.8 KB |
49.5 KB + 42.4 KB = 91.9 KB |
+6.2 B/KV on both |
opt-level = 3, 1 format arg |
118.4 KB + 1.3 KB = 119.7 KB |
59.1 KB + 42.1 KB = 101.3 KB |
~119 B/call vs. ~97 B/call |
opt-level = 3, + 2 KV pairs |
171.5 KB + 1.4 KB = 172.8 KB |
103.9 KB + 42.3 KB = 146.3 KB |
+26.6 B/KV vs. +22.5 B/KV |
In an isolated 1,000-call microbenchmark (opt-level = "z"), splitting shared &(module_path!(), file!()) metadata from a register-passed line!() argument (and omitting column) reduced .rodata by ~39.3 KB at a cost of +320 B in .text.
Scope of Investigation
- Build a reproducible benchmark script or standalone crate measuring
.text,.rodata, total stripped binary size, and callsite latency across Linux (ELFx86_64/aarch64) and macOS (Mach-O), coveringopt-level = 3,"s", and"z"(with and without LTO). - Evaluate splitting shared
(module_path, file)metadata from per-callsiteline, and assess whetherRecord::column/RecordBuilder::columnshould be retained, removed beforelogforth-core 1.0, or represented differently. - Evaluate micro-optimizations at macro callsites, such as avoiding empty
&[]key-value slice construction when no fields are passed and checking#[inline]behavior ofLogger::enabled. - Explore whether optional compile-time static level filtering (
max_level_*/release_max_level_*Cargo features) makes sense alongside explicitLoggerinstances.
Activity
meditecnic commentedon Nov 29, 2026
Edit: collapsed the raw data tables to keep the thread readable. No wording or numbers changed.
Hi! 👋 I ran a standalone Linux
x86_64ELF benchmark and a set of single-variable prototype experiments againstlogforth-core(5cf0480) andlog(0.4.31) to complement the macOS Mach-O measurements in the issue description.Environment and Methodology
7.0.0-38-generic(x86_64, glibc 2.43), AMD Ryzen 7 4800H (8C/16T),rustc 1.100.1 (20ddd0171 2026-11-25),cargo 1.100.1,GNU ld 2.46,GNU readelf 2.46.fast/logforthat5cf0480a2641b7807b742d2db099fa2594070b0e(logforth-core 0.4.0, default features) vs.log 0.4.31(features = ["std", "kv"]for KV feature parity, plus afeatures = ["std"]control on the no-KV case)../reproduce.sh --cleanalongside a sibling../logforthcheckout; single-variable prototype diffs are underpatches/).src/mods/m00.rs..m19.rs), measured atN = 0, 20, 200, 1,000callsites (0, 1, 10, 50calls/module) for1 format arg("event {}", x) and1 format arg + 2 KV pairs(u64+bool), across all 9opt-level(3,"s","z") xlto(false,"thin","fat") profiles with fixedcodegen-units = 1,panic = "unwind", andstrip = "symbols". A cold multi-shape call inmain()(warn!with KV +error!) prevents unrealistic whole-program IPCP from foldinglevel/kvs/format template under Fat LTO, andcompiler_fence(Ordering::SeqCst)prevents coalescing sequential level checks without adding machine instructions.10Miterations for disabled fast path,2Mfor enabled no-I/O path using a no-opAppend/log::Log), withstd::hint::black_boxon runtime inputs and inside the no-op sink; reports median and IQR (Q3 - Q1). Becauselogforth_core::record::RecordBuilder::new()callsSystemTime::now()whilelog::Recorddoes not, standaloneSystemTime::now()is measured in the same harness to separate timestamp cost.nm -C -Sandobjdump -d -Con unstripped builds (20/20module functions retained,1,000callsites emitted with zero loop rerolling or DCE), full ELF section diff checked acrossN = 200 -> 1,000, and a clean-slate rerun (./reproduce.sh --clean) reproduced180/180size builds byte-for-byte.1. Linux ELF Binary Size Matrix (
N = 1,000, stripped)Show tables
1 format arg
opt/lto.text.rodata.data.rel.ro.rela.dyn.eh_frameN=0(B)3/falselog3/falselogforth3/thinlog3/thinlogforth3/fatlog3/fatlogforths/falselogs/falselogforths/thinlogs/thinlogforths/fatlogs/fatlogforthz/falselogz/falselogforthz/thinlogz/thinlogforthz/fatlogz/fatlogforth1 format arg + 2 KV pairs
opt/lto.text.rodata.data.rel.ro.rela.dyn.eh_frameN=0(B)3/falselog3/falselogforth3/thinlog3/thinlogforth3/fatlog3/fatlogforths/falselogs/falselogforths/thinlogs/thinlogforths/fatlogs/fatlogforthz/falselogz/falselogforthz/thinlogz/thinlogforthz/fatlogz/fatlogforthSlope (B/call)is the marginal slope(File(1,000) - File(200)) / 800, isolating per-callsite cost fromN = 0fixed overhead; marginal slopes matched within ~1–3 B/call betweenN = 20 -> 200andN = 200 -> 1,000across all profiles. Marginal KV cost ((kv2 - arg1) / 2) was+50.4to+50.6 B/KVforlogforthvs.+60.6 B/KVforlogunder3/falseand3/fat, and+40.5to+41.5 B/KV(logforth) vs.+40.0to+47.0 B/KV(log) unders/zwith LTO (without LTO unders/z, both crates jump to+93to+110 B/KVbecauseLogValue::log_value/ToValue::to_valueare not inlined across crates).log'skvfeature (features = ["std"]) reduceslogarg1atN = 1,000by-50.5 KBunder3/false(517,352 B,178.8 B/call) and-50.7 KBunder3/fat(506,048 B,212.8 B/call) becauselog::__private_api::log_implinlines&NoneKV vtable setup at-O3, whereas unders/zthe difference is only-1.1to-4.0 KB. Separately,loguses a global singleton whereaslogforth-corepasses an explicit&Loggerparameter. A side probe withcodegen-units = 16onlogfortharg1left.data.rel.roand.rela.dynunchanged and shifted.textby+1.1to+3.0 KB.2. Callsite Latency Baseline (11 independent runs, median ns/op, IQR in parens)
Show tables
3/off3/fats/offz/offz/fatblack_box)SystemTime::now()onlylogdisabled (1 arg)logdisabled (1 arg + 2 KV)logforthdisabled, filtered (1 arg)logforthdisabled, filtered (2 KV)logforthdisabled,noop(1 arg)logenabled, no-op (1 arg)logenabled, no-op (1 arg + 2 KV)logforthenabled, no-op (1 arg)logforthenabled, no-op (2 KV)3. Single-Variable Prototype Experiments (vs. Baseline
5cf0480atN = 1,000)Show tables
Each prototype isolates one change on a local branch from
5cf0480before testing combinations: A adds__private::log_no_kvso empty[]calls skip&[]; B adds#[inline]toLogger::enabled; C0 dropscolumnfromLocationwithout splitting(module_path, file); C1 splitsconst { &ModuleLocation::new(module_path!(), file!()) }(32 B, align 8) and passesline: u32, column: u32; C1p packs(line, column)intou64(preservingRecord::column); C2 splitsModuleLocation, passesline: u32, and removesRecord::column/RecordBuilder::column(also updatingappenders/opentelemetryand integration tests;Recordshrinks128 -> 120 B,RecordOwned136 -> 128 B).Stripped file size delta vs. baseline (
logforth,1 format arg, bytes)3/off3/thin3/fats/offs/fatz/offz/fatlog_no_kv(no&[])#[inline]Logger::enabledcolumn(unsplitLOC)ModuleLoc+line, colModuleLoc+ packedu64ModuleLoc, removecolumn#[inline(never)])#[inline(never)])#[inline(never)]Stripped file size delta vs. baseline (
logforth,1 format arg + 2 KV pairs, bytes)3/off3/thin3/fats/offs/fatz/offz/fatlog_no_kv(no&[])#[inline]Logger::enabledcolumn(unsplitLOC)ModuleLoc+line, colModuleLoc+ packedu64ModuleLoc, removecolumn#[inline(never)]Section breakdown at
oz-lto-off(logforth,1 format arg,N = 1,000) and prototype latency (median ns, 11 runs).text.data.rel.ro.rela.dyn.eh_frame3/offs/offz/off3/off3/fat5cf0480)log_no_kv#[inline]Logger::enabledModuleLoc+l, cModuleLoc+u64column#[inline(never)]All non-control prototypes (
A,B,C1,C1p,C2, andA + B + C1p + #[inline(never)]) passedcargo +nightly check -Dwarnings,cargo test(unit, integration, and doctests),cargo +nightly clippy -- -D warnings,cargo +nightly fmt --all --check, anddocsrsrustdoc checks across all workspace crates exceptlogforth-append-syslog'snative-tlsfeature (requires systemlibssl-dev, absent on this host);taplo,typos, andhawkeyeare also not installed locally.Key Findings
Locationcost to88 B/call: BecauseLocationholds two&'static strpointers, PIE binaries placestatic LOCin.data.rel.ro(+40 B/call) rather than.rodata(+0.02 B/call) and emit two 24-byteR_X86_64_RELATIVEentries in.rela.dyn(+48 B/call). Enabling RELR (-Wl,-z,pack-relative-relocs) shrinks.rela.dyn(66,528 -> 1,608 Bplus848 B.relr.dynatoz-lto-off), but.data.rel.rostill pays40 B/call. Droppingcolumnwithout splitting (C0) leavessize_of::<Location>() == 40and saves0 Bin.data.rel.roand.rela.dynacross all profiles (the+10.4 KBdelta at3/thinis a.text+11.2 KBThin LTO codegen shift), confirming the alignment-padding observation.ModuleLocation+ packing(line, column)+log_no_kvcaptures ~95% of the win without breakingRecord::column: Splittingconst { &ModuleLocation }saves-39.4 KB.data.rel.roand-47.1 KB.rela.dyn(-86.5 KBtotal), but onx86_64SysV ABI (6 integer argument registers), addinglineandcolumnwithoutlog_no_kvspills arguments to the stack and adds+10to+27 KBof.eh_frameunwind metadata. Combininglog_no_kvwith packedline_col: u64(A + C1p) fits all 6 registers (logger,level,loc,line_col,fmt::Arguments2 words) with zero stack spills, saving-88to-100 KBonarg1(-59to-74 KBonarg1_kv2) while keepingRecord::columnintact; removingRecord::column(C2vs.C1p) yields an additional~2–5 B/callonarg1(and-8 BonRecord/RecordOwned) while breakinglogforth-append-opentelemetryandRecord::columncallers.#[inline]onLogger::enabledis a free win under-Os/-Ozwithout LTO: Onrustc 1.100.1, MIR inlining already inlinesLogger::enabledatopt-level = 3(even withlto = false), and LTO inlines it unders/z. Unders/zwithlto = false, adding#[inline]both shrinks stripped binaries (-4.9to-12.6 KB, eliminating GOT calls andpush/pop.eh_frameentries) and reduces disabled fast-path latency from1.53–1.98 nsto0.48–0.74 ns(2.7x–3.2xfaster), with0 B/0 nsregression elsewhere.__private::logis a hidden size trap: In baselineo3-lto-thin, Thin LTO inlines__private::loginto all 1,000 callsites (+125 KB.text,-88 KB.data.rel.ro + .rela.dyn, net+40 B/call). Introducinglog_no_kv(A) splitsLogger::logfrom 1 caller to 2, causing Fat LTO (o3-lto-fat) to stop inliningLogger::loginto__private::logand instead inline__private::log*into every callsite (+38to+63 KB). Marking__private::logand__private::log_no_kv#[inline(never)]prevents that regression across all 18 matrix cells (-90to-130 KBcombined), trading~2–3.8 nson the no-I/O enabled path under Fat LTO (vs.~23–24 nsforSystemTime::now()). Note also that underpanic = "unwind",opt-level = "z"produces slightly larger stripped binaries thanopt-level = "s"becausepush $imm8; popsequences inflate.eh_frame.max_level_*/release_max_level_*features: Becauselogforth-coremodels channels as explicitLoggerinstances rather than a global singleton (DESIGN.md) and disabled callsites already short-circuit in~0.49 nsvia a 24-bit mask test, crate-wide additive Cargo features create a real footgun where one dependency enablingrelease_max_level_infowould strip verbose callsites from unrelatedLoggerchannels (e.g., dedicated audit or diagnostic loggers) across the entire workspace; if added, they would likely need strict top-level-binary-only guidance similar tolog.Disclosure: I used AI assistance to help draft the benchmark harness scripts and analyze the ELF/disassembly data; all builds, tests, and measurements were compiled and executed locally on Linux and verified from a clean rebuild.
Happy to open a small focused PR for a non-breaking subset first (e.g.,
#[inline]onLogger::enabledand/or theconst &ModuleLocation+ packed(line, column)+log_no_kv+#[inline(never)]macro layout), or integrate the benchmark script in-tree if you think that's useful 🤗tisonkun commentedon Nov 30, 2026
@meditecnic Please try to write the comment top-down and convince me what you want to do is trustworthy, instead of pushing a 2000 words of AI reports and expect others to interpret it.
Have you read the report you throw here? Do you know what it means? Do you think it's useful? If so, why?
meditecnic commentedon Nov 30, 2026
Fair point — I'm sorry for dumping a long AI-generated report and ending with a vague "if you think that's useful".
To answer your questions honestly: I'm still learning Rust and used AI to build the benchmark and write up the report, so I don't want to pretend I designed that patch myself. Looking back, the combined
u64-packing +#[inline(never)]proposal I added at the end was a hack around compiler heuristics rather than a sound design, so I'm withdrawing it.The one data point I can explain and stand behind is the Linux
x86_64baseline: each callsite'sstatic LOCholds two pointers, so in a PIE binary it lands in.data.rel.ro(40 B) and also needs two dynamic relocations in.rela.dyn(48 B), ~88 B per callsite vs. ~40 B in the macOS numbers. So the per-callsite cost that the metadata split targets is roughly twice as large on Linux.I'll take the time to understand the design trade-offs properly before coming back with anything else. Thanks for the direct feedback.