Skip to content

refactor(sinktools): LazySinkSource cleanup waker handling, use StreamExt::split, improve unit tests, fix #2336#2556

Open
MingweiSamuel wants to merge 3 commits intomainfrom
lazy-1
Open

refactor(sinktools): LazySinkSource cleanup waker handling, use StreamExt::split, improve unit tests, fix #2336#2556
MingweiSamuel wants to merge 3 commits intomainfrom
lazy-1

Conversation

@MingweiSamuel
Copy link
Member

@MingweiSamuel MingweiSamuel commented Feb 6, 2026

Fix #2336

Copilot AI review requested due to automatic review settings February 6, 2026 23:02
@MingweiSamuel MingweiSamuel changed the title refactor(sinktools): LazySinkSource cleanup waker handling, improve unit tests refactor(sinktools): LazySinkSource cleanup waker handling, improve unit tests, fix #2336 Feb 6, 2026
@MingweiSamuel MingweiSamuel requested review from luckyworkama and removed request for Copilot February 6, 2026 23:02
@MingweiSamuel MingweiSamuel changed the title refactor(sinktools): LazySinkSource cleanup waker handling, improve unit tests, fix #2336 refactor(sinktools): LazySinkSource cleanup waker handling, use StreamExt::split, improve unit tests, fix #2336 Feb 6, 2026
Copilot AI review requested due to automatic review settings February 6, 2026 23:09
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 6, 2026

Deploying hydro with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7f8c10f
Status: ✅  Deploy successful!
Preview URL: https://5546180a.hydroflow.pages.dev
Branch Preview URL: https://lazy-1.hydroflow.pages.dev

View logs

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

Refactors sinktoolsLazySinkSource to simplify/optimize wakeup handling (addressing #2336) and modernize splitting by relying on StreamExt::split, alongside strengthening initialization-driving test coverage.

Changes:

  • Replace the old multi-waker approach with a 2-slot DualWaker based on futures_util::task::AtomicWaker.
  • Refactor LazySinkSource to hold state directly (removing Rc<RefCell<...>>) and remove the custom split-half types in favor of StreamExt::split.
  • Add/adjust unit tests for initialization behavior; update dev-deps to enable tokio::time.

Reviewed changes

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

File Description
sinktools/src/lazy_sink_source.rs Refactors internal state + wakeup handling; switches to StreamExt::split; expands unit tests.
sinktools/Cargo.toml Enables tokio’s time feature for dev-dependencies to support new tests.

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

Comment on lines +275 to 279
dual_waker.stream.register(cx.waker());
let waker = Waker::from(Arc::clone(dual_waker));

let mut new_context = Context::from_waker(&waker);

Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

Each poll clones the Arc<DualWaker> to build a new Waker (Waker::from(Arc::clone(...))). If this is on a hot path, consider using futures_util::task::waker_ref (or similar) to avoid the extra Arc refcount bump per poll.

Copilot uses AI. Check for mistakes.
Comment on lines 115 to 116
panic!("LazySinkHalf in invalid state.");
}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

This panic message still refers to LazySinkHalf, but the half types were removed and the trait impl is now on LazySinkSource. Update the panic text to match the current type to avoid confusing debugging output.

Copilot uses AI. Check for mistakes.
Comment on lines 144 to 145
panic!("LazySinkHalf not ready.");
}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

This panic message still refers to LazySinkHalf, but the half types were removed and the trait impl is now on LazySinkSource. Update the panic text to match the current type to avoid confusing debugging output.

Copilot uses AI. Check for mistakes.
Comment on lines 192 to 193
panic!("LazySinkHalf in invalid state.");
}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

This panic message still refers to LazySinkHalf, but the half types were removed and the trait impl is now on LazySinkSource. Update the panic text to match the current type to avoid confusing debugging output.

Copilot uses AI. Check for mistakes.
Comment on lines 240 to 241
panic!("LazySinkHalf in invalid state.");
}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

This panic message still refers to LazySinkHalf, but the half types were removed and the trait impl is now on LazySinkSource. Update the panic text to match the current type to avoid confusing debugging output.

Copilot uses AI. Check for mistakes.
.run_until(async {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();
println!("Listening on {}", addr);
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

Avoid println! in tests committed to the repo; it adds noise to CI logs. Prefer tracing (with test subscriber) or remove the output unless it’s needed for an assertion.

Suggested change
println!("Listening on {}", addr);

Copilot uses AI. Check for mistakes.
.run_until(async {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();
println!("Listening on {}", addr);
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

Avoid println! in tests committed to the repo; it adds noise to CI logs. Prefer tracing (with test subscriber) or remove the output unless it’s needed for an assertion.

Suggested change
println!("Listening on {}", addr);

Copilot uses AI. Check for mistakes.
Comment on lines +83 to 86
dual_waker.sink.register(cx.waker());
let waker = Waker::from(Arc::clone(dual_waker));

let mut new_context = Context::from_waker(&waker);
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

Each poll clones the Arc<DualWaker> to build a new Waker (Waker::from(Arc::clone(...))). If this is on a hot path, consider using futures_util::task::waker_ref (or similar) to avoid the extra Arc refcount bump per poll.

Copilot uses AI. Check for mistakes.
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.

refactor(sinktools): optimize lazy_sink_source MultiWaker, it only really needs to support 2 slots, maybe it can be lock free.

1 participant