Skip to content

perf(server): right-size deadline snapshot rentals - #257

Merged
SunSi12138 merged 21 commits into
devfrom
agent/issue-246-deadline-snapshot-sizing
Aug 20, 2026
Merged

SunSi12138 merged 21 commits into
devfrom
agent/issue-246-deadline-snapshot-sizing

Conversation

@SunSi12138

@SunSi12138 SunSi12138 commented Aug 20, 2026 •

Copy link
Copy Markdown
Owner

Fixes #246.

Summary

  • make StripedLongMap occupancy tracking opt-in so non-deadline users such as StreamManager do not pay shared atomic count writes
  • add a non-throwing bounded TryCopyEntries path for snapshot sizing races
  • size server deadline snapshots from observed active calls plus small headroom
  • grow geometrically with a hard retry bound and _maxCalls ceiling
  • clear only lease slots actually written before returning pooled arrays
  • add deterministic fake-time/race/failure coverage, including dispose-vs-scan, cleanup exception/re-arm, and 100k scan pool-reuse verification for lease use-count leaks

Baseline

Implemented and measured against dev@84e5152b00edce43fdf8280af6237fb4ead42839.

GitHub-hosted base/head performance evidence

Evidence run: https://github.com/SunSi12138/SharpLink/actions/runs/32389187846
Artifact: issue246-perf-evidence (artifact id 9414197210, retained 14 days).

Method: one GitHub-hosted Ubuntu 24.04 VM (AMD EPYC 7763, .NET SDK 10.0.400), base/head built in the same job, measurements pinned to the same logical CPU, five alternating ABBA repetitions. CPU/lateness numbers are comparative hosted-runner evidence rather than bare-metal absolute guarantees.

Scenario Snapshot bytes base → head Scan ns/op base → head Deadline lateness p95 base → head
max=1024 active=8 24,576 → 384 (-98.44%) 4,356.69 → 3,625.43 (-16.78%) 23,471 → 20,024 ns (-14.69%)
max=65536 active=8 1,572,864 → 384 (-99.98%) 44,625.08 → 3,602.63 (-91.93%) 109,721 → 20,989 ns (-80.87%)
max=65536 active=128, clustered 1,572,864 → 6,144 (-99.61%) 63,592.95 → 26,769.95 (-57.90%) 201,594 → 57,494 ns (-71.48%)
max=65536 active=1024 1,572,864 → 49,152 (-96.88%) 212,755.33 → 180,580.82 (-15.12%) 617,901 → 277,447 ns (-55.10%)
max=65536 active=0 1,572,864 → 0 (-100%) 44,038.41 → 38.13 (-99.91%) n/a

Registration/completion map hot-path probe: Set+TryRemove median 51.22 ns/op base → 49.26 ns/op head (-3.82%), with 0.00 managed B/op on both. The head count is opt-in to the server deadline-call map; non-deadline StripedLongMap users do not enable it.

Working-set measurements on the hosted VM were noisier than the deterministic sizing metrics. Peak working set was +0.69% for the default 1024/8 case and 2.9–7.4% lower for the measured max=65536 active cases; no high-max regression signal was observed.

The measured head was cf6ae532779ab18af5e703145c852269f879579e; after collecting the artifact, all temporary benchmark workflows were deleted. The final PR diff contains only the two implementation files and two deadline scheduler test files, so the measured production implementation is unchanged.

Validation

Final cleaned head: 83508bf737a78b2457273c4a254e60dd42446a6c.

  • PR Quick #666: success — formatting, Debug/Release build, Unit Tests, Generator Tests, Load Test Tests, Integration Tests, NativeAOT transport/topology smoke, packaging checks, package smoke, demo, Load Smoke, and Chaos Smoke all passed.
  • CodeQL #721: success.
  • Temporary performance workflow run 32389187846: success; artifact uploaded before all temporary workflow files were removed.
  • Final PR diff contains only:
    • src/SharpLink.Runtime/StripedLongMap.cs
    • src/SharpLink.Server/ServerCallDeadlineScheduler.cs
    • test/SharpLink.UnitTests/Server/ServerCallDeadlineSchedulerFailureTests.cs
    • test/SharpLink.UnitTests/Server/ServerCallDeadlineSchedulerSizingTests.cs

@SunSi12138 SunSi12138 left a comment

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.

Codex review: the lease/retry correctness looks sound on review and PR Quick is green. Remaining concerns are inline; I would keep this draft until the performance evidence and failure-path coverage are addressed.

Comment thread src/SharpLink.Runtime/StripedLongMap.cs Outdated
Comment thread src/SharpLink.Server/ServerCallDeadlineScheduler.cs

@SunSi12138 SunSi12138 left a comment

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.

Second pass: the opt-in count change addresses the shared-counter concern, and the new failure-path tests cover dispose/re-arm behavior. The performance-evidence P1 remains open; one additional test gap is inline.

@SunSi12138 SunSi12138 left a comment

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.

Codex review follow-up: no additional findings on the latest head. Rechecked the opt-in count tracking, bounded snapshot retry/cleanup paths, the strengthened 100k pool-reuse lease test, and the performance evidence. The current dev tip has advanced since the original baseline, but the PR merge commit is generated against current dev and PR Quick #666 / CodeQL #721 are green; the intervening runtime/build changes do not touch these scheduler/map implementation files.

@SunSi12138
SunSi12138 marked this pull request as ready for review August 20, 2026 16:30
@SunSi12138
SunSi12138 force-pushed the agent/issue-246-deadline-snapshot-sizing branch from d175f94 to 83508bf Compare August 20, 2026 16:32
@SunSi12138 SunSi12138 closed this Aug 20, 2026
@SunSi12138 SunSi12138 reopened this Aug 20, 2026
@SunSi12138
SunSi12138 merged commit 5c6b8ae into dev Aug 20, 2026
3 checks passed
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.

1 participant