Skip to content

Scan for MIME boundaries and base64 whitespace a word at a time (no new dependencies) - #143

Open
kurok wants to merge 1 commit into
staktrace:masterfrom
kurok:memmem-boundary-search
Open

Scan for MIME boundaries and base64 whitespace a word at a time (no new dependencies)#143
kurok wants to merge 1 commit into
staktrace:masterfrom
kurok:memmem-boundary-search

Conversation

@kurok

@kurok kurok commented Aug 28, 2026

Copy link
Copy Markdown

find_from_u8 and the whitespace strip in decode_base64 tested one byte at a time and dominated parse_mail on messages with large attachments. Both now scan a usize at a time using the haszero/hasless bit tricks — plain std, no unsafe, no new dependencies (this replaces #142, which added memchr).

Semantics are unchanged; the new tests compare both functions against the old loops over every byte value and alignment.

Full parse of a 767 KiB message with four base64 attachments, measured from a dependent crate:

before after
full parse 1.09 ms 0.23 ms
structure-only parse 0.37 ms 0.03 ms

@staktrace

Copy link
Copy Markdown
Owner

Thanks, this is something I could conceivably accept. However I'm having a really hard time following the code comments, can you please rewrite them in your own words instead of having the agent generate them?

@kurok

kurok commented Aug 28, 2026

Copy link
Copy Markdown
Author

Sure, wait a 10 minutes

find_from_u8 and the whitespace strip in decode_base64 tested one byte at a time
and dominated parse_mail on messages with large attachments. Both now scan a
usize at a time using the haszero/hasless bit tricks, in plain std, no unsafe.
Semantics unchanged; tests compare both against the old loops over every byte
value and alignment. Full parse of a 767 KiB message: 1.09 ms -> 0.23 ms.

Signed-off-by: kurok <22548029+kurok@users.noreply.github.com>
@kurok
kurok force-pushed the memmem-boundary-search branch from 2449fdb to abb3319 Compare August 28, 2026 10:53
@kurok

kurok commented Aug 28, 2026

Copy link
Copy Markdown
Author

Rewrote the comments and trimmed the commit message / description. Hopefully easier to follow now.

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