Skip to content

perf(smtp-server): shrink_to_fit() data buffers at the end of DATA command - #267

Merged
link2xt merged 1 commit into
mainfrom
link2xt/shrink_to_fit
Oct 22, 2026
Merged

link2xt merged 1 commit into
mainfrom
link2xt/shrink_to_fit

Conversation

@link2xt

@link2xt link2xt commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

shrink_to_fit() is generally a bad idea because it likely reallocates memory and copies the whole buffer once, but if we keep max_size allocated (30 MB currently, but we want to change to 50 MB in chatmail/relay#1052) for each message, then a single worker with full queue will use 1.5 GB of memory. Pre-allocating to max_size and then shrinking once is likely still better than growing the buffer from zero each time.

Follow-up to #264, commented there: https://github.com/chatmail/filtermail/pull/264/changes#r4347363381

…mmand

shrink_to_fit() is generally a bad idea because it likely reallocates memory
and copies the whole buffer once, but if we keep max_size allocated
(30 MB currently, but we want to change to 50 MB in chatmail/relay#1052)
for each message, then a single worker with full queue will use 1.5 GB of memory.
Pre-allocating to max_size and then shrinking once is likely still better
than growing the buffer from zero each time.
@link2xt
link2xt marked this pull request as ready for review October 22, 2026 11:16
@link2xt
link2xt merged commit c7c4334 into main Oct 22, 2026
7 checks passed
@j-g00da
j-g00da deleted the link2xt/shrink_to_fit branch October 22, 2026 11:37
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.

2 participants