aboutsummaryrefslogtreecommitdiffstats
path: root/prototypes
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-26 07:47:57 +0100
committereunhhu <[email protected]>2026-09-26 07:47:57 +0100
commit0c47bc2bc2497771740410bcd965d4d4fd0e3524 (patch)
tree85e9c24eb25f7f01f465a23cbe3995133e472152 /prototypes
parent4ebd1cd9108b135c1216bc6ae17832b77dcacaf3 (diff)
downloadpure-0c47bc2bc2497771740410bcd965d4d4fd0e3524.tar.gz
pure-0c47bc2bc2497771740410bcd965d4d4fd0e3524.zip
Let a burst hold up to 256 documents
A burst ended once 16 keys had joined it, so 64 writers needed four commits a round and some waited through several (p50 17.4 ms). The pending documents now grow on demand up to 256 keys, which also makes PureApp 1.3 KB smaller (3,128 bytes). With 64 connections a commit now carries 26 events on average instead of 12 and the median PUT waits 9.2 ms; throughput moves less, since each commit writes more and the SD card's syncs take most of the time.
Diffstat (limited to 'prototypes')
-rw-r--r--prototypes/connections/module.c8
-rw-r--r--prototypes/connections/module.h8
-rw-r--r--prototypes/connections/test-module.c6
3 files changed, 16 insertions, 6 deletions
diff --git a/prototypes/connections/module.c b/prototypes/connections/module.c
index f8ebdd3..ebb746f 100644
--- a/prototypes/connections/module.c
+++ b/prototypes/connections/module.c
@@ -1038,6 +1038,7 @@ void pure_app_stop(PureApp *app) {
pure_draft_close(app->list_drafts[i]);
}
pure_draft_close(app->stored_values);
+ free(app->pending);
pure_undo_free(&app->undo);
free(app->arena.bytes);
free(app->view_arena.bytes);
@@ -1164,6 +1165,13 @@ PureResult pure_app_message(PureApp *app, uint32_t input, const char *key, int64
PureResult saved = pure_app_save(app);
if (saved != PURE_OK) return saved;
}
+ if (app->pending_count == app->pending_capacity) {
+ unsigned capacity = app->pending_capacity ? 2 * app->pending_capacity : 16;
+ struct PurePending *grown = realloc(app->pending, capacity * sizeof(*grown));
+ if (!grown) return PURE_ALLOCATION;
+ app->pending = grown;
+ app->pending_capacity = capacity;
+ }
PureResult opened = app->data.open(app->data.context, 0, key, &app->document, &app->revision);
if (opened != PURE_OK) { app->document = NULL; return opened; }
if (base >= 0 && base != app->revision) { pure_app_finish(app); return PURE_CONFLICT; }
diff --git a/prototypes/connections/module.h b/prototypes/connections/module.h
index c5d4f52..c9fb606 100644
--- a/prototypes/connections/module.h
+++ b/prototypes/connections/module.h
@@ -19,7 +19,7 @@ enum {
PURE_MODULE_NAME = 32, PURE_MODULE_STRINGS = 32768, PURE_MODULE_HEADER = 40,
PURE_MODULE_FIELDS = 32, PURE_MODULE_COLLECTIONS = 1, PURE_MODULE_CONSTANTS = 64,
PURE_MODULE_CONSTANT_BYTES = 8192, PURE_MODULE_RECORDS = 8, PURE_MODULE_RECORD_FIELDS = 64,
- PURE_RECORD_FIELDS = 16, PURE_MODULE_JOINS = 8, PURE_APP_PENDING = 16
+ PURE_RECORD_FIELDS = 16, PURE_MODULE_JOINS = 8, PURE_APP_PENDING = 256
};
typedef enum {
@@ -147,7 +147,7 @@ typedef struct { unsigned char *bytes; size_t used, capacity; } PureArena;
* before it returns (a frame waits for the next one). Deferred, events apply
* at once and a host saves a burst with one commit: an event is durable once
* a later save succeeds, and each key's document joins a burst once (a second
- * message for it saves the burst first). */
+ * message for it, or one past PURE_APP_PENDING keys, saves the burst first). */
typedef struct {
const PureModule *module;
PureData data;
@@ -164,8 +164,8 @@ typedef struct {
double durable_values[PURE_MODULE_STATES];
PureVersion durable_texts[PURE_MODULE_STATES], durable_lists[PURE_MODULE_STATES];
uint64_t durable_ticks, durable_events;
- struct { void *document; char key[65]; bool edited; } pending[PURE_APP_PENDING];
- unsigned pending_count;
+ struct PurePending { void *document; char key[65]; bool edited; } *pending; /* grows to PURE_APP_PENDING */
+ unsigned pending_count, pending_capacity;
PureFault fault;
uint32_t fault_pc;
uint64_t ticks, events;
diff --git a/prototypes/connections/test-module.c b/prototypes/connections/test-module.c
index e1d1ccf..6f48bc8 100644
--- a/prototypes/connections/test-module.c
+++ b/prototypes/connections/test-module.c
@@ -1697,8 +1697,10 @@ static void deferred_messages(void) {
pure_app_stop(&app); /* the last edit was never saved */
CHECK(pure_app_start(&app, &module_a, pure_tree_data(path)) == PURE_OK && app.values[0] == 4 + PURE_APP_PENDING);
CHECK(pure_app_message(&app, 0, "k0", -1, (PureSpan){0}) == PURE_OK && app.revision == 2 && replied(&app, "abc"));
- CHECK(pure_app_message(&app, 0, "m16", -1, (PureSpan){0}) == PURE_NOT_FOUND);
- CHECK(pure_app_message(&app, 0, "m15", -1, (PureSpan){0}) == PURE_OK && replied(&app, "y"));
+ snprintf(key, sizeof(key), "m%d", PURE_APP_PENDING);
+ CHECK(pure_app_message(&app, 0, key, -1, (PureSpan){0}) == PURE_NOT_FOUND);
+ snprintf(key, sizeof(key), "m%d", PURE_APP_PENDING - 1);
+ CHECK(pure_app_message(&app, 0, key, -1, (PureSpan){0}) == PURE_OK && replied(&app, "y"));
pure_app_stop(&app);
remove_store(path);
}