Skip to content

perf(elem): cut copies and allocations from MRT update to elems - #348

Merged
digizeph merged 1 commit into
bgpkit:mainfrom
ties:perf/elem-allocations
Oct 6, 2026
Merged

digizeph merged 1 commit into
bgpkit:mainfrom
ties:perf/elem-allocations

Conversation

@ties

@ties ties commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

A performance improvement. The change in performance varies a bit between an Intel i7 14700 machine and a M2 MacBook Pro.

Summary of the change. These numbers are not from a fully idle machine, so I do not think the regressions are real. Would be good to re-run cargo bench though.

┌────────────────────────────────────────┬──────────┬──────────┬──────────────────────┐
│               Benchmark                │  Before  │  After   │        Change        │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ updates elementor record_to_elems_iter │ 1.421 ms │ 1.126 ms │ −20.5%               │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ updates into_elem_iter                 │ 3.947 ms │ 3.371 ms │ −14.9%               │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ rib into_elem_iter                     │ 52.86 ms │ 45.61 ms │ −13.7%               │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ rib into_record_iter                   │ 66.32 ms │ 65.25 ms │ −1.6%                │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ rib into_update_iter                   │ 66.19 ms │ 65.43 ms │ −1.1% (within noise) │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ rib into_raw_record_iter               │ 8.034 ms │ 7.997 ms │ −0.5% (within noise) │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ updates into_record_iter               │ 2.259 ms │ 2.261 ms │ no change            │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ updates into_raw_record_iter           │ 353.0 µs │ 354.1 µs │ no change            │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ updates into_route_iter                │ 1.753 ms │ 1.792 ms │ no change            │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ updates into_update_iter               │ 2.194 ms │ 2.235 ms │ +1.3% (within noise) │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ rib into_route_iter                    │ 22.37 ms │ 23.13 ms │ +3.4% ⚠              │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ CLI, update-example.gz (bgpkit)        │ 36.71 ms │ 36.55 ms │ no change            │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ CLI, rib-example-small.bz2 (bgpkit)    │ 1.857 s  │ 1.937 s  │ +4.3% ⚠              │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ bgpdump, updates (control)             │ 17.82 ms │ 18.34 ms │ +2.9%                │
├────────────────────────────────────────┼──────────┼──────────┼──────────────────────┤
│ bgpdump, RIB (control)                 │ 1.176 s  │ 1.265 s  │ +7.5%                │
└────────────────────────────────────────┴──────────┴──────────┴──────────────────────┘
  • ElemIterator yields elems per record instead of collecting a Vec
  • the last announced elem takes the shared attributes instead of cloning them
  • attribute values are moved out in place, not copied by value
  • parse_attributes clones attribute bytes only when parsing fails

into_elem_iter: -24% on updates, -21% on RIB dumps. A new updates elementor record_to_elems_iter benchmark times record-to-elem conversion alone: -22%.

Assisted-by: Claude Code

- ElemIterator yields elems per record instead of collecting a Vec
- the last announced elem takes the shared attributes instead of
  cloning them
- attribute values are moved out in place, not copied by value
- parse_attributes clones attribute bytes only when parsing fails

into_elem_iter: -24% on updates, -21% on RIB dumps. A new
`updates elementor record_to_elems_iter` benchmark times record-to-elem
conversion alone: -22%.

Assisted-by: Claude Code
@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.04%. Comparing base (005ad93) to head (10be00c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #348      +/-   ##
==========================================
- Coverage   92.05%   92.04%   -0.02%     
==========================================
  Files          96       96              
  Lines       23396    23396              
==========================================
- Hits        21537    21534       -3     
- Misses       1859     1862       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

Static review supports preserved behavior and focused regression coverage, though tests and benchmarks were not executed.

Review effort: Balanced
Findings: None

What changed in this PR

Reduces copying and allocation overhead when converting MRT records into BGP elements, while preserving output behavior.

Changes:

  • Streams elements per record instead of collecting intermediate vectors.
  • Moves shared attributes where possible and avoids unnecessary byte clones.
  • Adds focused regression tests and a conversion-only benchmark.
File Description
src/​parser/​mrt/​mrt_elem.rs Adds pending-element iteration, ownership optimizations, and regression tests.
src/​parser/​iters/​default.rs Replaces cached element vectors with streaming iteration.
src/​parser/​bgp/​attributes/​mod.rs Avoids upfront byte clones while preserving malformed attributes.
CHANGELOG.md Documents reported conversion speedups.
benches/​internals.rs Adds an isolated record-to-element benchmark.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@digizeph
digizeph merged commit ec90671 into bgpkit:main Oct 6, 2026
9 checks passed
@ties
ties deleted the perf/elem-allocations branch October 6, 2026 21:26
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.

3 participants