Skip to content

log_event_encoder: add direct-emit path for FLUENT_BIT_V2 format#11431

Open
edsiper wants to merge 1 commit intomasterfrom
log-event-encoder-perf-improvement
Open

log_event_encoder: add direct-emit path for FLUENT_BIT_V2 format#11431
edsiper wants to merge 1 commit intomasterfrom
log-event-encoder-perf-improvement

Conversation

@edsiper
Copy link
Member

@edsiper edsiper commented Feb 4, 2026

For FLUENT_BIT_V2 log format, emit_record can append the record as raw msgpack array bytes [ [timestamp, metadata], body ] directly to the main buffer instead of building it in the root buffer and then copying it. This avoids root buffer construction and one full-record copy per committed log record.

The record is emitted without a msgpack string wrapper so the on-wire format matches the existing path and decoders that expect a root array continue to work.

Estimated gain is on the order of 1–3% in the encoder hot path per record;


Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • Performance
    • Improved log encoding for Fluent Bit v2 with a new direct-emit fast path that reduces intermediate buffering, yielding faster record processing and lower CPU/memory overhead while preserving the previous behavior as a fallback.

@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

Adds a direct-emit fast path in the log event encoder that, for FLUENT_BIT_V2 with metadata and body present, serializes and appends a compact MessagePack sequence [timestamp, metadata, body] directly into the main buffer; preserves the original root-buffer-based emission as a fallback.

Changes

Cohort / File(s) Summary
Log Event Encoder Optimization
src/flb_log_event_encoder.c
Introduces a FLUENT_BIT_V2 fast path in flb_log_event_encoder_emit_record that builds a small MsgPack sequence and writes it directly to the main buffer when timestamp, metadata, and body are present. Adds flb_byteswap.h and string.h includes, constructs fixed MsgPack header and network-order timestamp, handles serialization success/failure, and retains the previous root-buffer emission as fallback. Key areas: byte-order handling, direct buffer writes, MsgPack header construction, and conditional control-flow changes for the newer path.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 I nibble bytes and swap with care,

I pack the time, meta, body fair,
A shortcut leap into the main,
No extra copies—what a gain! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'log_event_encoder: add direct-emit path for FLUENT_BIT_V2 format' accurately and specifically describes the main change: adding a direct-emit optimization path for the FLUENT_BIT_V2 format in the log event encoder.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch log-event-encoder-perf-improvement

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ad9cfc44a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

For FLUENT_BIT_V2 log format, emit_record can append the record as raw
msgpack array bytes [ [timestamp, metadata], body ] directly to the main
buffer instead of building it in the root buffer and then copying it.
This avoids root buffer construction and one full-record copy per
committed log record.

The record is emitted without a msgpack string wrapper so the on-wire
format matches the existing path and decoders that expect a root array
continue to work.

Estimated gain is on the order of 1–3% in the encoder hot path per
record;

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant