Skip to content

Feature/inline parse data fields - #285

Merged
mikemiles-dev merged 5 commits into
mainfrom
feature/inline-parse-data-fields
Mar 29, 2026
Merged

Feature/inline parse data fields#285
mikemiles-dev merged 5 commits into
mainfrom
feature/inline-parse-data-fields

Conversation

@mikemiles-dev

@mikemiles-dev mikemiles-dev commented Mar 29, 2026

Copy link
Copy Markdown
Owner
  • Inline V9 parse_data_fields into the record loop, eliminating per-record function call and Vec allocation overhead (~8-10% V9
    throughput improvement)
  • Replace nom's generic big-endian parsers with hand-rolled from_be_bytes intrinsics in a new fast_parse module. nom's be_uint uses a
    Shl+Add+From trait loop that LLVM fails to optimize into bswap/rev instructions at wider integer widths (u64, u128), resulting in
    byte-at-a-time loops. Micro-benchmarks show 9-26x speedup per parse call.
  • Apply fast parsers to DataNumber::parse, FieldValue IP/MAC parsing, and IPFIX variable-length field parsing
  • Add hot_path_bench criterion benchmark for V9/IPFIX data parsing
  • Comprehensive unit tests for all fast parse functions including i24 sign extension edge cases
  • Bump version to 1.0.2

Eliminates per-record function call overhead and Vec allocation in
the V9 field parser hot path. The inner field-parsing loop is now
inlined directly, giving the optimizer a single loop nest to work
with and allowing error recovery without unwinding through a
function boundary.

Benchmark results (V9 data parsing, 1000 flows):
  main:      130.04 µs  (146.85 MiB/s)
  optimized: 120.12 µs  (158.98 MiB/s)
  ~8% improvement

Also adds hot_path_bench for targeted V9/IPFIX data parsing benchmarks.
Extract hand-rolled from_be_bytes parsers into a dedicated fast_parse
module with comprehensive unit tests. nom's generic be_uint uses a
Shl+Add+From<u8> trait loop that LLVM does not optimize into bswap/rev
instructions at wider integer widths (u64, u128). Micro-benchmarks show
9-26x speedup for the from_be_bytes versions.

Replace nom number parsers in DataNumber::parse, FieldValue IP/MAC
parsing, and IPFIX variable-length field parsing. Update README with
new performance optimization notes.
Inlines the parse_data_fields helper directly into the record loop,
eliminating per-record function call overhead and Vec allocation.
This was accidentally reverted during baseline benchmarking.
@mikemiles-dev

Copy link
Copy Markdown
Owner Author

@bmjask based off findings from their PR

@mikemiles-dev mikemiles-dev self-assigned this Mar 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR focuses on improving NetFlow V9/IPFIX parsing throughput by removing avoidable per-record overhead and replacing nom’s generic big-endian number parsers with dedicated from_be_bytes-based implementations.

Changes:

  • Inline V9 data-field parsing into the record loop to reduce per-record call/allocation overhead.
  • Introduce variable_versions::fast_parse and use it for hot-path big-endian parsing (DataNumber, IP/MAC parsing, and IPFIX variable-length field lengths).
  • Add a new Criterion benchmark (hot_path_bench) and bump crate version to 1.0.2.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/variable_versions/v9/parser.rs Inlines record parsing logic and precomputes template field references/capacity for faster V9 data parsing.
src/variable_versions/mod.rs Adds the new internal fast_parse module.
src/variable_versions/ipfix/parser.rs Switches IPFIX variable-length field-length parsing to fast_parse helpers.
src/variable_versions/field_value.rs Uses fast_parse for DataNumber parsing and IP/MAC decoding paths.
src/variable_versions/fast_parse.rs New optimized big-endian primitive parsers with unit tests.
benches/hot_path_bench.rs Adds a hot-path benchmark for warmed V9/IPFIX data parsing.
README.md Documents the new fast parsers and V9 inlined parsing optimization.
Cargo.toml Bumps version and registers the new benchmark target.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mikemiles-dev
mikemiles-dev merged commit a1406fd into main Mar 29, 2026
16 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.

2 participants