feat(logging): zero-allocation format->dispatch path (LogRecord view)#795
Open
kamcheungting-db wants to merge 1 commit into
Open
feat(logging): zero-allocation format->dispatch path (LogRecord view)#795kamcheungting-db wants to merge 1 commit into
kamcheungting-db wants to merge 1 commit into
Conversation
Sinks now receive a non-owning `LogRecord` { level, string_view message,
source_location, span<const LogAttribute> } instead of an owned `LogMessage&&`.
The macros/function-style Log() format into a reused per-thread `FormatBuffer()`
(std::format_to + clear-keeps-capacity), so logging does no heap allocation after
the buffer warms up. `LogMessage`/`Builder` stay as the owned/retained type and
convert implicitly to `LogRecord`, so `logger->Log(builder.Build())` is unchanged.
Synchronous sinks (Cerr/Spd/Noop) read the view directly; retaining sinks
(test CapturingLogger) deep-copy into an owned LogMessage. Adds a dedicated
logging_zero_alloc_test (global operator-new counter + negative control) proving
the path is allocation-free. CerrLogger's own line rendering and
ICEBERG_LOG_RUNTIME_FMT still allocate (documented; out of this change's scope).
Co-authored-by: Isaac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes the logging format → dispatch path allocation-free, addressing the zero-allocation request on #725. Builds on the merged logging blocks (#722/#723/#724).
What changed
LogRecord({ level, std::string_view message, std::source_location, std::span<const LogAttribute> }) instead of an ownedLogMessage&&. The views are valid only for the duration of theLog()call.Log()/FormatAndEmitformat into a reused per-threadFormatBuffer()viastd::format_to(clear()keeps capacity), so logging performs no heap allocation after the buffer warms up.std::format_towith astd::format_stringkeeps compile-time format-string checking.LogMessage/Builderstay as the owned/retained type and convert implicitly toLogRecord, sologger->Log(builder.Build())is unchanged.CerrLogger, no-op) read the view directly with no allocation; retaining sinks (the testCapturingLogger) deep-copy into an ownedLogMessage, so existing assertions are unaffected.Why now: every production sink consumes the record synchronously, so the owned-
std::stringmodel wasn't buying anything in practice — better to change the interface before external adoption.Tests: new
logging_zero_alloc_test(its own binary; globaloperator newcounter + a negative control proving the probe works) asserts the format→dispatch path does 0 heap allocations after warmup. Existing logging tests pass unchanged; ASan/TSan clean.Out of scope (documented):
CerrLogger's own rendered-linestd::formatandICEBERG_LOG_RUNTIME_FMT(vformat) still allocate.The open macro/spdlog/registry PRs (#725/#726/#737) will be rebased onto this interface once it lands.
This pull request and its description were written by Isaac.