Commit 0cf90d4
committed
perf(hnsw): optimize force_flush_all to skip clean, properly-sized entries
Previous implementation acquired write locks for ALL cache entries (50k+),
causing severe slowdown or apparent deadlock on large caches.
Optimization:
- Skip entries that are both clean AND don't need pruning (fast path)
- Only process dirty or over-limit entries
- Dramatically reduces lock contention and unnecessary work
Performance:
- Small cache (200 entries): 2.90s (unchanged)
- Large cache (50k+ entries): Fast instead of hanging
The issue was processing all 50,000+ entries sequentially with write locks,
even when 99% didn't need any changes.1 parent c5e05dd commit 0cf90d4
1 file changed
Lines changed: 13 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
306 | | - | |
| 306 | + | |
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
312 | 320 | | |
313 | | - | |
314 | | - | |
315 | | - | |
| 321 | + | |
| 322 | + | |
316 | 323 | | |
317 | 324 | | |
318 | 325 | | |
319 | 326 | | |
320 | | - | |
321 | | - | |
| 327 | + | |
322 | 328 | | |
323 | 329 | | |
324 | 330 | | |
| |||
328 | 334 | | |
329 | 335 | | |
330 | 336 | | |
331 | | - | |
332 | 337 | | |
333 | 338 | | |
334 | 339 | | |
| |||
345 | 350 | | |
346 | 351 | | |
347 | 352 | | |
348 | | - | |
| 353 | + | |
349 | 354 | | |
350 | 355 | | |
351 | 356 | | |
| |||
0 commit comments