Skip to content

[WIP] Refactored MimeReader to use ReadOnlySpan<byte> instead of unsafe byte* #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jstedfast
Copy link
Owner

The main advantage of this change is to make the code a bit nicer. The AsyncMimeReader code, especially, becomes a lot nicer with this change.

The other advantage is that Spans don't interfere with the GC like pinned memory buffers do, which could theoretically mean that using MimeReader is less likely to result in memory fragmentation (although not sure on the real-world consequences of the previous code in practice).

The downside is that ReadOnlySpan.IndexOf() is slower than the current implementation on .NET Framework and possibly also even .NET Core where the platform architecture does not have support for SIMD.

That's why this PR is a Work-In-Progress and not yet merged to master.

@coveralls
Copy link

coveralls commented May 4, 2025

Coverage Status

coverage: 94.812% (-0.02%) from 94.827%
when pulling 2c6ea3c on mimereader-span
into 1921c1b on master.

The main advantage of this change is to make the code a bit nicer. The
AsyncMimeReader code, especially, becomes a lot nicer with this change.

The other advantage is that Spans don't interfere with the GC like pinned
memory buffers do, which could theoretically mean that using MimeReader is
less likely to result in memory fragmentation (although not sure on the
real-world consequences of the previous code in practice).

The downside is that ReadOnlySpan<byte>.IndexOf() is *slower* than the
current implementation on .NET Framework and possibly also even .NET Core
where the platform architecture does not have support for SIMD.

That's why this PR is a Work-In-Progress and not yet merged to master.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Improvements to speed or memory consumption
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants