Skip to content

feat: Add Push::size_hint, VecPush terminal operator, use in dfir codegen [ci-bench]#2678

Merged
MingweiSamuel merged 1 commit intomainfrom
mingwei/push-size
Mar 24, 2026
Merged

feat: Add Push::size_hint, VecPush terminal operator, use in dfir codegen [ci-bench]#2678
MingweiSamuel merged 1 commit intomainfrom
mingwei/push-size

Conversation

@MingweiSamuel
Copy link
Member

@MingweiSamuel MingweiSamuel commented Mar 23, 2026

Added size_hint(self: Pin<&mut Self>, hint: (usize, Option<usize>)) to the Push trait as the push-side analog of Pull::size_hint. This allows producers to announce how many items they're about to send, enabling downstream operators and sinks to pre-allocate.

New terminal operator:

  • VecPush<Buf>: pushes items into a Vec, uses size_hint to call Vec::reserve(hint.0) for pre-allocation. Gated on alloc feature.
  • Constructor: push::vec_push(buf) creates a VecPush from a &mut Vec<T>.

BREAKING CHANGE: Updates the Handoff trait to allow pushing to &mut Vec<T> directly instead of one-by-one, and allows pre-allocating.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 23, 2026

📊 Benchmark Results

✅ Benchmark completed! You can download the results from the links below.

Run History:

Last updated: 2026-03-24T18:48:16.229Z

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 23, 2026

Deploying hydro with  Cloudflare Pages  Cloudflare Pages

Latest commit: d7f7828
Status:⚡️  Build in progress...

View logs

@MingweiSamuel MingweiSamuel changed the title Add Push::size_hint and VecPush terminal operator [ci-bench] feat(dfir_lang): Add Push::size_hint and VecPush terminal operator [ci-bench] Mar 23, 2026
@MingweiSamuel MingweiSamuel changed the title feat(dfir_lang): Add Push::size_hint and VecPush terminal operator [ci-bench] feat: Add Push::size_hint, VecPush terminal operator, use in dfir codegen [ci-bench] Mar 23, 2026
@MingweiSamuel MingweiSamuel marked this pull request as ready for review March 23, 2026 21:06
Copilot AI review requested due to automatic review settings March 23, 2026 21:06
@MingweiSamuel
Copy link
Member Author

Shows some small performance improvements. A few performance decreases within noise.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds push-side size hints and a new Vec-collecting terminal push operator to enable downstream pre-allocation, and updates DFIR codegen/runtime plumbing to take advantage of the new bulk-push path.

