Skip to content

perf: store property statistics as values - #1267

Merged
vbreuss merged 1 commit into
mainfrom
perf/property-statistics-as-structs
Nov 29, 2026
Merged

vbreuss merged 1 commit into
mainfrom
perf/property-statistics-as-structs

Conversation

@vbreuss

@vbreuss vbreuss commented Nov 29, 2026

Copy link
Copy Markdown
Member

Every property access of a file system info registers a PropertyStatistic in the statistics of the mock, and the statistics keep all of them for the lifetime of the mock. In a test that reuses one mock for many calls, these objects survive garbage collections and make each collection more expensive.

The accesses are now stored as a small struct (counter, name, access) in the queue, and the PropertyStatistic objects are only created when Properties is read. The public API and the content and order of Properties are unchanged; only reading Properties twice now returns different instances with the same values.

Benchmark on Linux (min of two runs against main, same filter):

  • Inspect (FileInfo.New plus Exists, Length, LastWriteTimeUtc, Name, DirectoryName): 2.0 us -> 1.5 us (-27%), allocations 1,800 B -> 1,704 B (-5%)
  • Complete: within noise

Every property access of a file system info registers a `PropertyStatistic` in the statistics of the mock, and the statistics keep all of them for the lifetime of the mock. In a test that reuses one mock for many calls, these objects survive garbage collections and make each collection more expensive.

The accesses are now stored as a small struct (counter, name, access) in the queue, and the `PropertyStatistic` objects are only created when `Properties` is read. The public API and the content and order of `Properties` are unchanged; only reading `Properties` twice now returns different instances with the same values.

Benchmark on Linux (min of two runs against `main`, same filter):
- Inspect (`FileInfo.New` plus `Exists`, `Length`, `LastWriteTimeUtc`, `Name`, `DirectoryName`): 2.0 us -> 1.5 us (-27%), allocations 1,800 B -> 1,704 B (-5%)
- Complete: within noise
@vbreuss vbreuss self-assigned this Nov 29, 2026
@mergify

mergify Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

This pull request is merged.

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Stores property accesses as small, immutable values instead of keeping a PropertyStatistic object for every access.

  • Mock property statistics create objects only when callers read them.

Returning different instances across reads is intentional, as stated in the PR description supplied for author vbreuss.

No actionable issues were found. Build and tests were not run.

Reviews (1) · Last reviewed commit: "perf: store property statistics as value..." · Reviewed by Greptile

@vbreuss
vbreuss enabled auto-merge (squash) November 29, 2026 14:17
@sonarqubecloud

Copy link
Copy Markdown

@vbreuss
vbreuss merged commit 5f68db4 into main Nov 29, 2026
26 checks passed
@vbreuss
vbreuss deleted the perf/property-statistics-as-structs branch November 29, 2026 15:52
@github-actions

Copy link
Copy Markdown

🚀 Benchmark Results

Compared to main, which ran on the same runner. Times that change by more than 10% are marked.

Memory

Benchmark main PR Δ
Initialize (N=100) 410,689 B 419,929 B 🔴 +9,240 B (+2%)
RoundTrip (Size=1024) 4,713 B 4,825 B 🔴 +112 B (+2%)
RoundTrip (Size=65536) 198,443 B 198,428 B 🟢 -15 B (±0%)
Inspect 1,800 B 1,704 B 🟢 -96 B (-5%)

Time

Benchmark main PR Δ
Inspect 2.12 μs 1.62 μs 🟢 -24%
Chunks 47.34 μs 52.26 μs 🔴 +10%
CompleteTestBenchmarks
Complete Mean Error StdDev Ratio Allocated Alloc Ratio
Testably 21.60 μs 0.241 μs 0.225 μs 1.00 46.13 KB 1.00
SystemIOAbstractions 73.04 μs 0.998 μs 0.933 μs 3.38 166.7 KB 3.61
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V74 3.66GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4

Job=InProcess  Toolchain=InProcessEmitToolchain  IterationCount=15  
LaunchCount=1  WarmupCount=10  

InitializationBenchmarks
Initialize N Mean Error StdDev Ratio Allocated Alloc Ratio
Testably 10 26.04 μs 0.111 μs 0.099 μs 1.00 50.03 KB 1.00
SystemIOAbstractions 10 20.96 μs 0.108 μs 0.090 μs 0.80 48.59 KB 0.97
Testably 100 232.16 μs 1.423 μs 1.261 μs 1.00 410.09 KB 1.00
SystemIOAbstractions 100 164.03 μs 0.784 μs 0.654 μs 0.71 392.78 KB 0.96
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V74 3.65GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4

Job=InProcess  Toolchain=InProcessEmitToolchain  IterationCount=15  
LaunchCount=1  WarmupCount=10  

