aboutsummaryrefslogtreecommitdiffstats
path: root/serve/serve.c
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-27 18:48:32 +0100
committereunhhu <[email protected]>2026-09-27 18:49:16 +0100
commit63bfa85e6a63f0718f8e644921201b26bbe8bfd8 (patch)
tree8a54eae378d5178a409f490af6f2b3e277d10b73 /serve/serve.c
parent76f5edb2bcc227c2be743873753792dbc5af1f48 (diff)
downloadpure-63bfa85e6a63f0718f8e644921201b26bbe8bfd8.tar.gz
pure-63bfa85e6a63f0718f8e644921201b26bbe8bfd8.zip
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.
Diffstat (limited to 'serve/serve.c')
-rw-r--r--serve/serve.c7
1 files changed, 3 insertions, 4 deletions
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;