Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
Where the time goes, per request type (measured with profile_requests.py)
Measurement only. Nothing in the server was edited; the script monkeypatches its own process and lives in temp dirs. Reproduce: .venv-jit/bin/python scripts/bench/experiments/profile_requests.py --compare 10,1000 --budget 1.0 --out r.txt --json r.json (--whatif --users N, --micro for the follow-up experiments; --from-json re-prints a saved run).
Setup
- In-process through the real ASGI app (persistent event loop, no HTTP server), signed-in NON-admin user via Bearer session token, enforcement ON.
- 57 packages installed in dependency order (every package under
packages/exceptadmin-write-probeandhello-world; all installed cleanly): 102 schemas, 246 permission rules, ~160 objects.
Seeded per user: 3 sessions, 2 projects, 3 project grants, 10 notes, 2 orders x 3 lines, 1 invoice x 2 lines, 3 contacts, 3 tasks.
- Flags:
DBBASIC_ENABLE_EVENT_HANDLERS=true(HANDLES objects),DBBASIC_ENABLE_RECORD_EVENTS=true(durable event log, default on), realtime on (default, no subscribers), site routes on. The event log is prefilled to its 1000-row retention cap so a publish pays the steady-state price. - Fan-out proven to run, not assumed: an order-line create moved the order total 3000 -> 4000 (
system_order_totalsfired); a payment with a negative amount was rejected 400 by the schema-wiredhook_payments; a payment create re-triggered the invoice rollup (payments_received_cents= 1); a payment create executes 6 objects (the hook + 5 HANDLES handlers: books, gift_card_issue, invoice_status, record_conversion, shop_fulfillment). - Every response is checked for status AND body shape on every repetition (e.g. list must return exactly 20 rows and no foreign rows; the page must carry
VIEW_ID='view_notes'and this viewer's id; search must have notes hits). No request in the tables below is an error path. Zero checks failed. - Method per request: (a) bare wall time, nothing patched (best / median of N, N = 5..100 sized to a time budget); (b) perf_counter exclusive-time wrappers around ~50 functions (+ audit hook for file opens) for the stage breakdown, 1.04-1.10x wrapper overhead; (c) cProfile with the wrappers switched off (inflates call-heavy code 2.3-6x, so it is used for call counts and for cross-checking the wrapper numbers, not for percentages).
- Noise: shared machine (another agent was running tests). Two independent 10-user runs agreed within ~3% (list 10.6 / 10.2 ms, asset 41.9 / 40.9 ms, payment create 41.9 / 40.6 ms). At 1000 users the slowest cases got only n = 5 repetitions (list, anon rows, search), their best-vs-median spread was < 4%.
Finding about the existing bench
scripts/bench/multiuser.py create_note POSTs {"content": "bench note"} with no owner_id. With enforcement on that is 403 "no matching role rule" (the permission check runs on the submitted record BEFORE the server stamps owner_id; the generated form always sends owner_id). oha reports latency for 403s, so that bench's create number is a refusal path. This script sends owner_id like the form does.
Wall time per request, bare (median ms; best within 5% everywhere)
| request | 10 users | 1000 users | growth |
|---|---|---|---|
| floor: GET /health | 0.06 | 0.06 | 1x |
| 1 list notes limit=20 | 10.2 | 375.6 | 37x |
| 2 get one note | 2.3 | 3.1 | 1.3x |
| 3 create note | 16.2 | 38.6 | 2.4x |
| 4 update note | 20.1 | 44.3 | 2.2x |
| 4 delete note | 17.4 | 40.8 | 2.3x |
| 5 order line create (HANDLES order_totals) | 37.3 | 93.2 | 2.5x |
| 5 order line update | 41.9 | 98.1 | 2.3x |
| 5 order line delete | 30.3 | 66.4 | 2.2x |
| 5b payment create (hook + rollup + 5 handlers) | 40.6 | 50.5 | 1.2x |
| 5b payment update | 32.8 | 44.4 | 1.4x |
| 5b payment delete | 20.6 | 28.7 | 1.4x |
| 5c contact create (computed full_name) | 16.6 | 28.5 | 1.7x |
| 6 page GET /notes (signed in, HTML) | 93.4 | 94.8 | 1.0x |
| 7 search q=note | 345 | 1092 | 3.2x |
| 8 GET /api/schema/notes | 0.15 | 0.15 | 1x |
| 8 GET views/view_notes | 2.5 | 3.1 | 1.2x |
| 8 GET notes?limit=500 (the list block's own fetch) | 10.3 | 364.7 | 35x |
| 8 GET projects?limit=500 (relation labels) | 3.4 | 76.5 | 22x |
| 8 GET /objects/action_nav_entries | 4.7 | 6.4 | 1.4x |
| 8 GET views?limit=200 | 7.0 | 7.8 | 1.1x |
| 8 GET entities?limit=200 / notifications?limit=50 / prefs | 2.4 / 2.4 / 1.1 | 3.2 / 3.1 / 1.8 | ~1.3x |
| 8 nine page assets (/style /markdown /list /form /detail /thread /attachments /share /nav), each | 39.5-40.9 | 41.6-42.3 | 1.0x |
| 9 anonymous public page /notes | 92.6 | 91.7 | 1.0x |
| 9 anonymous public rows (3 rows returned) | 5.3 | 347.6 | 66x |
Opening /notes in a browser = HTML + 9 assets + 9 data calls (read from the served HTML/JS, not by running a browser): 486 ms of server time at 10 users, 938 ms at 1000 (assets alone 358 / 376 ms; assets send no Cache-Control/ETag/Last-Modified and no conditional-request handling, so each page view re-executes them; that last bit is inferred browser behaviour).
Ranked hot spots (all requests)
Percentages are shares of the request as measured with the wrappers; "what-if" numbers are MEASURED with the cheapest plausible patch monkeypatched into the profiling process (response bytes identical to baseline for 8 read requests).
| # | hot spot | evidence | kind | what fixing saves | risk |
|---|---|---|---|---|---|
| 1 | A schema-less collection name makes get_schema run object_collections.list_collections(): a full object scan (rglob 160 files, one get_object_state read per object, log probing, policy parse) = 35.7 ms per occurrence. Hit by _site_host_records() on EVERY site-route request (collection site_hosts has no schema and no records), by site_routes on pages, and 7x per search (object categories action hook site system triggers webhook + site_routes returned by list_schemas). | asset: 160 get_object_state calls, 38+29+20% of 42 ms; page 3 dir scans; search 8 list_collections; micro: read_collection_records('site_hosts') 35.6 ms vs 0.25 ms for a collection that has a schema | algorithmic (repeated full scan to answer "does this collection exist") | assets 42 -> 4.3 ms (-90%), page 94 -> 24 ms (-75%), page bundle ~ -80% of the fixed part, search 345 -> 188 ms (10u, with #2) | site_hosts short-circuit is exact (low); a general negative/derived-schema cache is moderate (collection "known-ness" also comes from objects and permission rules) |
| 2 | iter_object_sources = rglob("*.py") + sort + per-file resolve on every call: 15.8 ms. Used by list_collections (#1) and by resolve_object_id on a MISS: the convention probe site_notes for /notes misses and scans, so every page routed through the site_routes table (/notes, /orders/{id}, /views/{id}...) pays it | page: 3 scans = 47 of 98 ms; asset 1 scan = 37% | algorithmic (no cache; result depends only on which files exist) | with #1 fixed: page 89 -> 42 ms by itself, search -40% | low (invalidate on directory mtimes) |
| 3 | _rollup_parents_for_source runs on EVERY write and calls get_schema for all 102 schemas to find rollup parents | 7.7 ms/call micro; 8.2-8.6 ms incl per plain write (46% of a 10-user note create, 20% at 1000u); 3 invocations in an order-line write (24.6 ms, 61%) | algorithmic (O(#schemas) per write, answer changes only when a schema changes) | ~7.7 ms of every write alone; after #4 only 0.3-2.4 ms remains | low (memo keyed by schemas-dir mtime) |
| 4 | get_schema costs 71 us even on a cache hit (4 Path.resolve() + 3 stats for a path-safety check on an already-validated name; a hit could be 1 stat = 5 us) | 49 calls per list (34% of a 10-user list), 115-127 per plain write (43-50%), 224-346 per order-line/payment write (up to 62%), 54 per views list (53%); per-visible-row redaction calls it per row, which is why _redact_records_for_permission costs ~110 us/row of which only ~35 is check_permission | repeated work | measured: list 10.4 -> 6.7 ms (-36%), note create 16.3 -> 8.2 (-50%), order-line create 38 -> 14.5 (-62%), views list -55%, payment create -44% | low |
| 5 | check_permission once per row of the whole collection (known #1): 36 us/call, 87% of it the rule scan (24.7 us with 246 rules vs 3.3 us narrowed to the 3 relevant ones) | list 1000u: 10,044 calls = 94% (367 ms); anon public rows 94%; load notes?limit=500 94%; projects labels 88%; search 21,136 calls = 66% (762 ms); 10u list 42% | algorithmic O(rows x rules) | 330+ ms of 375 at 1000u, grows linearly with rows; narrowing rules alone ~ -85% of the engine cost | medium-high (permission semantics; another agent is editing the engine) |
| 6 | load_policy re-parses policy.json and rebuilds 246 rules per call, 1-3 calls per request | 0.98 ms/call; get_note 41%, view record 41%, nav bell/entities 38-40% of 10-user requests; 3 calls in an update, 3 on a page | missing cache | measured: get_note 1.89 -> 0.84 ms (-55% on top of #4); every request -0.9..-3 ms | low (stat-keyed; frozen dataclass) |
| 7 | Identity resolved 2-5x per request, each = 3 read_collection_records (project_access, projects, record_shares: every call copies all rows, and record_shares is a collection with a schema but no records file) plus a session lookup | 0.8 ms (10u) -> 1.7 ms (1000u) per resolution; get_note 30% -> 49%; updates 3.3 / 6.7 ms (14-15%), payment update 9.7 ms (20% at 1000u) | repeated work + O(users) | 2-8 ms per write at 1000u, grows with users (about +0.9 us per user per resolution); get_note ~ -45% | low-medium (per-request memo; must not outlive a grant change) |
| 8 | Classic-mode persist_write rewrites the whole TSV | notes 725 KB: 21 ms = 51% of a create at 1000u; order-line create 54 ms (3 rewrites: line, order via the handler, ...) = 54%; contacts 11 ms | O(file size), inherent to classic mode | ~20 ms per write at 1000u (-50%), grows with rows; append mode already exists | operational (storage migration), code risk low |
| 9 | Durable event log publish rewrites a 1000-row file per write | micro: 0.4 ms at 0 rows, 0.67 at 100, 1.76 at 500, 3.07 at 1000 (306 KiB file); 16% of a 10-user note create, 7% at 1000u; in every write | O(log size) up to the retention cap | ~2.5 ms per write | medium (daemon/pollers read this file) |
| 10 | Objects are re-imported on every execution (_load_module: read + compile + exec), 0.8-0.95 ms each, and each execution also appends an execution log under a flock | payment create runs 6 objects = 4.4 ms (10%) + their log appends; nav entries 17%; page 0.8 ms; compile SyntaxWarning re-emitted per load | missing mtime-keyed module cache | ~4 ms per payment write | medium (objects may rely on fresh module state) |
| 11 | Search shape: reads and row-filters every searchable collection (55 collection reads, ~21k permission checks at 1000u) + 8 full scans (#1) | 1.09 s at 1000u, 345 ms at 10u (75% of it #1/#2 + get_schema) | algorithmic | covered by #1, #2, #5 | - |
| 12 | Permission audit log: one audit.jsonl append per permission check (1 per request, 55 per search), never rotated | open-audit shows W permissions/audit.jsonl x1 on every request | unbounded growth (disk), time cost small | n/a (not time) | low |
Not hot (measured): session lookup (cached) 0.06 ms = 0.6% of a list, 1-5% of the cheap calls; change-log latest lookup 0.2 ms (+0.2 ms with 50,000 prior entries per collection, so the tail read really is O(1)); schema validation, computed fields, transition checks, realtime publish (no subscribers) all < 1% each; the ASGI/driver floor is 0.06 ms; routing's long if-chain is inside the "other" 1-3%.
What-if (cumulative patches, median ms bare, --whatif)
10 users: list 10.4 -> 5.7, get 2.3 -> 0.86, note create 16.3 -> 7.5, update 20.0 -> 8.8, order-line create 38.3 -> 12.0, update 43.4 -> 13.4, payment create 41.0 -> 20.4, page 94.2 -> 22.5, asset 40.4 -> 2.7, search 347 -> 188, views list 7.0 -> 2.1, anon rows 5.3 -> 3.8. 1000 users: list 357 -> 351 (only #5 matters), note create 38.3 -> 29.1 (the rest is #8), order-line create 93.9 -> 66.3, payment create 51.0 -> 30.2, page 96.2 -> 24.3, asset 42.3 -> 4.3, search 1072 -> 914, anon rows 337 -> 335. (c1 get_schema cache, c2 load_policy cache, c3 rollup-parents memo, c4 object-sources cache, c5 site_hosts short-circuit.) The order-line delete row is noisy (14.6 -> 17.2 at c4/c5 at 10u): single-run medians on a shared machine.
Which stages scale with data or users (10 -> 1000 users)
check_permissioncalls per list: 143 -> 10,044 (O(rows); the row count also driveslist.row filter,compute_record_revstays at 20 = the window).persist_write: 0.6 -> 21 ms per notes write (O(file)); 1.7 -> 54 ms per order-line create.- identity scans (project_access / projects / record_shares): 0.016 -> 0.26 ms per resolution on top of 0.7 ms constant (3 cached reads that each copy their rows).
read_collection_records: 0.6 -> 2.2 ms per list (it copies every row of every collection it reads, also on a cache hit).- Constant in users (but large): get_schema calls, load_policy, event-log publish, rollup-parent scans, object loads, iter_object_sources,
get_object_statex160.
Per-request counts (calls per request, 10u / 1000u where they differ)
| request | read_collection_records | check_permission | identity resolutions | load_policy | get_schema | json.loads | os.stat | file opens R/W | object loads |
|---|---|---|---|---|---|---|---|---|---|
| list notes | 4 | 143 / 10044 | 1 | 1 | 49 / 50 | 1 | 165 | 1 / 1 | 0 |
| get note | 3 | 1 | 1 | 1 | 6 | 1 | 34 | 1 / 1 | 0 |
| note create | 6 | 1 | 2 | 1 | 120 | 1004 | 402 | 4 / 5 | 0 |
| note update | 12 | 3 | 4 | 3 | 127 | 1006 | 449 | 6 / 6 | 0 |
| note delete | 9 | 2 | 3 | 2 | 115 | 1004 | 398 | 5 / 5 | 0 |
| order-line create | 7 | 1 | 2 | 1 | 339 | 1004 | 1110 | - | 1 |
| payment create | 25 | 1 | 3 | 1 | 268 | 1037 | 1033 | - | 6 |
| page /notes | 9 | 1 | 2 | 3 | 11 | 3 | 1130 | 6 / 5 | 1 (+ 319 get_object_state, 3 dir scans) |
| asset /style | 7 | 1 | 2 | 2 | 9 | 2 | 588 | 4 / 3 | 1 (+ 160 get_object_state, 1 dir scan) |
| search | 55 | 346 / 21136 | 1 | 9 | 324 | 9 | 5693 | 9 / 55 | 0 (+ 1272 get_object_state, 8 dir scans) |
| anon public rows | 1 | 104 / 10004 | 1 | 1 | 6 | 1 | 25 | 1 / 1 | 0 |
(Writes parse ~1000 JSON values because load_policy and the event/state files are JSON/TSV parsed per request; a plain write opens 4-6 files for read and 5-6 for write/append: collection file + lock + tmp, change log read + append, event-state, audit log.)
Measured vs inferred, and what did not work
- Measured: everything in the tables, the micro and what-if numbers. Stage percentages come from perf_counter wrappers (cProfile agreed on ordering everywhere I compared; it is reported in the raw output only for call counts).
- Inferred: browser behaviour (the page's call list comes from reading the served HTML/JS, not from running it;
/ws, realtime subscription and any call made only after user interaction are not included;/api/flagsis not requested by the loaded scripts); that missing cache headers make browsers refetch the assets; the 10k-user extrapolations (linear scaling of the O(rows)/O(users) terms was observed between 10 and 1000, not tested beyond). - Did not run / not covered: real HTTP and TLS, concurrency (everything single-threaded), the daemon passes, analytics (off by default), packages' schemas other than the ones driven.
DBBASIC_OBJECT_TIMEOUT_SECONDSis unset (in-process objects). Event-handler dispatch was verified for order lines and payments only; invoice-line writes were not driven. - Everything installed; no package failed. No handler failed to fire. The one surprise was the 403 on creates without
owner_id(above), found while building the harness.
After (2026-11-29, at 0d564b2)
Same script, same 57 packages and seed, --budget 1.0 --no-cprofile, one subprocess per size (--users 10 and --users 1000, then --from-json to combine; --compare needs .venv-jit inside the checkout). Median ms, bare wall time; "before" is the table above (c145348). Every response was status- and shape-checked as before.
| request | before 10u | after 10u | before 1000u | after 1000u |
|---|---|---|---|---|
| 1 list notes limit=20 | 10.2 | 6.1 | 375.6 | 403.4 |
| 2 get one note | 2.3 | 0.63 | 3.1 | 0.65 |
| 3 create note | 16.2 | 6.1 | 38.6 | 26.9 |
| 4 update note | 20.1 | 6.8 | 44.3 | 28.2 |
| 4 delete note | 17.4 | 6.3 | 40.8 | 27.6 |
| 5 order line create | 37.3 | 10.7 | 93.2 | 67.5 |
| 5 order line update | 41.9 | 12.3 | 98.1 | 68.3 |
| 5 order line delete | 30.3 | 12.8 | 66.4 | 45.9 |
| 5b payment create | 40.6 | 18.8 | 50.5 | 27.7 |
| 5c contact create | 16.6 | 6.9 | 28.5 | 16.9 |
| 6 page GET /notes (signed in) | 93.4 | 3.0 | 94.8 | 2.9 |
| 7 search q=note | 345 | 26.7 | 1092 | 859 |
| 8 GET views?limit=200 | 7.0 | 2.2 | 7.8 | 2.4 |
| 8 GET projects?limit=500 | 3.4 | 1.35 | 76.5 | 79.4 |
| 8 page asset, each (9 per page) | 39.5-40.9 | 1.65-2.5 | 41.6-42.3 | 1.6-2.8 |
| 9 anonymous public page /notes | 92.6 | 2.6 | 91.7 | 2.3 |
| 9 anonymous public rows | 5.3 | 4.2 | 347.6 | 371.7 |
| /notes page load (html + 9 assets + 9 data calls) | 486 | 33.4 | 938 | 507 |
- What is left is the two O(data) items that were not touched:
check_permissiononce per row of the whole collection (#5: still 95% of a 1000-user list, of the notes?limit=500 and projects?limit=500 loads and of anonymous rows, and most of search), and classic-modepersist_writerewriting the whole TSV (#8: 21 ms of a 1000-user note write, 75%). The 1000-user list / anon-rows medians are within this shared machine's run-to-run noise of before. - Payment update and delete are no longer measured:
hook_paymentsnow refuses both (409 "money moves, it does not mutate"), a package change made on this branch by other work, so those rows have no after number. - One identity resolution, session lookup included, is now 0.33 ms at 10 users and 0.31 ms at 1000 (it was 0.8 -> 1.7 ms and grew with users), measured with the stage wrappers.
- Page assets are 1.6-2.8 ms each because the full object scan per request (#1, #2) is gone; they still send no cache headers and run their object every time, deliberately. An ETag/304 would save bytes but none of this time (the object must run to know the body). A freshness lifetime (
Cache-Control: max-age) would stop the re-execution but would keep serving an old /style after a theme switch and old /list after a package upgrade, the stale-script failure_html_cache_headerswas written for, and objects cannot set cache headers themselves by design (_object_set_cookie_headers). A server-side cache of object output is not provably correct: an object's output may depend on its state, records, the viewer and the clock, and the platform cannot see which.