Skip to content

Alternative concurrent counter - #819

Open
bitfaster wants to merge 9 commits into
mainfrom
users/alexpeck/counterplus
Open

Alternative concurrent counter#819
bitfaster wants to merge 9 commits into
mainfrom
users/alexpeck/counterplus

Conversation

@bitfaster

@bitfaster bitfaster commented Aug 26, 2026

Copy link
Copy Markdown
Owner

Address feedback from .NET team.

Benchmark taken from https://github.com/dotnet/runtime/pull/91566

New counter vs striped is marginally slower in these tests, although likely noise:

BitFaster Caching Benchmarks CounterBenchmark-net9 0-columnchart
BenchmarkDotNet v0.15.8, Windows 11 (10.0.26200.9106/25H2/2025Update/HudsonValley2)
Intel Xeon W-2133 CPU 3.60GHz, 1 CPU, 12 logical and 6 physical cores
.NET SDK 10.0.400
  [Host] : .NET 10.0.11 (10.0.11, 10.0.1126.37416), X64 RyuJIT x86-64-v4
  net9.0 : .NET 9.0.19 (9.0.19, 9.0.1926.36724), X64 RyuJIT x86-64-v4

Job=net9.0  Runtime=.NET 9.0

| Method                   | Mean      | Error     | StdDev    |
|------------------------- |----------:|----------:|----------:|
| CounterSerial            | 20.179 ms | 0.2076 ms | 0.1942 ms |
| CounterParallel          |  2.189 ms | 0.0335 ms | 0.0297 ms |
| Striped64CounterSerial   | 19.944 ms | 0.0514 ms | 0.0481 ms |
| Striped64CounterParallel |  2.195 ms | 0.0278 ms | 0.0247 ms |
| MetricsCounterSerial     | 65.934 ms | 0.8149 ms | 0.6805 ms |
| MetricsCounterParallel   | 52.809 ms | 0.4452 ms | 0.4164 ms |
| UpDownCounterSerial      | 67.020 ms | 1.0584 ms | 0.9383 ms |
| UpDownCounterParallel    | 42.196 ms | 0.8298 ms | 1.0191 ms |

Comment thread BitFaster.Caching/Counters/Counter.cs Outdated
Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
Comment thread BitFaster.Caching/Counters/Counter.cs Outdated
Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
@coveralls

coveralls commented Aug 26, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 99.228% (+0.02%) from 99.212% — users/alexpeck/counterplus into main

/// <param name="value">The value to add.</param>
public void Add(long value)
{
Cell[]? @as;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@copilot remove all the nullable ? annotations to fix the warnings in this file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Done in 199da0e - removed the ? annotations, which fixes the CS8632 warnings since nullable context isn't enabled in this project.

Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
@bitfaster bitfaster changed the title Implement a good counter Alternative concurrent counter Aug 26, 2026
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