Decode base64/quoted-printable a block at a time#62
Open
iliaal wants to merge 1 commit into
Open
Conversation
Transfer-decoding during extraction ran one byte through two function pointers (the per-char filter function and its output callback) and a smart_string append for every output byte. For a multi-megabyte base64 or quoted-printable body that is millions of indirect calls. Add buffer-at-a-time decoders that consume a whole input block in one loop and append decoded bytes straight to the work buffer, using the filter's status/cache as the carry state between blocks. The output is byte-for-byte identical to the per-char path. php_mimepart_decoder_feed and _finish now use these; the now-unused filter_into_work_buffer output callback is removed. The per-char encode path used by mailparse_stream_encode is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Transfer-decoding during extraction ran every input byte through two function pointers (the per-char filter function and its output callback) plus a
smart_stringappend per output byte. For a multi-megabyte base64 or quoted-printable body that is millions of indirect calls.This adds buffer-at-a-time decoders (
mb_convert_filter_feed_block/_flush_block) that consume a whole input block in one tight loop and append decoded bytes straight to the work buffer, reusing the filter'sstatus/cacheas the carry state between blocks. The decoded output is byte-for-byte identical to the per-char path.php_mimepart_decoder_feed/_finishnow use them, and the now-unusedfilter_into_work_bufferoutput callback is removed. The per-char encode path used bymailparse_stream_encodeis unchanged.Verified byte-identical output against the current
masterbuild across 61 base64/QP cases (padding variants, embedded whitespace, invalid chars, partial quartets, soft line breaks, lower/upper hex, all 256 byte values), plus 4000 random round-trips. Decoding a 16 MB base64 body in a debug build went from 349 ms to 197 ms (~1.8x).