Skip to content

Simplify load bookkeeping and drop comments that restate the code - #11

Draft
andared wants to merge 1 commit into
mainfrom
simplify_load_bookkeeping
Draft

andared wants to merge 1 commit into
mainfrom
simplify_load_bookkeeping

Conversation

@andared

@andared andared commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Refactor with no intended change in behaviour.

  • The load token goes through setValue, setNegative, store and shard.set as one nullable *loadToken parameter instead of a variadic tokens ...*loadToken that only ever held zero or one.
  • The recheck under the flight-group lock, which was duplicated in core.load, core.acquire and View.load, is now shard.beginLoadUnlessCached. The view passes isType[T] so that a hit of another type still loads.
  • The repeated idx := c.shardIndex(key); g, s := c.flights[idx], c.shards[idx] is now flightFor, on both core and View.
  • Len and Bytes read only the shard sizes instead of building a full Stats snapshot, which loaded all 15 atomic counters of every shard.
  • Comments that restated the code are removed. The comment on shard.set now documents the non-obvious part: a stale token makes the write a silent no-op. Comments in tests explain intent and are left as they are.

Checklist

  • make test and make lint pass (go test -race ./..., golangci-lint run: 0 issues)
  • Behaviour changes come with a test that fails without the change: n/a, no behaviour change
  • Performance claims come with benchmark output: none made; Len/Bytes only drop work
  • Public API changes are noted in CHANGELOG.md: no API change; the Len/Bytes internals are noted under Unreleased
  • No new dependencies

- Pass the load token as one nullable parameter instead of a variadic
  that only ever held zero or one.
- Share the under-lock recheck of load, acquire and View.load as
  shard.beginLoadUnlessCached, and the shard/flight-group lookup as
  flightFor.
- Len and Bytes read the shard sizes without snapshotting every counter.
- Remove comments that repeat what the code says; document instead that
  a stale token makes shard.set a silent no-op.
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.

2 participants