Commit 6fb7ab0
perf(audience): cache DiskStore.Count to avoid per-tick directory scans
Sample diagnostics panels poll QueueSize on a UI tick — at 10 Hz with
a non-trivial spool that's a continuous Directory.GetFiles scan for a
value that barely changes. Cache the count instead.
- Seed at construction from the existing spool so first poll is
correct without a pre-mutation branch. Lazy-seeding on first bump
had a double-count bug: the seed scan already saw the just-written
file, then the +1 delta pushed the cache past the real on-disk
count.
- Write / Delete / DeleteAll / ApplyAnonymousDowngrade maintain the
delta via BumpCount (Interlocked.Add) and TryDelete now returns a
bool so "actually removed" vs "already gone" can drive the
decrement.
- TryDelete folds DirectoryNotFoundException into the true
(idempotent) branch — per the MS docs it fires on invalid paths
(example: "unmapped drive"), and an unreachable path can't point
to a real file — and keeps IOException / UnauthorizedAccessException
in the false branch so the cache stays honest when a file survived
the delete attempt. FileNotFoundException is deliberately absent:
File.Delete silently succeeds when the file is gone, so there is
nothing to catch.
- Count() reads through Volatile.Read so a caller on a different
thread sees the latest published value.
Cache invariant: on-disk-count-at-ctor + Σ tracked deltas. Events
written outside the DiskStore API (direct File.* calls from tests
that plant fixtures) are not tracked and will drift the cache; such
tests assert on the post-op filesystem state, not Count().
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 0879819 commit 6fb7ab0
1 file changed
Lines changed: 29 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
17 | 24 | | |
18 | 25 | | |
19 | 26 | | |
20 | 27 | | |
| 28 | + | |
21 | 29 | | |
22 | 30 | | |
23 | 31 | | |
| |||
29 | 37 | | |
30 | 38 | | |
31 | 39 | | |
| 40 | + | |
32 | 41 | | |
33 | 42 | | |
34 | 43 | | |
35 | 44 | | |
36 | 45 | | |
37 | 46 | | |
38 | | - | |
39 | 47 | | |
40 | 48 | | |
| 49 | + | |
41 | 50 | | |
| 51 | + | |
| 52 | + | |
42 | 53 | | |
43 | 54 | | |
44 | 55 | | |
| |||
71 | 82 | | |
72 | 83 | | |
73 | 84 | | |
74 | | - | |
| 85 | + | |
75 | 86 | | |
76 | 87 | | |
77 | 88 | | |
| |||
86 | 97 | | |
87 | 98 | | |
88 | 99 | | |
89 | | - | |
| 100 | + | |
90 | 101 | | |
91 | 102 | | |
92 | | - | |
93 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
94 | 108 | | |
95 | | - | |
| 109 | + | |
96 | 110 | | |
97 | | - | |
98 | | - | |
99 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
100 | 115 | | |
101 | 116 | | |
102 | 117 | | |
| |||
105 | 120 | | |
106 | 121 | | |
107 | 122 | | |
108 | | - | |
| 123 | + | |
109 | 124 | | |
110 | 125 | | |
111 | 126 | | |
| |||
126 | 141 | | |
127 | 142 | | |
128 | 143 | | |
129 | | - | |
| 144 | + | |
130 | 145 | | |
131 | 146 | | |
132 | 147 | | |
133 | 148 | | |
134 | 149 | | |
135 | | - | |
| 150 | + | |
136 | 151 | | |
137 | 152 | | |
138 | 153 | | |
| |||
176 | 191 | | |
177 | 192 | | |
178 | 193 | | |
179 | | - | |
| 194 | + | |
180 | 195 | | |
181 | 196 | | |
182 | 197 | | |
183 | | - | |
| 198 | + | |
184 | 199 | | |
185 | 200 | | |
186 | 201 | | |
| |||
0 commit comments