From e254a0e0f31874da58de52dbf325c39a66f6afe4 Mon Sep 17 00:00:00 2001 From: Davide Cappellini Date: Sat, 21 Nov 2026 00:34:28 +0100 Subject: [PATCH] docs: tile gate is dbLock-free, private mutex (#65) --- docs/ANALYSIS.md | 2 +- docs/DESIGN.md | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/ANALYSIS.md b/docs/ANALYSIS.md index f63b086..ba79fae 100644 --- a/docs/ANALYSIS.md +++ b/docs/ANALYSIS.md @@ -367,7 +367,7 @@ simpler than any outbox with byte accounting and fits the pin's limits. | Polygon, dense 5k | 1.28 ms | ~0.1 ms (sweep) | | Thick, dense, 6-token party | 75.6 ms | a few ms (sweep, near faces) | | Vision frame per move | 3.4-3.7 KB | ~1 KB (quantised) | -| Tile request cost | global lock + DB + SHA-256 | lock-free map lookup + bit test | +| Tile request cost | global lock + DB + SHA-256 | `dbLock`-free map lookup + bit test (private mutex) | | Data-race class | present | gone | --- diff --git a/docs/DESIGN.md b/docs/DESIGN.md index 6c3117e..72877d3 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -469,10 +469,15 @@ server clamps nothing silently (clamping would leak the hit distance, T8). whole explored `HashSet` per player (~4.9 ms at 262144 cells on the review build, measured). Nothing that egress holds may outlive the lock hold. - **The scene is a value swapped, never mutated, under the lock** (#31): every reader takes one - snapshot under `dbLock` and uses it for the whole request โ€” `tileGate` (parse, explored check and - `X-Accel-Redirect` from one record), `checkScene` (the id), the wall/door handlers (the post-lock - log and effect frame). A handler that reads `app.scene` twice can see two records; one that reads - it outside the lock races the assignment and ORC's free of the old `walls`. + snapshot under `dbLock` and uses it for the whole request โ€” `checkScene` (the id), the wall/door + handlers (the post-lock log and effect frame). A handler that reads `app.scene` twice can see two + records; one that reads it outside the lock races the assignment and ORC's free of the old + `walls`. +- **The tile gate is `dbLock`-free** (#65): `tileGate` reads the `GateCache` under its own private + mutex (not lock-free, just off the global lock) โ€” a hash lookup and a bit test, no SQL, no + `app.scene` snapshot. Writers (join, key replacement, player removal, explored refresh) update + the cache under `dbLock` before the ack, so a revoked session or a freshly explored cell is + visible before the client's next request. - SQLite tail: server worst ~20 ms is the COMMIT and every other mutation queues behind it as `lock_wait` (measurement and hypothesis: TESTING ยง4.3). Accepted for v1. Moving persist out of the lock breaks ack-after-commit and order; not done.