Skip to content

refactor(core): return ValueTask from the greeting repository - #167

Merged
e128 merged 1 commit into
mainfrom
refactor/core-valuetask
Nov 15, 2026
Merged

e128 merged 1 commit into
mainfrom
refactor/core-valuetask

Conversation

@e128

@e128 e128 commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Executive Summary

The greeting repository returned Task from methods that never suspend. SaveAsync already returned the cached Task.CompletedTask, so it allocated nothing, but GetRecentAsync allocated a fresh Task<IReadOnlyList<Greeting>> on every read. Both methods now return ValueTask, so a save allocates nothing and a read allocates only its result array.

The same read path had lost its measured optimization. Commit 83f564a, a bulk analyzer refactor, replaced the backward list walk with a full OrderByDescending sort. The walk is restored. Recency follows save order, because GreetingService stamps CreatedAt at save time.

Code Changes

  • IGreetingRepository returns ValueTask and ValueTask<IReadOnlyList<Greeting>>.
  • InMemoryGreetingRepository implements both signatures and reads the newest entries by walking back from the list end under the existing lock.
  • FixedGreetingRepository and the CoreBenchmarks read benchmark follow the new signatures.
  • InMemoryGreetingRepositoryTests consumes each ValueTask once, which CA2012 enforces as an error in this repo.
  • lode/dotnet/performance.md records the ValueTask contract and drops a stale net10.0 clause from the runtime-async note.
  • The change set also carries the mr-sparkle precondition lines, three analyzer candidates captured from the 2026-11-14 sessions, and that run's review plan.

Tests and Tooling

scripts/check.sh --all passed: shell lint, format check, build, and 2990 tests with 0 failures and 2 pre-existing skips. scripts/internal/analyzer-release-check.sh and scripts/readme-table-diff.sh --analyzer report no drift.

The recorded throughput figures (1,655 req/s with the sort, 7,278 req/s without) were not re-measured in this run. They come from the commit that first introduced the walk.

Review Guide

Read InMemoryGreetingRepository.GetRecentAsync first: it holds the restored walk and the changed return type. Then check the four signature changes. The interface change is a public API change.

Rollback

Revert this commit. Nothing depends on the new signatures outside the solution.

Links

None.

🤖 Generated with Claude Code

The repository methods run against an in-memory list, so the Task wrapper
bought nothing. SaveAsync now allocates nothing and GetRecentAsync allocates
only its result array. CA2012 enforces the single consumption.

Restore the backward read walk that 83f564a dropped. A full sort on the read
path costs the stored count per call: the recorded harness ran 1,655 req/s
with the sort and 7,278 req/s without it.

Record the ValueTask contract in lode/dotnet/performance.md and drop the
stale net10.0 clause from the runtime-async note.

Also adds the mr-sparkle precondition, three analyzer candidates from the
2026-11-14 sessions, and the review plan for that run.

Co-Authored-By: Claude
@e128
e128 merged commit 03f17cc into main Nov 15, 2026
2 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