[party] Short circuit expensive loop at the end of every party (#37004)

Before:
```
----------------------------------------------------------------------------------------------------
Benchmark                                                          Time             CPU   Iterations
----------------------------------------------------------------------------------------------------
grpc_core::BM_UnaryWithSpawnPerEnd<CallSpineFixture>            1171 ns         1171 ns      2373821
grpc_core::BM_UnaryWithSpawnPerOp<CallSpineFixture>             1326 ns         1326 ns      2124026
grpc_core::BM_ClientToServerStreaming<CallSpineFixture>          256 ns          256 ns     10512990
grpc_core::BM_UnaryWithSpawnPerEnd<ForwardCallFixture>          2957 ns         2957 ns       949121
grpc_core::BM_UnaryWithSpawnPerOp<ForwardCallFixture>           3172 ns         3172 ns       882463
grpc_core::BM_ClientToServerStreaming<ForwardCallFixture>        500 ns          500 ns      5765914
```

After:
```
----------------------------------------------------------------------------------------------------
Benchmark                                                          Time             CPU   Iterations
----------------------------------------------------------------------------------------------------
grpc_core::BM_UnaryWithSpawnPerEnd<CallSpineFixture>            1147 ns         1147 ns      2451909
grpc_core::BM_UnaryWithSpawnPerOp<CallSpineFixture>             1325 ns         1325 ns      2107818
grpc_core::BM_ClientToServerStreaming<CallSpineFixture>          256 ns          256 ns     10896638
grpc_core::BM_UnaryWithSpawnPerEnd<ForwardCallFixture>          2876 ns         2876 ns       954360
grpc_core::BM_UnaryWithSpawnPerOp<ForwardCallFixture>           3148 ns         3148 ns       891892
grpc_core::BM_ClientToServerStreaming<ForwardCallFixture>        503 ns          503 ns      5518039
```

Closes #37004

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37004 from ctiller:cancel-fast 6b6b2b449c
PiperOrigin-RevId: 646138952
pull/37033/head
Craig Tiller 5 months ago committed by Copybara-Service
parent 14ab9e790e
commit a34b8b9ef3
  1. 1
      src/core/lib/promise/party.cc
  2. 4
      src/core/lib/promise/party.h

@ -178,6 +178,7 @@ Party::Participant::~Participant() {
Party::~Party() {} Party::~Party() {}
void Party::CancelRemainingParticipants() { void Party::CancelRemainingParticipants() {
if (!sync_.has_participants()) return;
ScopedActivity activity(this); ScopedActivity activity(this);
for (size_t i = 0; i < party_detail::kMaxParticipants; i++) { for (size_t i = 0; i < party_detail::kMaxParticipants; i++) {
if (auto* p = if (auto* p =

@ -224,6 +224,10 @@ class PartySyncUsingAtomics {
return iteration_.load(std::memory_order_relaxed); return iteration_.load(std::memory_order_relaxed);
} }
bool has_participants() const {
return (state_.load(std::memory_order_relaxed) & kAllocatedMask) != 0;
}
private: private:
bool UnreffedLast(); bool UnreffedLast();

Loading…
Cancel
Save