Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
290ac63
fix(views): rebuild list views on retained notifications
glennawatson Dec 1, 2026
d2a0a67
fix(views): resync ReactiveView from its source when notifications ca…
glennawatson Dec 1, 2026
3e217d3
test: add CsCheck model, concurrency and lifecycle tests for quaterna…
glennawatson Dec 1, 2026
448a074
fix(list): make ReactiveList thread-safe with queued notifications an…
glennawatson Dec 1, 2026
c487619
test(list): add CsCheck model-based and concurrency fuzz tests
glennawatson Dec 1, 2026
0cf4d1f
fix: make quaternary collections disposal-safe, ordered and multiset-…
glennawatson Dec 1, 2026
b98eef0
fix(views): confirm ReactiveView copies against late notifications an…
glennawatson Dec 1, 2026
655ab17
perf: cut allocations in index, ToArray and RemoveRange paths and add…
glennawatson Dec 1, 2026
3c6ab4f
fix(views): project dynamic and secondary index views through StreamP…
glennawatson Dec 1, 2026
6ce9a54
perf(list): read without locking from a shared snapshot and add core …
glennawatson Dec 1, 2026
9f8edc8
fix(extensions): detach AutoRefresh handlers and stop losing FilterDy…
glennawatson Dec 1, 2026
8a9a21b
test(views): add concurrency fuzz tests and harden view copies agains…
glennawatson Dec 1, 2026
d90737c
test(views): assert common notifications apply without a source resync
glennawatson Dec 1, 2026
2dd2c30
perf(views): add view benchmarks across the floor, interactive and bu…
glennawatson Dec 1, 2026
693c887
test(list): pin delivery order, reentrancy and dispose semantics
glennawatson Dec 1, 2026
2dc17e0
test(list): cover serialization round trips of lock, disposal, mirror…
glennawatson Dec 1, 2026
368af9a
docs(list): state the AsSpan and AsMemory snapshot contract and test it
glennawatson Dec 1, 2026
7c2c6d8
Merge branch 'worktree-agent-a08fb86dd92baa2ec' into perf-reliability…
glennawatson Dec 1, 2026
4edd6e3
Merge branch 'worktree-agent-a98662ac520bb3cbf' into perf-reliability…
glennawatson Dec 1, 2026
0c4c3e5
ci: pin actions-common to the coverage re-run and Codecov token fix
glennawatson Dec 1, 2026
9f59d08
refactor: adopt the Primitives exception helper polyfill pattern
glennawatson Dec 1, 2026
6708204
perf(views): apply batch removals to list views incrementally and ver…
glennawatson Dec 1, 2026
69691c8
Merge branch 'worktree-agent-a63565c22e67574b2' into perf-reliability…
glennawatson Dec 1, 2026
f13a710
refactor: replace ThrowHelper with the ArgumentExceptionHelper alias
glennawatson Dec 1, 2026
925828c
wip: ShardLock abstraction over the shard locks (experiment)
glennawatson Dec 1, 2026
17e6900
Merge remote-tracking branch 'origin/perf-reliability-pass' into work…
glennawatson Dec 1, 2026
1d6e248
perf: skip history arrays without mirrors, lock-free reads, range mir…
glennawatson Dec 1, 2026
f543599
Merge remote-tracking branch 'origin/perf-reliability-pass' into work…
glennawatson Dec 1, 2026
25217f6
feat: pair quaternary snapshots with notification versions and report…
glennawatson Dec 1, 2026
cf023dd
feat: pair quaternary snapshots with notification versions and report…
glennawatson Dec 1, 2026
b949516
feat: expose quaternary versioned snapshots through an internal sourc…
glennawatson Dec 1, 2026
609f266
feat: expose quaternary versioned snapshots through an internal sourc…
glennawatson Dec 1, 2026
5dbfa1c
fix: announce reorder-only edits and make rewrites replay-safe on the…
glennawatson Dec 1, 2026
100bdca
refactor: keep ReaderWriterLockSlim shard locks after measuring Lock …
glennawatson Dec 1, 2026
a706364
fix(views): cancel scheduled drains on dispose and wait for a running…
glennawatson Dec 1, 2026
59a1987
feat(views): add BatchResetLimit, seal the stream views and keep batc…
glennawatson Dec 1, 2026
5d3c548
test: add weak-reference retention tests and mirror and lookup benchm…
glennawatson Dec 1, 2026
8e13cf5
feat(queries): add the Live query front door
glennawatson Dec 1, 2026
8b52e01
refactor!: remove QuaternaryBase and publish the versioned snapshot c…
glennawatson Dec 1, 2026
f145d76
perf(views): remove large batches in one pass and search lists withou…
glennawatson Dec 1, 2026
4e4d756
merge: public versioned snapshot source and QuaternaryBase removal
glennawatson Dec 1, 2026
7e3d657
docs: describe IReactiveSource on its own terms
glennawatson Dec 1, 2026
e8dc195
perf(views): use the versioned snapshot source and drop the quaternar…
glennawatson Dec 1, 2026
55bccba
test(queries): add model tests and plan ordered queries on the fused …
glennawatson Dec 1, 2026
1a028eb
fix: name the collection type when used after disposal and keep shard…
glennawatson Dec 1, 2026
b71a01b
test: cover disposed-object names and stream replay from a versioned …
glennawatson Dec 1, 2026
ac69afd
bench: add creation, versioned snapshot and versioned stream benchmar…
glennawatson Dec 1, 2026
76336c3
bench: unseal benchmark classes because BenchmarkDotNet requires it
glennawatson Dec 1, 2026
e9bd1f6
perf(benchmarks): replace the view benchmark base class and add Batch…
glennawatson Dec 1, 2026
1d92fee
refactor!: seal ReactiveList and make Reactive2DList a forwarding class
glennawatson Dec 1, 2026
1ea2ad0
Merge branch 'worktree-agent-a891ae9c4a012e167' into perf-reliability…
glennawatson Dec 1, 2026
f895715
Merge remote-tracking branch 'origin/perf-reliability-pass' into work…
glennawatson Dec 1, 2026
1c9dd8b
wip: live queries, concurrency and state tests; PublicAPI baselines s…
glennawatson Dec 1, 2026
3556f10
test(queries): import the reactive signal factory
glennawatson Dec 1, 2026
0c40ee2
fix(views): rebuild invalidated projections
glennawatson Dec 1, 2026
8b11d15
chore: integrate versioned view changes
glennawatson Dec 1, 2026
e120f1f
chore: integrate sharded collection changes
glennawatson Dec 1, 2026
e7365f2
fix(queries): handle versioned dictionary batches
glennawatson Dec 1, 2026
168eff3
docs: update collection and inlining guidance
glennawatson Dec 1, 2026
580a361
refactor: centralize runtime compatibility
glennawatson Dec 1, 2026
c1e8356
fix(dictionary): preserve batch stream payloads
glennawatson Dec 1, 2026
a6ca125
fix(queries): complete during source disposal
glennawatson Dec 1, 2026
18ed535
feat(views): support immutable source items
glennawatson Dec 1, 2026
66bc2fc
perf(list): skip redundant empty clears
glennawatson Dec 1, 2026
42393fe
perf(views): use list search for value types
glennawatson Dec 1, 2026
c1639e6
test(queries): collect generated scripts serially
glennawatson Dec 1, 2026
8fbdde1
test(benchmarks): cover live query workloads
glennawatson Dec 1, 2026
2a18bb2
feat(collections): defer change notifications
glennawatson Dec 1, 2026
ad4b229
perf(views): reduce drain and search work
glennawatson Dec 1, 2026
e284c9c
fix(shards): complete streams racing startup
glennawatson Dec 1, 2026
abd8244
fix(queries): keep snapshots consistent during writes
glennawatson Dec 1, 2026
d55d7b6
refactor(collections): reuse shared update paths
glennawatson Dec 1, 2026
2b99627
perf(queries): reconcile live windows once per batch
glennawatson Dec 1, 2026
a6dd24b
fix(views): keep a late schedule handle from cancelling a newer drain
glennawatson Dec 1, 2026
b54111d
fix(views): re-sort a sorted view item replaced by itself
glennawatson Dec 1, 2026
1f32a04
fix(views): remove every item of a large batch from a filtered projec…
glennawatson Dec 1, 2026
34af38c
fix(list): announce a silent clear to versioned observers
glennawatson Dec 1, 2026
a545ad4
fix(queries): take the first count from a copy of the source
glennawatson Dec 1, 2026
bac6677
perf(views): remove a positionless batch from the mirror in one pass
glennawatson Dec 1, 2026
726716d
fix(views): release the source subscription when a view constructor t…
glennawatson Dec 1, 2026
4a883f0
fix(views): cover the subscribe gap and honour a drain requested befo…
glennawatson Dec 1, 2026
7471ca3
fix(queries): release SelectMany subscriptions after an inner error a…
glennawatson Dec 1, 2026
8a18105
fix(collections): keep state committed when user code throws mid-oper…
glennawatson Dec 1, 2026
95bd8a4
perf(views): keep filtered range inserts and removals linear
glennawatson Dec 1, 2026
a7cd071
fix(views): apply a dictionary upsert incrementally
glennawatson Dec 1, 2026
d4661e2
fix(queries): order groups like LINQ, group incrementally and read gr…
glennawatson Dec 1, 2026
1e6420c
fix(list): complete subscribers of a disposed list and close the Curr…
glennawatson Dec 1, 2026
213f33b
fix(views): stop quietly when the source is disposed before a drain
glennawatson Dec 1, 2026
c075f68
feat(collections): forward the versioned snapshot source through Reac…
glennawatson Dec 1, 2026
f0f0821
docs(core): say when CacheAction.Reset is raised
glennawatson Dec 1, 2026
e5b2994
refactor(collections): drop the iterator and the blocking observable …
glennawatson Dec 1, 2026
2e91165
fix(views): make BatchResetLimit the only reset threshold
glennawatson Dec 1, 2026
b8c4d47
feat(queries): compose where, select, skip, take and grouping after a…
glennawatson Dec 1, 2026
9564213
fix(views): stop a drain on dispose without waiting for it
glennawatson Dec 1, 2026
b70f3db
perf(queries): move only the items that enter or leave when a window …
glennawatson Dec 1, 2026
4a33028
test(queries): gate dispose tests on running writers and check state …
glennawatson Dec 1, 2026
29709db
test(queries): widen the model scripts and make the identity check exact
glennawatson Dec 1, 2026
033978a
fix(views): publish view events inside the disposal gate
glennawatson Dec 1, 2026
4d3b2bc
fix(views): use the SpinOnce overload every target framework has
glennawatson Dec 1, 2026
d868e03
perf(queries): add group and window slide benchmarks and record the n…
glennawatson Dec 1, 2026
8ad03b7
Merge branch 'worktree-agent-ae71e9308470910cf' into worktree-agent-a…
glennawatson Dec 1, 2026
3a2f8ac
Merge branch 'worktree-agent-ab3322c45fa3e6b3e' into worktree-agent-a…
glennawatson Dec 1, 2026
3bccb48
fix(api): order the windowed query members in the baselines
glennawatson Dec 1, 2026
46db613
fix(queries): satisfy nullable analysis on every target
glennawatson Dec 1, 2026
a9d7111
fix(queries): wait for in-flight work on dispose with the disposal gate
glennawatson Dec 1, 2026
f1bc921
feat(queries): add a batch reset limit to live views
glennawatson Dec 1, 2026
692c8ae
test(queries): cover silent clears and throwing source user code
glennawatson Dec 1, 2026
4da42bb
docs: describe live query syntax, windows, groups and the reset limit
glennawatson Dec 1, 2026
9a7c548
test(queries): keep the counting list legacy and add a versioned list…
glennawatson Dec 1, 2026
fa9ba5c
perf(sharded): build no index table until an index exists and count i…
glennawatson Dec 1, 2026
f559998
perf(list): count the copies a range removal takes in pooled arrays
glennawatson Dec 1, 2026
267ed9f
perf(views): apply immediate notifications without the queue and stop…
glennawatson Dec 1, 2026
e74066d
perf(2d): read rows and inner lists through their snapshots
glennawatson Dec 1, 2026
46bd453
perf(list): keep history compact and release delivery without the lock
glennawatson Dec 1, 2026
671d30d
perf(dictionary): compare value-type keys with the default comparer d…
glennawatson Dec 1, 2026
3fde81b
perf(dictionary): publish one removal for RemoveMany instead of one p…
glennawatson Dec 1, 2026
1d90b8a
perf(list): read the indexer under the locks of the shards up to the …
glennawatson Dec 1, 2026
c1b7c8c
perf(views): fill new views silently and allocate dispatchers, signal…
glennawatson Dec 1, 2026
770e184
perf(list): enumerate with a sealed snapshot enumerator and copy ToAr…
glennawatson Dec 1, 2026
7787849
perf(sharded): keep the indexes in one array of entries
glennawatson Dec 1, 2026
2a210e1
perf(list): route a batch to its shards without a delegate call per item
glennawatson Dec 1, 2026
b495b56
perf(views): enter the disposal gate with one fence and leave it with…
glennawatson Dec 1, 2026
882db84
perf(queries): apply a window change inside the drain without rebuild…
glennawatson Dec 1, 2026
8bb0de3
perf(views): allocate less per view and keep dictionary entries from …
glennawatson Dec 1, 2026
9c5caf1
Merge branch 'worktree-agent-aab7a6c1a0aca9621' into perf-reliability…
glennawatson Dec 1, 2026
75aa307
Merge branch 'worktree-agent-a5acdbcf4cb5332f1' into perf-reliability…
glennawatson Dec 1, 2026
c8ad7bc
test(queries): wait for the reset event before counting it
glennawatson Dec 1, 2026
cb32b86
fix(dictionary): publish the shard count as one value
glennawatson Dec 1, 2026
860be90
perf(sharded): skip zeroing arrays that are filled straight away
glennawatson Dec 2, 2026
b4b454c
test(testapp): expect source order when an update gains membership
glennawatson Dec 2, 2026
de0fb45
style(testapp): add the blank line the analyzer requires
glennawatson Dec 2, 2026
11cce73
fix(views): apply a queued filter with the changes that follow it
glennawatson Dec 2, 2026
7739f7a
test(sharded): bound the read race writers by time
glennawatson Dec 2, 2026
ceba4ce
test(views): cover reset limit and change event accessors of every view
glennawatson Dec 2, 2026
c3a301e
test: cover Reactive2DList forwarding members and ItemComparison
glennawatson Dec 2, 2026
b1ff141
refactor: move the delivery hand-off into DrainState and test it
glennawatson Dec 2, 2026
f2c403b
fix(queries): rebuild a tally when an item changes in place
glennawatson Dec 2, 2026
423fc27
test(queries): cover the live view and query overload surface
glennawatson Dec 2, 2026
22d1b03
test: cover serialized observer, multiset difference, mirror removal …
glennawatson Dec 2, 2026
a6e402a
test(queries): cover subscriptions, serializer, sequence and group la…
glennawatson Dec 2, 2026
b82695f
test: cover auto refresh teardown, non-generic list members and dicti…
glennawatson Dec 2, 2026
5247278
test(queries): cover refreshed items and queued window drains
glennawatson Dec 2, 2026
30dd463
test: cover snapshot enumerators, value equality members, range colle…
glennawatson Dec 2, 2026
6eff32f
test: cover dynamic filter relays, dispatcher disposal, source copy r…
glennawatson Dec 2, 2026
e16c90b
test(views): cover the mirror repair paths of the view change buffer
glennawatson Dec 2, 2026
4c2eece
refactor(views): move racy view helpers into static internal methods …
glennawatson Dec 2, 2026
d0a6ac0
test: cover quiet batches and grouped engine sink callbacks
glennawatson Dec 2, 2026
94a5818
test: cover sorted and filtered engine refresh paths
glennawatson Dec 2, 2026
a2a8c5a
Merge branch 'worktree-agent-a0213c7312a5330c6' into perf-reliability…
glennawatson Dec 2, 2026
f4b1a2d
test: cover view mirror pump failures and make snapshot replay tests …
glennawatson Dec 2, 2026
8e1ad74
test: qualify the internal observable helper in reactive mode
glennawatson Dec 2, 2026
be6d451
test: cover signal creation races and stale refresh guards
glennawatson Dec 2, 2026
7adb52d
test: cover collection-changed handler swap retries and closed gate o…
glennawatson Dec 2, 2026
d802cb3
test: cover view mirror pump count publication and subscription hand-…
glennawatson Dec 2, 2026
eeded7b
test: cover stream projection failure, disposal and unapplied-notific…
glennawatson Dec 2, 2026
41999c3
test: cover leftover batch removal check, updated multi-key entries a…
glennawatson Dec 2, 2026
9803a4f
Merge collections coverage branch into the views coverage branch
glennawatson Dec 2, 2026
d1c8273
test: cover attach after disposal and current signal creation after d…
glennawatson Dec 2, 2026
5f607ab
refactor(views): read the projection error handler once
glennawatson Dec 2, 2026
1ff2e06
refactor(views): check the batch reset limit in one helper
glennawatson Dec 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
permissions:
contents: read
actions: write
uses: reactiveui/actions-common/.github/workflows/workflow-common-setup-and-build.yml@af603d4a2e933d92681b77919452a8bde4be9e13 # main
uses: reactiveui/actions-common/.github/workflows/workflow-common-setup-and-build.yml@e07297f2914b5af0b96e82ddb6872835156a0287 # main
with:
configuration: Release
productNamespacePrefix: ReactiveList
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
contents: read
packages: read
actions: read
uses: reactiveui/actions-common/.github/workflows/workflow-common-codeql.yml@af603d4a2e933d92681b77919452a8bde4be9e13 # main
uses: reactiveui/actions-common/.github/workflows/workflow-common-codeql.yml@e07297f2914b5af0b96e82ddb6872835156a0287 # main
with:
srcFolder: src
solutionFile: ReactiveList.slnx
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
permissions:
issues: write
pull-requests: write
uses: reactiveui/actions-common/.github/workflows/workflow-common-lock-threads.yml@af603d4a2e933d92681b77919452a8bde4be9e13 # main
uses: reactiveui/actions-common/.github/workflows/workflow-common-lock-threads.yml@e07297f2914b5af0b96e82ddb6872835156a0287 # main
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
contents: write
id-token: write
packages: read
uses: reactiveui/actions-common/.github/workflows/workflow-common-release.yml@af603d4a2e933d92681b77919452a8bde4be9e13 # main
uses: reactiveui/actions-common/.github/workflows/workflow-common-release.yml@e07297f2914b5af0b96e82ddb6872835156a0287 # main
with:
solutionFile: ReactiveList.slnx
minverMinimumMajorMinor: '7.0'
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
permissions:
contents: write
needs: [release, publish-nuget]
uses: reactiveui/actions-common/.github/workflows/workflow-common-create-release.yml@af603d4a2e933d92681b77919452a8bde4be9e13 # main
uses: reactiveui/actions-common/.github/workflows/workflow-common-create-release.yml@e07297f2914b5af0b96e82ddb6872835156a0287 # main
with:
version: ${{ needs.release.outputs.semver2 }}
tag: ${{ needs.release.outputs.tag }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
contents: read
id-token: write
security-events: write
uses: reactiveui/actions-common/.github/workflows/workflow-common-scorecard.yml@af603d4a2e933d92681b77919452a8bde4be9e13 # main
uses: reactiveui/actions-common/.github/workflows/workflow-common-scorecard.yml@e07297f2914b5af0b96e82ddb6872835156a0287 # main
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions:

jobs:
sonarcloud:
uses: reactiveui/actions-common/.github/workflows/workflow-common-sonarcloud.yml@af603d4a2e933d92681b77919452a8bde4be9e13 # main
uses: reactiveui/actions-common/.github/workflows/workflow-common-sonarcloud.yml@e07297f2914b5af0b96e82ddb6872835156a0287 # main
with:
productNamespacePrefix: ReactiveList
solutionFile: ReactiveList.slnx
Expand Down
8 changes: 5 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Thread safety is a core contract of `ReactiveList`. Every collection, secondary
| Area | Mandatory Rule |
| :--- | :--- |
| **Lock primitive** | Use the repo `Lock` alias (`System.Threading.Lock` on `net10.0+`, `object` on `.NET Framework`) for short, non-recursive mutual exclusion. Never `lock (this)` or lock on public instances or `Type` objects. |
| **Sharded lock order** | In four-shard quaternary collections (`QuaternaryBase`, `QuaternaryList<T>`, `QuaternaryDictionary<TKey, TValue>`), multi-shard operations (`Count`, snapshots, `Clear`, `RemoveRange`, index rebuilds) must acquire shard locks in strict ascending index order (`0` to `ShardCount - 1`) and release them in reverse order inside `finally`. Never acquire a lower-numbered shard lock while holding a higher-numbered one. |
| **Sharded lock order** | In `QuaternaryList<T>` and `QuaternaryDictionary<TKey, TValue>`, operations that acquire multiple shard locks must take them in ascending order and release them in reverse order inside `finally`. Never acquire a lower-numbered shard lock while holding a higher-numbered one. |
| **Idempotent disposal** | Guard `Dispose` and `Dispose(bool)` with an atomic latch: `if (Interlocked.Exchange(ref _disposed, 1) != 0) { return; }` (`PSH1306`). Check `Volatile.Read(ref _disposed) != 0` on entry to operations that throw `ObjectDisposedException`. |
| **Memory-model visibility** | Every non-`Interlocked` read of a field mutated via `Interlocked.*` (`_disposed`, `_version`, counters, state references) must use `Volatile.Read` (`PSH1307`). Never publish multi-field state via plain writes; swap a single immutable state object or snapshot reference with `Interlocked.CompareExchange` or `Volatile.Write`. |
| **Callback reentrancy** | Never invoke external user delegates (filter predicates when avoidable, `IObserver<T>.OnNext`, `CollectionChanged`, `PropertyChanged`) while holding internal shard or mutation locks if reentrant callbacks can deadlock or observe half-updated invariants. Capture notification state inside the lock, release the lock, and dispatch outside or via the single-reader notification channel. |
Expand All @@ -84,7 +84,7 @@ Structure public and internal mutation/query methods so cheap checks reject no-o

### 2. Cold-Gate Splitting for JIT Inlining

The .NET JIT refuses to inline methods that contain `try`/`finally` blocks (including `lock` statements), large switch/loop bodies, or inline `throw new ...` expressions:
The .NET 10 and later JIT can inline some methods that contain `try`/`finally`. The presence of a lock is not enough to decide whether to split a method. Use measurements to justify a split on modern targets. Keep large branches and uncommon work out of the steady-state path:

- Keep hot steady-state paths (`Count`, indexer reads, `AsSpan`, observerless fast checks, lazy-initialized pipeline/channel reads) small and mark tiny wrappers `[MethodImpl(MethodImplOptions.AggressiveInlining)]`.
- Read lazy-initialized references (`_streamPipeline`, `_eventChannel`) via `Volatile.Read` on the warm path, and split lock-protected initialization (`EnsureEventProcessorStarted`, `EnsurePipelineCreated`), buffer resizing, contention fallback, and exception throwing into `[MethodImpl(MethodImplOptions.NoInlining)]` slow-path methods.
Expand All @@ -99,12 +99,14 @@ The .NET JIT refuses to inline methods that contain `try`/`finally` blocks (incl

## 4. Allocation, Data-Layout, and Idiomatic C# Rules

Use sealed classes and composition instead of custom base classes. Interfaces are allowed. Inherit from a class or leave it unsealed only when an external dependency requires it.

Library hot paths must minimize GC pressure, pointer chasing, and interface dispatch across all supported target frameworks.

- **Zero LINQ, zero `Regex`, and zero `yield return` on production hot paths:** `System.Linq`, `System.Text.RegularExpressions`, and iterator state machines (`yield return`) are banned on hot paths in `src/ReactiveList` and `src/ReactiveList.Reactive` (LINQ is permitted in test projects for assertion clarity). Use indexed `for` loops over `T[]`, `Span<T>`, `ReadOnlySpan<T>`, and `List<T>`.
- **Frozen collections are banned:** Do not use `System.Collections.Frozen`, `FrozenDictionary`, `FrozenSet`, `ToFrozenDictionary`, or `ToFrozenSet`. `ReactiveList` is a reusable library and cannot assume a long-running host process to amortize construction cost. Use `Dictionary<TKey, TValue>` and `HashSet<T>` with explicit capacity hints where size is known, and always pass `StringComparer.Ordinal` for string keys (index names, property names).
- **Concrete collection types (`CA1859`):** Type fields, locals, parameters, and internal return values as concrete `List<T>`, `Dictionary<TKey, TValue>`, `HashSet<T>`, or `T[]` rather than `IList<T>`, `ICollection<T>`, `IDictionary<TKey, TValue>`, or `IEnumerable<T>` so `foreach` uses non-allocating struct enumerators and method calls devirtualize.
- **Single-lookup dictionary operations:** Never pair `ContainsKey` with an indexer read/write. Use `TryGetValue`, `Remove(key, out value)`, and on `NET8_0_OR_GREATER` `CollectionsMarshal.GetValueRefOrAddDefault` / `CollectionsMarshal.GetValueRefOrNullRef` (`#if`-guarded cleanly for `.NET Framework`).
- **Single-lookup dictionary operations:** Never pair `ContainsKey` with an indexer read/write. Use `TryGetValue`, `Remove(key, out value)`, and `DictionaryCompat` for ref-based updates. Keep runtime choices such as `CollectionsMarshal` and their .NET Framework fallbacks in shared internal static helpers, not at the call sites.
- **Zero closure allocations (`IDE0320`):** Mark all production lambdas and local functions `static`. Pass context explicitly through state parameters (`Scope.Create(state, static s => ...)`) using named positional `record` or `readonly record struct` types rather than value tuples across method boundaries.
- **Cached event args and singletons:** Reuse `static readonly` `PropertyChangedEventArgs` (`Count`, `Item[]`), `NotifyCollectionChangedEventArgs` (`Reset`), empty `ChangeSet<T>.Empty`, `Array.Empty<T>()` / `[]`, and stateless `IComparer<T>` instances instead of allocating per notification.
- **Safe `ArrayPool<T>` discipline:** Always return rented `ArrayPool<T>.Shared` buffers inside `finally` (or via deterministic `PooledBatch<T>.Dispose()`). Pass `clearArray: RuntimeHelpers.IsReferenceOrContainsReferences<T>()` (or `Array.Clear(buffer, 0, count)`) when returning buffers so pooled arrays never retain references to user objects. Never use `stackalloc` inside a loop.
Expand Down
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Supported targets: `net10.0`, `net11.0`, `net47`, `net471`, `net472`, `net48`, a
- [Core concepts](#core-concepts)
- [Collections](#collections)
- [Views](#views)
- [Live queries](#live-queries)
- [Extension methods](#extension-methods)
- [API overview](#api-overview)
- [Thread safety](#thread-safety)
Expand Down Expand Up @@ -229,7 +230,7 @@ A cache notification (`CacheNotify<T>`) describes one change to a collection. A

| Member | Meaning |
| --- | --- |
| `Action` | The `CacheAction` that occurred (`Added`, `Removed`, `Updated`, `Moved`, `Refreshed`, `Cleared`, `BatchOperation`, `BatchAdded`, or `BatchRemoved`). |
| `Action` | The `CacheAction` that occurred (`Added`, `Removed`, `Updated`, `Moved`, `Refreshed`, `Cleared`, `BatchOperation`, `BatchAdded`, `BatchRemoved`, or `Reset`). `Reset` means the contents were replaced as a whole: it is raised when a deferral ends with changes, and on `VersionedStream` after a replace, an edit, a silent clear or a removal by predicate. A `Reset` without a snapshot tells the consumer to copy the source again. |
| `Item` | The affected item for single-item operations. |
| `Batch` | The `PooledBatch<T>` for batch operations. Call `AutoDisposeBatches()` or dispose the batch after reading it. |
| `CurrentIndex` | The item's new index, or `-1` when no index applies. |
Expand All @@ -238,7 +239,7 @@ A cache notification (`CacheNotify<T>`) describes one change to a collection. A

### ChangeSet

A change set (`ChangeSet<T>`) is a read-only list of `Change<T>` entries for step-by-step diff processing, similar to DynamicData. Call `ToChangeSets()` on `Stream` or `Connect()` on a collection to receive change sets.
A change set (`ChangeSet<T>`) is a read-only list of `Change<T>` entries for step-by-step diff processing. Call `ToChangeSets()` on `Stream` or `Connect()` on a collection to receive change sets.

Each `Change<T>` carries a `ChangeReason` (`Add`, `Remove`, `Update`, `Move`, `Refresh`, or `Clear`) along with current and previous items and indexes. `ChangeSet<T>` exposes `Count`, `Adds`, `Removes`, `Updates`, `Moves`, and `AsSpan()`.

Expand Down Expand Up @@ -353,6 +354,59 @@ using var search = products.CreateView(
public sealed record Product(string Name, string Category, bool IsActive);
```

## Live queries

Import `ReactiveList.Queries`, or `ReactiveList.Reactive.Queries` for the System.Reactive package. Start with a reactive collection's `Live` property and finish with a view or a stream:

```csharp
using ReactiveList.Collections;
using ReactiveList.Queries;
using ReactiveUI.Primitives;
using ReactiveUI.Primitives.Concurrency;
using ReactiveUI.Primitives.Signals;

using var orders = new ReactiveList<Order>();
using var latestOpenOrders = orders.Live
.Where(static order => order.IsOpen)
.OrderByDescending(static order => order.Id)
.Take(20)
.ToView(Sequencer.Default);

var openCount = orders.Live.Count(static order => order.IsOpen);
using var countSubscription = openCount.Subscribe(Console.WriteLine);

orders.Add(new(1, IsOpen: true));

public sealed record Order(int Id, bool IsOpen);
```

The view uses one subscription to the source for filtering, sorting and the window. `Count`, `Any`, `Contains` and dictionary `ObserveValue` report the current result when you subscribe and emit again only when it changes. `SelectMany` merges one observable per matching item and detaches it when that item leaves the query.

Query syntax works too, and each clause maps to one operator. A chain of `where`, `orderby`, `Skip`, `Take` and `select` still plans onto one view with one source subscription:

```csharp
var page = from order in orders.Live
where order.IsOpen
orderby order.Id descending
select order.Id;
using var ids = page.ToView(Sequencer.Default);

var byStatus = from order in orders.Live
orderby order.Id
group order.Id by order.IsOpen;
using var groups = byStatus.ToView(Sequencer.Default);
```

- **Order:** `OrderBy`, `ThenBy` and their descending forms are stable. Items that tie keep the order of the source. A sharded source has no stable order, so add a final `ThenBy` on a unique key when you need an exact result.
- **Windows:** `Skip` and `Take` compose as in LINQ, so `Take(10).Skip(2)` exposes the third to the tenth item. Either takes an `IObservable<int>` and the window follows it. The view is empty until each observable emits. Moving a window changes only the items that enter or leave it.
- **Groups:** groups appear in the order their key first occurs in the query result, as `GroupBy` does in LINQ. Members keep the query order. `GroupBy(key, element)` holds a projected value in each group. A group view can be read from any thread while it changes.
- **Projections:** `Select` after `OrderBy`, `Skip` or `Take` projects what the window exposes and keeps the order and window. `Where`, `Count`, `Any`, `Contains` and `GroupBy` after such a projection see the projected items.

`LiveView` and `LiveGroupView` expose `BatchResetLimit`, with the same default and meaning as the regular views. Set it to raise one reset for batches larger than the limit, or for a window move larger than the limit, instead of reporting each item separately.
If a source's items never change in place, initialize it with `Options = new() { ItemsAreImmutable = true }`. Views can then ignore refresh notifications. Replacements are still applied.

Use `DeferNotifications()` on a reactive list or sharded collection to group several writes. Reads see each write as soon as it commits. When the last nested scope closes, the collection publishes one reset whose batch contains the final snapshot. Empty scopes publish nothing.

## Extension methods

### `CacheNotifyExtensions`
Expand Down
1 change: 1 addition & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<!-- Testing -->
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.12.0" />
<PackageVersion Include="TUnit" Version="1.90.1" />
<PackageVersion Include="CsCheck" Version="5.0.2" />

<!-- Dependencies -->
<PackageVersion Include="ReactiveUI.Primitives" Version="$(ReactiveUIPrimitivesVersion)" />
Expand Down
30 changes: 30 additions & 0 deletions src/Polyfills/ArgumentExceptionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) ReactiveUI and Contributors. All rights reserved.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace ReactiveList.Polyfills;

/// <summary>Polyfill for <c>ArgumentNullException.ThrowIfNull</c> on target frameworks that predate it.</summary>
[ExcludeFromCodeCoverage]
internal static class ArgumentExceptionHelper
{
/// <summary>Throws an <see cref="ArgumentNullException"/> if <paramref name="argument"/> is <see langword="null"/>.</summary>
/// <param name="argument">The reference type argument to validate as non-null.</param>
/// <param name="paramName">The name of the parameter with which <paramref name="argument"/> corresponds.</param>
/// <exception cref="ArgumentNullException"><paramref name="argument"/> is <see langword="null"/>.</exception>
internal static void ThrowIfNull(
[NotNull] object? argument,
[CallerArgumentExpression(nameof(argument))]
string? paramName = null)
{
if (argument is not null)
{
return;
}

throw new ArgumentNullException(paramName);
}
}
72 changes: 72 additions & 0 deletions src/Polyfills/ArgumentOutOfRangeExceptionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) ReactiveUI and Contributors. All rights reserved.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace ReactiveList.Polyfills;

/// <summary>Polyfill for modern <see cref="ArgumentOutOfRangeException"/> guard helpers on target frameworks that predate them.</summary>
[ExcludeFromCodeCoverage]
internal static class ArgumentOutOfRangeExceptionHelper
{
/// <summary>Throws when <paramref name="value"/> is negative.</summary>
/// <param name="value">The value to validate.</param>
/// <param name="paramName">The parameter name.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is negative.</exception>
internal static void ThrowIfNegative(int value, [CallerArgumentExpression(nameof(value))] string? paramName = null)
{
if (value >= 0)
{
return;
}

throw new ArgumentOutOfRangeException(paramName, value, null);
}

/// <summary>Throws when <paramref name="value"/> is less than <paramref name="other"/>.</summary>
/// <param name="value">The value to validate.</param>
/// <param name="other">The lower bound.</param>
/// <param name="paramName">The parameter name.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than <paramref name="other"/>.</exception>
internal static void ThrowIfLessThan(int value, int other, [CallerArgumentExpression(nameof(value))] string? paramName = null)
{
if (value >= other)
{
return;
}

throw new ArgumentOutOfRangeException(paramName, value, null);
}

/// <summary>Throws when <paramref name="value"/> is greater than <paramref name="other"/>.</summary>
/// <param name="value">The value to validate.</param>
/// <param name="other">The upper bound.</param>
/// <param name="paramName">The parameter name.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is greater than <paramref name="other"/>.</exception>
internal static void ThrowIfGreaterThan(int value, int other, [CallerArgumentExpression(nameof(value))] string? paramName = null)
{
if (value <= other)
{
return;
}

throw new ArgumentOutOfRangeException(paramName, value, null);
}

/// <summary>Throws when <paramref name="value"/> is greater than or equal to <paramref name="other"/>.</summary>
/// <param name="value">The value to validate.</param>
/// <param name="other">The exclusive upper bound.</param>
/// <param name="paramName">The parameter name.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is greater than or equal to <paramref name="other"/>.</exception>
internal static void ThrowIfGreaterThanOrEqual(int value, int other, [CallerArgumentExpression(nameof(value))] string? paramName = null)
{
if (value < other)
{
return;
}

throw new ArgumentOutOfRangeException(paramName, value, null);
}
}
Loading
Loading