MockCreationBenchmarks
CreateMock Mean Error StdDev Ratio Allocated Alloc Ratio
Testably 1.240 μs 0.0519 μs 0.0486 μs 1.00 6 KB 1.00
SystemIOAbstractions 3.663 μs 0.0490 μs 0.0459 μs 2.96 8.15 KB 1.36
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
Intel Xeon 6975P-C 3.71GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4

Job=InProcess  Toolchain=InProcessEmitToolchain  IterationCount=15  
LaunchCount=1  WarmupCount=10  

FileRoundTripBenchmarks
RoundTrip Size Mean Error StdDev Median Ratio Allocated Alloc Ratio
Testably 1024 8.416 μs 4.571 μs 4.2760 μs 6.107 μs 1.23 4.71 KB 1.00
SystemIOAbstractions 1024 8.537 μs 1.996 μs 1.8671 μs 9.199 μs 1.25 16.54 KB 3.51
Testably 65536 115.647 μs 1.064 μs 0.9949 μs 115.733 μs 1.00 193.78 KB 1.00
SystemIOAbstractions 65536 71.204 μs 1.007 μs 0.9423 μs 71.252 μs 0.62 408.49 KB 2.11
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 3.06GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v3

Job=InProcess  Toolchain=InProcessEmitToolchain  InvocationCount=4096  
IterationCount=15  LaunchCount=1  UnrollFactor=1  
WarmupCount=10  

FileInfoBenchmarks
Inspect Mean Error StdDev Ratio Allocated Alloc Ratio
Testably 1.622 μs 0.0913 μs 0.0809 μs 1.00 1.66 KB 1.00
SystemIOAbstractions 1.343 μs 0.0262 μs 0.0232 μs 0.83 2.55 KB 1.54
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4

Job=InProcess  Toolchain=InProcessEmitToolchain  InvocationCount=65536  
IterationCount=15  LaunchCount=1  UnrollFactor=1  
WarmupCount=10  

FileStreamBenchmarks
Chunks Mean Error StdDev Ratio Allocated Alloc Ratio
Testably 52.26 μs 6.077 μs 5.684 μs 1.01 201.67 KB 1.00
SystemIOAbstractions 80.76 μs 0.817 μs 0.764 μs 1.56 326.67 KB 1.62
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
Intel Xeon 6975P-C 2.70GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4

Job=InProcess  Toolchain=InProcessEmitToolchain  InvocationCount=2048  
IterationCount=15  LaunchCount=1  UnrollFactor=1  
WarmupCount=10  

DirectoryTreeBenchmarks
MoveTree Mean Error StdDev Ratio Allocated Alloc Ratio
Testably 285.56 μs 15.236 μs 13.506 μs 1.00 136.07 KB 1.00
SystemIOAbstractions 63.41 μs 2.038 μs 1.702 μs 0.22 106.62 KB 0.78
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 3.23GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v3

Job=InProcess  Toolchain=InProcessEmitToolchain  InvocationCount=512  
IterationCount=15  LaunchCount=1  UnrollFactor=1  
WarmupCount=10  

Enumeration10Benchmarks
Enumerate N Pattern Mean Error StdDev Ratio Allocated Alloc Ratio
Testably 10 ***** 5.516 μs 0.3056 μs 0.2386 μs 1.00 4.86 KB 1.00
SystemIOAbstractions 10 * 5.977 μs 0.0553 μs 0.0431 μs 1.09 3.93 KB 0.81
Testably 10 *.txt 5.714 μs 0.0617 μs 0.0547 μs 1.00 4.55 KB 1.00
SystemIOAbstractions 10 *.txt 9.619 μs 0.0879 μs 0.0779 μs 1.68 4.24 KB 0.93
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 2.65GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v3

Job=InProcess  Toolchain=InProcessEmitToolchain  InvocationCount=16384  
IterationCount=15  LaunchCount=1  UnrollFactor=1  
WarmupCount=10  

Enumeration1000Benchmarks
Enumerate N Pattern Mean Error StdDev Ratio Allocated Alloc Ratio
Testably 1000 ***** 490.8 μs 3.78 μs 3.53 μs 1.00 308.18 KB 1.00
SystemIOAbstractions 1000 * 170.9 μs 5.55 μs 5.19 μs 0.35 70.42 KB 0.23
Testably 1000 *.txt 497.3 μs 2.53 μs 2.25 μs 1.00 273.42 KB 1.00
SystemIOAbstractions 1000 *.txt 328.6 μs 7.85 μs 6.56 μs 0.66 66.87 KB 0.24
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V45 4.25GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4

Job=InProcess  Toolchain=InProcessEmitToolchain  InvocationCount=512  
IterationCount=15  LaunchCount=1  UnrollFactor=1  
WarmupCount=10  

github-actions Bot added a commit that referenced this pull request Nov 29, 2026
github-actions Bot added a commit that referenced this pull request Nov 29, 2026
@github-actions

Copy link
Copy Markdown

This is addressed in release v8.1.2.

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