Skip to content

Batch and throttle tantivy commits to stop churning DB#187

Open
ara4n wants to merge 2 commits into
mainfrom
matthew/commit-cadence
Open

Batch and throttle tantivy commits to stop churning DB#187
ara4n wants to merge 2 commits into
mainfrom
matthew/commit-cadence

Conversation

@ara4n

@ara4n ara4n commented Jun 24, 2026

Copy link
Copy Markdown
Member
  • The tantivy index goes through a full read->decrypt->update->encrypt->write cycle every time it's updated, which can solidly chew a load of disk and CPU; instead, batch the updates to once a minute (or 20,000 updates, whichever comes first)
  • Also, only reload the index when needed.

Fixes bits of element-hq/element-web#32119

ara4n and others added 2 commits June 24, 2026 12:50
Tune the Tantivy commit cadence for power rather than latency:

- COMMIT_TIME 5s -> 60s: during idle/backfill we now flush accumulated
  events into searchable segments roughly once a minute instead of every
  few seconds, so the CPU can race to idle between bursts (far fewer
  fsyncs and segment merges). Search freshness is unaffected because the
  search path force-commits first.
- COMMIT_RATE 500 -> 20000: at network-paced backfill (/messages is the
  bottleneck) the old count cap fired every few seconds and produced ~15
  small segments per minute, each carrying its own AES + HMAC-SHA256
  finalization, file opens and eventual merge. Letting ~a minute's worth
  of events coalesce into one segment cuts that per-segment overhead by
  ~10x. The value sits within the writer heap, which self-flushes if it
  fills first, so it can't overrun memory.

Durability is unchanged: events and checkpoints still commit to SQLite
per batch and are replayed from the uncommitted_events table on restart.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JP4yoxKeGLRDLkCPTu3DFq
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