Skip to content

perf(source_sender): share output state to make per-request clones cheaper - #26369

Open
thomasqueirozb wants to merge 3 commits into
masterfrom
source-sender-clone-optimization
Open

thomasqueirozb wants to merge 3 commits into
masterfrom
source-sender-clone-optimization

Conversation

@thomasqueirozb

@thomasqueirozb thomasqueirozb commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Summary

Sources clone their SourceSender per request. Previously each Output clone duplicated every metric handle and metadata reference separately. This moves that state behind a single shared Arc, making the clone a refcount bump.

Profiling evidence

Sampled the running Vector process (macOS sample, 30s, 1ms intervals) under a lading-driven http_server source with small request bodies (~86k req/s, noop remap):

  • Before: Output::clone accounted for 601/35,854 and 532/32,426 samples (~1.7% of process CPU) across two runs; SourceSender::clone (inclusive) for ~1.75%.
  • After: Output::clone dropped to 0 samples (eliminated - it is now an Arc refcount bump); SourceSender::clone (inclusive) fell to 279/32,345 and 304/31,798 samples (~0.9%).

Criterion bench (lib/vector-core/benches/source_sender/, new in this PR) A/B against baseline code:

  • SourceSender::clone: 34.7 ns -> 22.0 ns (-38%, p = 0.00)
  • clone + send_event (1 event): 764 ns -> 717 ns (-6.1%, p = 0.00)

End-to-end (lading, high request rate, noop remap, two A/B runs each):

  • Baseline: 91,023 req/s mean; optimized: 91,474 req/s mean (+0.5%)

The send path is a small slice of total pipeline CPU, so microbench gains translate to ~0.5% end-to-end; larger gains are expected for sources where the clone path dominates.

References

Related: #25628

Vector configuration

NA

How did you test this PR?

  • cargo bench -p vector-core --bench source_sender A/B against baseline code: clone 34.7 ns -> 22.0 ns (-38%), request cycle 764 ns -> 717 ns (-6.1%), both flagged "Performance has improved" by Criterion
  • cargo test -p vector-core source_sender (11 passed)
  • make check-clippy with sources-http_server,transforms-remap,sinks-http,vrl/stdlib features
  • make fmt
  • End-to-end lading benchmark (http_server source, high request rate): +0.5% mean requests/s across two A/B runs

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

Contributor Guidelines

  • Please read our Vector contributor resources.
  • Do not hesitate to use @vectordotdev/vector to reach out to us regarding this PR.
  • Before pushing, follow our pre-push guidance.
  • After a review is requested, please avoid force pushes to help us review incrementally.
    • Feel free to push as many commits as you want. They will be squashed into one before merging.
    • For example, you can run git merge origin master and git push.

@github-actions github-actions Bot added the domain: core Anything related to core crates i.e. vector-core, core-common, etc label Sep 14, 2026
@thomasqueirozb
thomasqueirozb force-pushed the source-sender-clone-optimization branch from 0b4ff3b to c80eb02 Compare September 14, 2026 14:24
@thomasqueirozb
thomasqueirozb marked this pull request as ready for review September 14, 2026 14:24
@thomasqueirozb
thomasqueirozb requested a review from a team as a code owner September 14, 2026 14:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: core Anything related to core crates i.e. vector-core, core-common, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant