iterate.com / kernel

git clone https://git.iterate.com/repos/kernel

The catalog counts the rows that SQLite reads and writes for it

`itx.contexts.watches()` answers the engine's counters. Two more: the rows read and written by
its statements, index entries too, which is what a Durable Object is billed by. So what a
watched catalog costs a mind is read from the mind itself.

Session: agy b859a067-e1f8-4f91-8d14-337c9a19b40b on beelink
Worker: claude 02c7d409-d06c-4792-af54-c1861507c2e0 on beelink

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NCuxgWcYQGgMn3WtDburVD

Jonas Templestein, 2026-11-26 22:47 UTC · f4b4eff8a302af46d6754f8ccbdd1f635c325070 · parent b942a1a

2 files changed

M core/itx/src/context/reactive-catalog.ts
@@ -408,6 +408,10 @@
 
   counters = {
     statements: 0,
+    /** Rows that SQLite read and wrote for those statements, index entries too: what a Durable
+     *  Object is billed by. */
+    rowsRead: 0,
+    rowsWritten: 0,
     writes: 0,
     /** Writes of a row equal to the stored one. */
     sameWrites: 0,
@@ -513,7 +517,11 @@
 
   #exec<T extends Record<string, SqlStorageValue>>(sql: string, ...args: unknown[]): T[] {
     this.counters.statements += 1;
-    return this.#sql.exec<T>(sql, ...args).toArray();
+    const cursor = this.#sql.exec<T>(sql, ...args);
+    const rows = cursor.toArray();
+    this.counters.rowsRead += cursor.rowsRead || 0;
+    this.counters.rowsWritten += cursor.rowsWritten || 0;
+    return rows;
   }
 
   /** Memory that no longer matches SQLite (a transaction that threw) is read again. */
M core/lib/src/api.ts
@@ -1930,8 +1930,9 @@
     rev: number;
     watchers: number;
   }[];
-  /** What the catalog did since it last woke: writes, the writes that changed no window, seeks,
-   *  messages and characters sent. */
+  /** What the catalog did since it last woke: statements with the rows that SQLite read and
+   *  wrote for them (what the object is billed by), writes, the writes that changed no window,
+   *  seeks, messages and characters sent. */
   counters: Record<string, number>;
   /** With `{ verify: true }`: each window whose stored size or bound disagrees with the rows. */
   faults?: string[];