Skip to content

perf(mail): build the throwaway-domain set once for every caller - #3349

Merged
leemour merged 1 commit into
mainfrom
perf/disposable-domain-check
Nov 25, 2026
Merged

leemour merged 1 commit into
mainfrom
perf/disposable-domain-check

Conversation

@leemour

@leemour leemour commented Nov 25, 2026

Copy link
Copy Markdown
Member

Task

Follow-up to #3347: its PR body noted that isDisposableEmailDomain (disposable-email-domains-js) builds its whole list on every call, and that src/mail/score.ts still called it once per sender.

Why

The library's isDisposableEmailDomain turns its array of about 9,000 domains into a new Set on each call. scoreGroup calls it for every sender group, so scoring a large mailbox spent most of its time rebuilding the same set.

What

  • src/mail/score.ts: new isDisposableDomain(domain), which builds the set once (disposableEmailBlocklistSet) on first use. scoreGroup uses it.
  • src/store/sqlite/domain-organizations.ts: its private cache from feat(people): organizations from mail domains #3347 is gone; companyDomainOf imports isDisposableDomain from the same module it already takes FREE_MAIL and registrableOf from.
  • Changelog fragment under "Fixed".

Decision (owner asleep): the shared helper lives in mail/score.ts, next to FREE_MAIL, rather than in a new module. Both callers already import from there. The input is not lower-cased or trimmed, unlike the library function: both callers pass registrableOf output, which is lower case already.

Testing

Measured, synthetic case: 20,000 senders, 3 emails each (every tenth at mailinator.com), scoreGroup over all of them, 5 runs in one process, vitest --maxWorkers=1, Node 24.19, 24 cores, load average about 5. The timing file was a throwaway test, not committed.

Runs (ms) Median
Before (origin/main) 8026, 7116, 6948, 6987, 7255 7.0 s
After 240, 209, 218, 208, 207 0.21 s

About 0.35 ms per sender before, 0.01 ms after (that is the whole score, not only the check).

  • New test in src/mail/score.test.ts: isDisposableDomain is true for mailinator.com and guerrillamail.com, false for gmail.com and a company domain. The existing disposable_domain signal test still passes.
  • src/mail/score.test.ts, src/store/domain-organizations.test.ts: 22 passed.
  • pnpm typecheck, pnpm lint (no new warnings), pnpm docs:check, pnpm schema:check.

🤖 Generated with Claude Code

isDisposableEmailDomain from disposable-email-domains-js builds its set of
about 9,000 domains on every call. scoreGroup called it once per sender, so
scoring 20,000 senders spent about 7 s on it. #3347 had already cached the
set inside domain-organizations.ts; the cache now lives in mail/score.ts as
isDisposableDomain, next to FREE_MAIL, and both callers use it.

Synthetic run, 20,000 senders of 3 emails each: 7.0 s -> 0.21 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leemour
leemour merged commit 8963d60 into main Nov 25, 2026
38 of 41 checks passed
@leemour
leemour deleted the perf/disposable-domain-check branch November 25, 2026 04:35
leemour added a commit that referenced this pull request Nov 25, 2026
#3350 stores the sector in organization metadata as `sector`, since
`category` already means client, supplier or partner. #3349 made the
throwaway-domain check one prebuilt set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant