Skip to content

Conversation

cosmo0920
Copy link
Contributor

@cosmo0920 cosmo0920 commented Sep 8, 2025


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

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

  • Refactor
    • Optimized JSON string handling and float detection using CPU vectorization for significantly faster parsing on supported systems.
    • Retains identical behavior on systems without vectorization by automatically falling back to the original logic.
    • No configuration changes or public API updates required.

Copy link

coderabbitai bot commented Sep 8, 2025

Walkthrough

Introduces SIMD-assisted detection and fast paths in src/flb_pack.c: adds flb_simd.h, implements json_find_escapable_simd, short-circuits string unescape when safe, and adds a SIMD scan in is_float with scalar fallbacks. No public API changes. (≤50 words)

Changes

Cohort / File(s) Summary of changes
SIMD-assisted JSON packing & float parsing
src/flb_pack.c
Added #include <fluent-bit/flb_simd.h>; added json_find_escapable_simd (SIMD path guarded by FLB_HAVE_SIMD with scalar fallback); updated pack_string_token to fast-path direct pack when no escapables; extended is_float with a SIMD scan for ./e/E (optional sign) and scalar continuation; no public API changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant pack_string_token
  participant json_find_escapable_simd as json_find_escapable_simd
  participant Unescape as Unescape/Pack

  Caller->>pack_string_token: pack_string_token(str, len, ...)
  alt FLB_HAVE_SIMD enabled
    pack_string_token->>json_find_escapable_simd: scan for escapables
    alt No escapables found
      pack_string_token->>Caller: pack direct (no unescape)
    else Escapable found
      pack_string_token->>Unescape: unescape and pack
      Unescape-->>Caller: result
    end
  else No SIMD
    pack_string_token->>Unescape: scalar path (existing logic)
    Unescape-->>Caller: result
  end
Loading
sequenceDiagram
  autonumber
  participant Caller
  participant is_float

  Caller->>is_float: is_float(p, end)
  alt FLB_HAVE_SIMD enabled
    is_float->>is_float: SIMD scan for '.' / 'e' / 'E' (+/-)
    note right of is_float: On match jump to scalar verification
  end
  is_float->>is_float: Scalar verification (tail / edge cases)
  is_float-->>Caller: boolean result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • edsiper
  • koleini
  • fujimotos

Poem

I hop through bytes with vector feet,
sniffing dots and exponents neat.
If no escapes in sight appear,
I pack the string with joyful cheer.
SIMD breeze, scalar hug—rabbit complete. 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7d579b and a87b53a.

📒 Files selected for processing (1)
  • src/flb_pack.c (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/flb_pack.c
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-centos-7
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
  • GitHub Check: PR - fuzzing test
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cosmo0920-implement-simd-fast-paths-for-packing-msgpack

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.

Signed-off-by: Hiroshi Hatake <[email protected]>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/flb_pack.c (1)

287-289: Minor: widen buf_size type on assignment

state->buf_size appears to be size_t; assigning int s is fine on typical platforms but consider making s size_t to avoid narrowing on large inputs.

-    int s;
+    size_t s;
@@
-        s = len + 1;
+        s = (size_t)len + 1;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 070e761 and a7d579b.

📒 Files selected for processing (1)
  • src/flb_pack.c (4 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-08-29T06:25:02.561Z
Learnt from: shadowshot-x
PR: fluent/fluent-bit#10794
File: tests/internal/aws_compress.c:7-7
Timestamp: 2025-08-29T06:25:02.561Z
Learning: In Fluent Bit, ZSTD (zstandard) compression library is bundled directly in the source tree at `lib/zstd-1.5.7` and is built unconditionally as a static library. Unlike optional external dependencies, ZSTD does not use conditional compilation guards like `FLB_HAVE_ZSTD` and is always available. Headers like `<fluent-bit/flb_zstd.h>` can be included directly without guards.

Applied to files:

  • src/flb_pack.c
📚 Learning: 2025-08-29T06:25:27.250Z
Learnt from: shadowshot-x
PR: fluent/fluent-bit#10794
File: tests/internal/aws_compress.c:93-107
Timestamp: 2025-08-29T06:25:27.250Z
Learning: In Fluent Bit, ZSTD compression is enabled by default and is treated as a core dependency, not requiring conditional compilation guards like `#ifdef FLB_HAVE_ZSTD`. Unlike some other optional components such as ARROW/PARQUET (which use `#ifdef FLB_HAVE_ARROW` guards), ZSTD support is always available and doesn't need build-time conditionals. ZSTD headers are included directly without guards across multiple plugins and core components.

Applied to files:

  • src/flb_pack.c
📚 Learning: 2025-08-31T12:46:11.940Z
Learnt from: ThomasDevoogdt
PR: fluent/fluent-bit#9277
File: .github/workflows/pr-compile-check.yaml:147-151
Timestamp: 2025-08-31T12:46:11.940Z
Learning: In fluent-bit CMakeLists.txt, the system library preference flags are defined as FLB_PREFER_SYSTEM_LIB_ZSTD and FLB_PREFER_SYSTEM_LIB_KAFKA with the FLB_ prefix.

Applied to files:

  • src/flb_pack.c
🧬 Code graph analysis (1)
src/flb_pack.c (2)
include/fluent-bit/flb_simd.h (4)
  • flb_vector8_broadcast (228-239)
  • flb_vector8_load (140-151)
  • flb_vector8_is_highbit_set (244-257)
  • flb_vector8_eq (194-206)
src/flb_unescape.c (1)
  • flb_unescape_string_utf8 (186-277)
🔇 Additional comments (3)
src/flb_pack.c (3)

32-32: Header include looks fine

Unconditional include is OK since flb_simd.h provides non-SIMD fallbacks; no guard needed here.


270-279: Fast-path pack for strings is good, contingent on escapable finder correctness

Bypassing unescape when no '"' '' or control chars are present is a clear win. Once json_find_escapable_simd is fixed to catch control chars inside blocks, this path is safe.

Please add a regression case: a long string containing a lone 0x1F byte in the middle should take the slow path and be unescaped; a purely ASCII string should take the fast path.


57-109: The above script will list every flb_vector8_… symbol so we can confirm if any compare/bitwise ops exist. Once we see the available helpers, I’ll finalize whether a fully SIMD-based control‐char test is feasible or if the minimal scalar‐in‐block fix is the correct recommendation.

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