Skip to content

feat(core): Zero-Copy Logging — ZeroCopyLogger with string_view hot-path and pre-allocated thread-local buffer (v1.6.0, Issue #65) - #4162

Merged
makr-code merged 3 commits into
developfrom
copilot/zero-copy-logging-implementation
Mar 13, 2026
Merged

makr-code merged 3 commits into
developfrom
copilot/zero-copy-logging-implementation

Conversation

Copilot AI commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

Implements the Zero-Copy Logging roadmap item (v1.6.0) targeting 30–50% reduction in logging hot-path allocations. Adds ZeroCopyLogger, a drop-in ILogger replacement backed by two complementary mechanisms: string_view dispatch and a per-thread pre-allocated format buffer.

New: ZeroCopyLogger

Files: include/core/concerns/zero_copy_logger.h · src/core/concerns/zero_copy_logger.cpp

  • string_view hot-path API — logSV / traceSV / debugSV / infoSV / warnSV / errorSV / criticalSV / logStructuredSV forward directly to spdlog without constructing an intermediate std::string
  • Pre-allocated thread-local buffer — logStructuredSV and logStructured reuse a static thread_local std::string reserved once per thread at kDefaultBufferCapacity = 4096 bytes; subsequent calls clear() (no deallocation) and write into it
  • Early level-check — shouldLog(Level) lets callers skip expensive formatting before it starts
  • ILogger compatibility — all const std::string& virtual overrides delegate to the string_view path; zero caller-side changes required
  • Thread-safe mode toggle — json_mode_ is std::atomic<bool> so setJsonMode() is safe to call concurrently with active logging threads
  • Allocation-free PII redaction — isPiiKey() uses a 128-byte stack buffer and string_view::find; no heap allocation on the hot path
auto logger = std::make_unique<ZeroCopyLogger>(spdlog_logger);

// Zero-copy hot path — no std::string construction
logger->infoSV("query executed");
logger->logStructuredSV(ILogger::Level::INFO, "insert done",
    {{"table", "users"}, {"rows", "1"}});   // initializer_list, no alloc

// Guard expensive formatting behind level check
if (logger->shouldLog(ILogger::Level::DEBUG))
    logger->debugSV(buildExpensiveMessage());

// Drop-in via ILogger*
ILogger* ilog = logger.get();
ilog->info("startup complete");             // delegates to infoSV, no copy

Build system

zero_copy_logger.cpp added to cmake/CMakeLists.txt (THEMIS_CORE_SOURCES) and cmake/ModularBuild.cmake.

Tests

41 focused tests in tests/test_zero_copy_logging.cpp → ZeroCopyLoggingFocusedTests CTest target, covering all acceptance criteria including:

  • All six *SV levels + logSV dispatch
  • shouldLog early-exit (filtered levels produce zero output)
  • JSON mode + plain-text structured output
  • PII redaction for password / token / email / ssn / secret keys in both modes
  • ILogger* polymorphic use
  • Lifecycle (flush / shutdown / isHealthy)
  • setLevel / getLevel round-trip
  • Concurrent logSV (8 threads) + concurrent logStructuredSV (4 threads) — null-sink, no crash
  • ConcurrentSetJsonMode_WhileLogging_NoRaceOrCrash — 4 logger threads + 2 setJsonMode toggle threads exercising the atomic fix

Documentation

  • src/core/FUTURE_ENHANCEMENTS.md — Zero-Copy Logging marked ✅ Implemented
  • src/core/ROADMAP.md — added to Completed list and Phase 3

Type of Change

  • Bug fix
  • New feature
  • Refactoring
  • Documentation
  • Other:

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed

📚 Research & Knowledge (wenn applicable)

  • Diese PR basiert auf wissenschaftlichen Paper(s) oder Best Practices?
    • Falls JA: Research-Dateien in /docs/research/ angelegt?
    • Falls JA: Im Modul-README unter "Wissenschaftliche Grundlagen" verlinkt?
    • Falls JA: In /docs/research/implementation_influence/ eingetragen?

Relevante Quellen:

  • Paper:
  • Best Practice:
  • Architecture Decision:

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No new warnings introduced
Original prompt

This section details on the original issue you should resolve

<issue_title>Zero-Copy Logging</issue_title>
<issue_description>### Context

This issue implements the roadmap item 'Zero-Copy Logging' for the core domain. It is sourced from the consolidated roadmap under 🟠 High Priority — Near-term (v1.5.0 – v1.8.0) and targets milestone v1.6.0.

Primary detail section: Zero-Copy Logging

Goal

Deliver the scoped changes for Zero-Copy Logging in src/core/ and complete the linked detail section in a release-ready state for v1.6.0.

Detailed Scope

Zero-Copy Logging

Priority: High
Target Version: v1.6.0

Reduce memory allocations in logging hot paths.

Current: String formatting and copying for every log call
Target: Pre-allocated buffers and string_view usage

Expected Improvement: 30-50% reduction in logging overhead


Acceptance Criteria

  • Implement the scoped changes described in the linked detail section.
  • Add or update tests that verify the intended behaviour.

Relationships

References

  • src/ROADMAP.md
  • src/core/FUTURE_ENHANCEMENTS.md#zero-copy-logging
  • Source key: roadmap:65:core:v1.6.0:zero-copy-logging

Generated from the consolidated source roadmap. Keep the roadmap and issue in sync when scope changes.

</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…nd pre-allocated thread-local buffer (v1.6.0, Issue #65)

Co-authored-by: makr-code <[email protected]>
Copilot AI changed the title [WIP] Implement zero-copy logging for core domain feat(core): Zero-Copy Logging — ZeroCopyLogger with string_view hot-path and pre-allocated thread-local buffer (v1.6.0) Mar 13, 2026
Copilot AI requested a review from makr-code March 13, 2026 08:43
@makr-code
makr-code marked this pull request as ready for review March 13, 2026 09:04
Copilot AI changed the title feat(core): Zero-Copy Logging — ZeroCopyLogger with string_view hot-path and pre-allocated thread-local buffer (v1.6.0) feat(core): Zero-Copy Logging — ZeroCopyLogger with string_view hot-path and pre-allocated thread-local buffer (v1.6.0, Issue #65) Mar 13, 2026
@makr-code
makr-code merged commit 7d54bae into develop Mar 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zero-Copy Logging

2 participants