Changes:

  • Add Push::size_hint and propagate it through push combinators/sinks, plus new alloc-gated VecPush/push::vec_push.
  • Update DFIR runtime Handoff / SendCtx APIs to expose a “borrow mutable inner for giving” path used by codegen.
  • Update macros/tests and various pulls to account for the new size-hint requirements and type changes.

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
dfir_rs/tests/compile-fail-stable/surface_demuxenum_wrongfields_2.stderr Update expected diagnostics due to new VecPush type appearing in trait impl lists.
dfir_rs/tests/compile-fail-stable/surface_demuxenum_wrongfields_1.stderr Same: refresh compile-fail expectations after push API expansion.
dfir_rs/tests/compile-fail-stable/surface_demuxenum_wrongenum.stderr Same: refresh stderr golden output for changed trait impl candidates.
dfir_rs/src/util/demux_enum.rs Extend DemuxEnumPush with a size_hint hook for derived demux pushes.
dfir_rs/src/scheduled/port.rs Add SendCtx::borrow_mut_give() to support bulk writes into handoffs.
dfir_rs/src/scheduled/handoff/vector.rs Implement borrow_mut_give for VecHandoff by borrowing the input buffer mutably.
dfir_rs/src/scheduled/handoff/tee.rs Add borrow_mut_give stub for TeeingHandoff (currently todo!()).
dfir_rs/src/scheduled/handoff/mod.rs Add borrow_mut_give requirement to the Handoff trait.
dfir_rs/src/compiled/push/demux_enum.rs Forward Push::size_hint into DemuxEnumPush::size_hint.
dfir_rs/src/compiled/pull/lattice_bimorphism.rs Implement required Pull::size_hint (returns (0, None) due to UDF dependence).
dfir_pipes/src/push/vec_push.rs New alloc-gated VecPush terminal operator collecting into Vec and reserving via size_hint.
dfir_pipes/src/push/unzip.rs Propagate size_hint to both downstream pushes.
dfir_pipes/src/push/test_utils.rs Record size_hint calls in TestPush history for testing/validation.
dfir_pipes/src/push/sink.rs Add no-op size_hint implementation for Sink.
dfir_pipes/src/push/resolve_futures.rs Forward size_hint downstream (1 future → 1 output).
dfir_pipes/src/push/persist.rs Reserve internal buffer and forward size_hint downstream.
dfir_pipes/src/push/mod.rs Add Push::size_hint; export alloc-gated VecPush + push::vec_push constructor.
dfir_pipes/src/push/map.rs Forward size_hint unchanged.
dfir_pipes/src/push/inspect.rs Forward size_hint unchanged.
dfir_pipes/src/push/for_each.rs Add no-op size_hint (terminal side-effecting push).
dfir_pipes/src/push/flatten.rs Conservative size_hint propagation (forces (0, None)).
dfir_pipes/src/push/flat_map.rs Conservative size_hint propagation (forces (0, None)).
dfir_pipes/src/push/filter_map.rs Adjust size_hint lower bound to 0 and forward upper bound.
dfir_pipes/src/push/filter.rs Adjust size_hint lower bound to 0 and forward upper bound.
dfir_pipes/src/push/fanout.rs Propagate size_hint to both downstream pushes.
dfir_pipes/src/push/demux_var.rs Add size_hint to variadic demux and propagate recursively.
dfir_pipes/src/pull/symmetric_hash_join.rs Refactor new-tick path to pull::iter and add size_hint impls returning (0, None) (TODO for estimates).
dfir_pipes/src/pull/poll_fn.rs Implement required Pull::size_hint (UDF-dependent, returns (0, None)).
dfir_pipes/src/pull/mod.rs Make Pull::size_hint required (remove default impl) to prevent accidental omission.
dfir_pipes/src/pull/from_fn.rs Implement required Pull::size_hint (UDF-dependent, returns (0, None)).
dfir_pipes/src/pull/cross_singleton.rs Implement size_hint with singleton-state-aware lower-bound adjustment.
dfir_macro/src/lib.rs Update demux enum derive output to use Pin::as_mut and generate size_hint plumbing.
dfir_lang/src/graph/meta_graph.rs Switch send-port codegen from per-item give(Some(v)) to borrowing the inner vec and using vec_push.

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

@MingweiSamuel
Copy link
Member Author

Looks good

Added `size_hint(self: Pin<&mut Self>, hint: (usize, Option<usize>))` to the
`Push` trait as the push-side analog of `Pull::size_hint`. This allows
producers to announce how many items they're about to send, enabling
downstream operators and sinks to pre-allocate.

Trait changes:
- `Push::size_hint`: default no-op implementation
- `&mut P` blanket impl: forwards to inner
- `PushVariadic::size_hint`: new required method

Propagation through combinators:
- Map, Inspect: pass through unchanged (1:1 mapping)
- Filter, FilterMap: lower bound set to 0, upper preserved
- FlatMap, Flatten: hint becomes (0, None) — output count unknown
- Fanout, Unzip: forward to both branches
- Persist: reserves on internal Vec buffer, then forwards
- DemuxVar: forwards to all downstream pushes via PushVariadic
- ForEach, SinkPush, ResolveFutures: use default no-op

New terminal operator:
- `VecPush<Buf>`: pushes items into a `Vec`, uses `size_hint` to call
  `Vec::reserve(hint.0)` for pre-allocation. Gated on `alloc` feature.
- Constructor: `push::vec_push(buf)` creates a VecPush from a `&mut Vec<T>`.


Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@MingweiSamuel MingweiSamuel enabled auto-merge (squash) March 24, 2026 18:29
@MingweiSamuel MingweiSamuel merged commit 52ed106 into main Mar 24, 2026
18 of 19 checks passed
@MingweiSamuel MingweiSamuel deleted the mingwei/push-size branch March 24, 2026 18:57
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