Skip to content

Conversation

martincostello
Copy link
Member

  • Avoid LINQ to create components.
  • Do not recreate Outcome<T> for chaos.
  • Avoid predicate allocation.
  • Use ArgumentNullException.ThrowIfNull() where possible.
  • Add throw helper for ObjectDisposedException.
  • Remove unused Stopwatch.
  • Use Volatile.Read instead of Interlocked.CompareExchange().

Cherry-picked from #2664.

- Avoid LINQ to create components.
- Do not recreate `Outcome<T>` for chaos.
- Avoid predicate allocation.
- Use `ArgumentNullException.ThrowIfNull()` where possible.
- Add throw helper for `ObjectDisposedException`.
- Remove unused `Stopwatch`.
- Use `Volatile.Read` instead of `Interlocked.CompareExchange()`.

Cherry-picked from #2664.

Co-Authored-By: Pent Ploompuu <kaalikas@gmail.com>
Copy link

codecov bot commented Jul 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.23%. Comparing base (0459a8b) to head (c278bb8).
Report is 7 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2667      +/-   ##
==========================================
- Coverage   96.23%   96.23%   -0.01%     
==========================================
  Files         311      311              
  Lines        7329     7322       -7     
  Branches     1013     1012       -1     
==========================================
- Hits         7053     7046       -7     
  Misses        222      222              
  Partials       54       54              
Flag Coverage Δ
linux 96.23% <100.00%> (-0.01%) ⬇️
macos 96.23% <100.00%> (-0.01%) ⬇️
windows 96.22% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Update the benchmarks for latest run.
@martincostello
Copy link
Member Author

Ran benchmarks on main and then compared to the results pushed into this PR.

Almost all benchmarks had improvements, though not necessarily large. Some benchmarks that didn't show an improvement were within the margin of error for measurement noise.

@martincostello martincostello marked this pull request as ready for review July 8, 2025 14:24
@Copilot Copilot AI review requested due to automatic review settings July 8, 2025 14:24
@martincostello martincostello added this to the 8.6.2 milestone Jul 8, 2025
Copy link

@Copilot 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

This PR applies a series of low-level performance optimizations across the pipeline utilities, reducing allocations and improving synchronization checks.

  • Swaps Interlocked.CompareExchange for Volatile.Read to check pending executions.
  • Introduces a throw helper for ObjectDisposedException and uses ArgumentNullException.ThrowIfNull() when available.
  • Replaces LINQ allocation patterns and streamlines default predicate instantiation.

Reviewed Changes

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

Show a summary per file
File Description
ExecutionTrackingComponent.cs Uses Volatile.Read instead of Interlocked.CompareExchange
ComponentDisposeHelper.cs Extracts throw logic into a dedicated helper method
Guard.cs Calls ArgumentNullException.ThrowIfNull() under .NET 8+
DefaultPredicates.cs Replaces switch-expression allocation with direct ValueTask
ResiliencePipelineBuilderBase.cs Uses List<T>.ConvertAll instead of LINQ Select().ToList()
Comments suppressed due to low confidence (1)

src/Polly.Core/Utils/Guard.cs:12

  • Add or update unit tests to cover the ArgumentNullException.ThrowIfNull path under .NET 8+ to ensure the guard behaves as expected.
#if NET8_0_OR_GREATER

@martincostello martincostello enabled auto-merge (rebase) July 8, 2025 14:25
@martincostello martincostello merged commit a75929c into main Jul 8, 2025
26 checks passed
@martincostello martincostello deleted the perf-tweaks branch July 8, 2025 14:25
peggy-quartech pushed a commit to bcgov/PSSG-SPDBT that referenced this pull request Sep 4, 2025
Updated [Polly](https://github.com/App-vNext/Polly) from 8.5.2 to 8.6.3.

<details>
<summary>Release notes</summary>

_Sourced from [Polly's
releases](https://github.com/App-vNext/Polly/releases)._

## 8.6.3

## What's Changed

* Add release notes configuration by @​martincostello in
App-vNext/Polly#2678
* Simplify release workflow by @​martincostello in
App-vNext/Polly#2679
* Sign-off commits by @​martincostello in
App-vNext/Polly#2694
* Add GitHub sponsorship by @​martincostello in
App-vNext/Polly#2695
* Refactor project dependencies by @​martincostello in
App-vNext/Polly#2696
* Add zizmor by @​martincostello in
App-vNext/Polly#2698
* Update benchmarks by @​martincostello in
App-vNext/Polly#2712
* Reduce async overhead by @​pentp in
App-vNext/Polly#2664
* Update benchmarks by @​martincostello in
App-vNext/Polly#2713

## New Contributors

* @​pentp made their first contribution in
App-vNext/Polly#2664

**Full Changelog**:
App-vNext/Polly@8.6.2...8.6.3


## 8.6.2

## What's Changed

* Performance tweaks by @​martincostello in
App-vNext/Polly#2667
* Update dependencies by @​martincostello in
App-vNext/Polly#2668
* Update benchmark results by @​martincostello in
App-vNext/Polly#2669

## New Contributors

* @​pentp made their first contribution in
App-vNext/Polly#2667

**Full Changelog**:
App-vNext/Polly@8.6.1...8.6.2


## 8.6.1

## What's Changed

* Fix integer overflow in `BulkheadSemaphoreFactory` by @​ahusseini in
App-vNext/Polly#2638
* Generate SBOM by @​martincostello in
App-vNext/Polly#2640
* Attest artifacts by @​martincostello in
App-vNext/Polly#2647

## New Contributors

* @​ahusseini made their first contribution in
App-vNext/Polly#2638

**Full Changelog**:
App-vNext/Polly@8.6.0...8.6.1

Commits viewable in [compare
view](App-vNext/Polly@8.5.2...8.6.3).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Polly&package-manager=nuget&previous-version=8.5.2&new-version=8.6.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant