Repository navigation
Highlights
This release reworks the dispatcher hot path so bulk campaigns no longer fsync per send, re-encode attachments per recipient, or hold every rendered body in RAM.
Performance
- Coalesced offset saves. Per-success disk writes are replaced with an in-memory contiguous high-water mark plus a 200ms flusher goroutine. Integration test shows ~2500× fewer disk saves under 16-worker concurrency. Microbench:
MarkComplete33 ns/op vs the oldUpdateOffset+Saveat 28 µs/op (842×). - Per-dispatch attachment cache (
email.AttachmentCache). A 5 MB PDF sent to 1M recipients is now read & base64-encoded once, not 1M times. Size-capped at 256 MiB by default with a streaming fallback. - Streaming task pipeline.
cli.StreamEmailTasks+email.StartDispatcherStreamlet the bulk path render and send concurrently. Memory drops from O(recipients × body) to O(buffer). The CLI uses streaming automatically; dry-run keeps the slice path. - Bulk monitor seed. New
monitor.Monitor.InitializePending([]string)registers all recipients in one lock acquisition instead of N per-recipientUpdateRecipientStatuscalls. - Misc. Fixed-order MIME header writes (no concat allocs, stable for DKIM), crypto/rand MIME boundaries,
wg.Add(concurrency)once, pre-allocated task slice.
Correctness fixes
- Resume under concurrency now persists a contiguous high-water mark. The previous code persisted
max(idx), so if worker B finished idx 50 while worker A was still on idx 30, the saved offset would be 51 — and on a crash + resume, idx 30 would be skipped. Fixed viaOffsetTracker.MarkComplete(idx). - Fixed
StartOffset + Index + 1double-count. On resume, the saved offset would jump by twice the resume baseline. Removed. - Skipped recipients no longer stall the high-water mark.
Indexis now sequential post-skip, not raw recipient position.
Caveat
Resume is correct under concurrency. It is not guaranteed correct under input mutation between runs — if a CSV row becomes invalid (or vice versa) before a resume, positional offset can shift. This was true before and remains so.
New / changed public API
email.StartDispatcherStream(ctx, taskCh <-chan Task, ...)— channel-based dispatchemail.AttachmentCache,NewAttachmentCache(maxBytes int64)email.OffsetTracker.MarkComplete(idx int)— interface change; external implementers ofOffsetTrackermust add this methodemail.DispatchOptions.AttachmentCache,OffsetSaveInterval,PendingEmailsmonitor.Monitor.InitializePending(emails []string)— interface change; external implementers must add this methodcli.StreamEmailTasks(...) (<-chan email.Task, <-chan error)
Tests
5 new MarkComplete tests (in-order, out-of-order, duplicate-below-offset, resume baseline, 1000-goroutine concurrent), 4 new AttachmentCache tests, 2 new flusher integration tests, plus benchmarks. Full suite passes under go test -race ./....
Full diff: v1.0.0...v1.1.0