Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions performance/people/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ Measurements of cli-core's people: who is listed, and how fast.
- [bots](bots/README.md): what moving programs off people costs (cli-core store version 75). With 20,000 program
senders, the first list holds the write lock for about 1 s, the upgrade from version 74 takes 0.3–3.2 s, and warm
pages of people and bots stay under 60 ms (2026-11-25).
- [newsletter-bots](newsletter-bots/README.md): what making senders of a newsletter only bots costs (cli-core
`feat/newsletter-bots`, owner's ruling of 2026-11-25). With 20,000 such senders, the check that gives a bot back after
a 1-to-1 mail costs 31–51 ms under the write lock on each kept list. The first list takes 3.2–13 s on a machine at
load 15 to 52 (2026-11-26).
63 changes: 63 additions & 0 deletions performance/people/newsletter-bots/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# People: what making newsletter-only senders bots costs the people list

## Why it was run

On 2026-11-25 the owner ruled that a sender who only sends a newsletter is a bot, even when a human writes it (an
author on a newsletter platform). Before, such a sender stayed a person with reach `broadcast`. cli-core branch `feat/newsletter-bots`
builds it. The first people list after the upgrade moves every such sender to a bot. Each later list also checks
whether a 1-to-1 mail or the owner's reply should give a newsletter bot back. Both run under the store's write lock,
and other writers wait for it for at most 5 s.

The questions:

1. How long does the first people list take on 20,000 newsletter senders?
2. What does the give-back check cost on each later list?

## Setup

- Machine: AMD Ryzen AI 9 HX 370 (24 threads), Linux 7.0, Node 24.19.0. Other agents' runs kept the load average at
15 to 52 during the runs, so the numbers vary a lot and are higher than on an idle machine.
- Code: cli-core branch `feat/newsletter-bots` (store version 77, no migration), built with `pnpm build`.
- Data, all synthetic:
- 20,000 newsletter senders `author<n>@letters<n % 400>.ru`, each with 2 mails that carry a List-Id and
List-Unsubscribe.
- 20,000 humans `person<n>@firm<n % 300>.ru`, each with 2 plain mails to the owner.
- The senders are saved through `store.people.savePeople`. The 80,000 mails are written straight into the store's
tables.
- With `lists` = 0, the newsletter senders' mail has no list headers, so nobody moves. That run measures the rule's
pass alone.
- The kept list nulls one person's stored kind and lists again, so `keep` and the give-back check run once.
- The give-back check alone is `ruleBotsBack` in a transaction that is rolled back, three times per run.

```sh
node bench.mjs <cli-core checkout> 20000 1 # newsletter senders become bots
node bench.mjs <cli-core checkout> 20000 0 # same mail, no list headers
```

## Results

| Step | 20,000 newsletter bots | No bots (lists = 0) |
| --- | ---: | ---: |
| first people list, 40,000 kinds worked out (5 runs / 5 runs) | 3.2–13.3 s, one run 91 s at load 48 | 2.1–10.6 s |
| warm people list, first 50 | 20–34 ms | 27–29 ms |
| bots list, first 50 | 18–39 ms | 1 ms |
| kept list after one stale kind | 0.6–3.7 s | 0.14–13.5 s |
| give-back check alone (`ruleBotsBack`), 6 timings | 31–51 ms | 0 ms |

## What it showed

- The give-back check, the one new step under the write lock on every kept list, costs 31–51 ms with 20,000
newsletter bots. That is far inside another writer's 5 s wait.
- The first list with 20,000 moves takes about as long as on the [bots](../bots/README.md) page (2.4–6.0 s for 20,000
program senders) once the load is moderate. The moves use the same code as there, where the write lock was held for
about 1 s.
- The kept list varies more with the machine's load than with the bots: a run with no bots took 13.5 s at load 18.
These numbers say nothing about the change itself.
- Warm pages stay under 40 ms.

## Not measured

- The time under the write lock during the first list. These runs did not time it. The bots page measured about
1 s for the same moves.
- An idle machine. Every run here shared the machine with other agents' builds and tests.
- Stores whose newsletter senders also have messenger identities or ties: the rule skips them before any mail is read.
111 changes: 111 additions & 0 deletions performance/people/newsletter-bots/bench.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Times the first people list when N senders of a newsletter only become bots (cli-core, owner's ruling of
// 2026-11-25), beside N humans who wrote to the owner directly. Usage: node bench.mjs <cli-core checkout> [N] [lists]
// `lists` = 0 seeds the same mail with no list headers, so nobody moves: the cost of the rule's pass alone.
import { mkdtempSync } from "node:fs"
import { loadavg, tmpdir } from "node:os"
import { join } from "node:path"

const repo = process.argv[2]
const N = Number(process.argv[3] ?? 20000)
const LISTS = process.argv[4] !== "0"
const MAILS = 2
const { openStore } = await import(join(repo, "dist/store/index.js"))
const { openCache } = await import(join(repo, "dist/store/open.js"))
const MAIL = { provider: "email", account: "me@acme.ru" }
const TG = { provider: "telegram", account: "1" }
const say = (line) => process.stdout.write(`${line}\n`)

const time = async (label, work) => {
const start = performance.now()
const result = await work()
say(`${label}: ${Math.round(performance.now() - start)} ms`)
return result
}

const seeded = async () => {
const path = join(mkdtempSync(join(tmpdir(), "newsletter-bots-")), "store.db")
const store = await openStore({ path })
await store.people.savePeople(TG, [{ id: "1", name: "Me" }])
await store.people.linkToOwner({ provider: "telegram", id: "1" })
await store.accounts.saveAccount(MAIL, { name: null })
const authors = Array.from({ length: N }, (_, n) => ({ id: `author${n}@letters${n % 400}.ru`, name: `Author ${n}` }))
const humans = Array.from({ length: N }, (_, n) => ({ id: `person${n}@firm${n % 300}.ru`, name: `Person ${n}` }))
const senders = [...authors, ...humans]
for (let at = 0; at < senders.length; at += 2000) await store.people.savePeople(MAIL, senders.slice(at, at + 2000))
await store.close()
const db = await openCache(path)
const account = db.prepare("SELECT id FROM accounts WHERE provider = 'email'").get().id
const identity = new Map(
db
.prepare("SELECT id, external_id FROM identities WHERE provider = 'email'")
.all()
.map((row) => [row.external_id, row.id]),
)
const thread = db.prepare(
"INSERT INTO email_threads (account_id, external_id, created_at, updated_at) VALUES (?, ?, 1, 1) RETURNING id",
)
const email = db.prepare(
"INSERT INTO emails (account_id, email_thread_id, external_id, from_identity_id, from_address, headers, outgoing, " +
"sent_at, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, 0, ?, 1, 1) RETURNING id",
)
const to = db.prepare(
"INSERT INTO email_recipients (email_id, address, role, position, created_at, updated_at) " +
"VALUES (?, 'me@acme.ru', 'to', 0, 1, 1)",
)
db.exec("BEGIN")
let m = 0
for (const [list, people] of [
[LISTS, authors],
[false, humans],
])
for (const { id } of people)
for (let k = 0; k < MAILS; k++) {
m += 1
const headers = list
? JSON.stringify({ "list-id": `<${id.split("@")[0]}.letters.ru>`, "list-unsubscribe": true })
: null
const t = thread.get(account, `t${m}`).id
to.run(email.get(account, t, `m${m}`, identity.get(id), id, headers, 1_790_000_000_000 + m).id)
}
db.exec("COMMIT")
db.close()
return { path, mails: m }
}

say(
`node ${process.version}, N = ${N}, lists ${LISTS}, load ${loadavg()
.map((x) => x.toFixed(1))
.join(" ")}`,
)
const { path, mails } = await seeded()
say(`seeded ${2 * N} senders, ${mails} mails`)
const store = await openStore({ path })
await time(`first people list, ${2 * N} kinds worked out`, () => store.people.list({ limit: 50 }))
await time("warm people list, page of 50", () => store.people.list({ limit: 50 }))
const bots = await time("bots list, page of 50", () => store.people.listBots({ limit: 50 }))
await store.close()
{
const db = await openCache(path)
db.prepare(
"UPDATE persons SET kind = NULL WHERE id = (SELECT max(id) FROM persons WHERE owner = 0 AND kind <> 'merged')",
).run()
db.close()
}
const again = await openStore({ path })
await time("kept list after one stale kind, with every bot checked for a 1-to-1 mail", () =>
again.people.list({ limit: 50 }),
)
say(
`bots: ${bots.total}, newsletter-only: ${bots.items.filter((bot) => bot.reason === "newsletter-only").length} of the page`,
)
await again.close()
{
const { ruleBotsBack } = await import(join(repo, "dist/store/sqlite/sender-bots.js"))
const db = await openCache(path)
for (let k = 0; k < 3; k++) {
db.exec("BEGIN IMMEDIATE")
await time("give-back check alone (ruleBotsBack), under the write lock", () => ruleBotsBack(db, Date.now()))
db.exec("ROLLBACK")
}
db.close()
}