From 63bfa85e6a63f0718f8e644921201b26bbe8bfd8 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Sun, 27 Sep 2026 18:48:32 +0100 Subject: Find a burst's keys in one look A message for a document scanned the burst's pending keys with strcmp to see whether its key was there, and the host scanned the burst's earlier requests the same way before each one: both quadratic in the burst (64 concurrent reads, about 31 compares each, twice). The app now indexes its pending documents by key (open addressing over an FNV-1a hash, 1 KiB), answers pure_app_pending in one look, and the host asks it; whether the current event's document is pending is a flag instead of a scan by pointer. Bursts split where they did, except that on an owner, which applies a round's reads first, an edit of a key read in the same round now splits the burst at the host rather than the app saving on its own. A unit test checks the index at 200 keys. --- serve/serve.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'serve') diff --git a/serve/serve.c b/serve/serve.c index 8f0bb8d..d0f3dd1 100644 --- a/serve/serve.c +++ b/serve/serve.c @@ -1190,10 +1190,9 @@ static void execute(Executor *ex, const Job *jobs, size_t count, void (*finish)( size_t n = reads, start = reads, keys = 0; for (size_t i = 0; i < count; ++i) { if (ex->reads_first && jobs[i].effect.input == PURE_INPUT_READ) continue; - bool document = jobs[i].route.kind == ROUTE_OBJECT, repeated = false; - for (size_t k = start; k < n && document && !repeated; ++k) - repeated = applied[k].route == ROUTE_OBJECT && !strcmp(applied[k].key, jobs[i].effect.key); - if (repeated || (document && keys == PURE_APP_PENDING)) { + /* A document joins a burst once (its revision moves once a save). */ + bool document = jobs[i].route.kind == ROUTE_OBJECT; + if (document && (keys == PURE_APP_PENDING || pure_app_pending(&ex->app, jobs[i].effect.key))) { save_burst(ex, applied + start, n - start); finish(context, applied + start, n - start); start = n; -- cgit v1.2.3