Skip to content

Optimized Unix2DosFilter to use Span<T>.IndexOf() and CopyTo() #1163

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

Unfortunately, this optimization is not all rainbows and sunshine.

For short lines, and especially the pathological cases where the input is nothing but "\n\n\n\n..." or "\r\n\r\n\r\n...", performance really suffers with this patch (as seen in the benchmark results below).

Holding off on merging this until I can think up a better solution that is better in all cases (or at least not significantly worse in the pathological cases).

BenchmarkDotNet v0.14.0, Windows 11 (10.0.26100.3775) Intel Core i7-9700 CPU 3.00GHz, 1 CPU, 8 logical and 8 physical cores .NET SDK 9.0.300-preview.0.25177.5
[Host] : .NET 8.0.15 (8.0.1525.16413), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.15 (8.0.1525.16413), X64 RyuJIT AVX2

Method Mean Error StdDev
Unix2Dos_LoremIpsumDos 4,042.9 ns 50.29 ns 47.04 ns
Unix2Dos_LoremIpsumUnix 2,642.5 ns 47.31 ns 66.33 ns
Unix2Dos_PathologicalDos 2,296.2 ns 25.69 ns 22.77 ns
Unix2Dos_PathologicalUnix 1,349.1 ns 15.80 ns 13.19 ns
Unix2Dos2_LoremIpsumDos 616.8 ns 12.10 ns 13.45 ns
Unix2Dos2_LoremIpsumUnix 588.5 ns 10.54 ns 8.80 ns
Unix2Dos2_PathologicalDos 7,154.4 ns 122.12 ns 114.23 ns
Unix2Dos2_PathologicalUnix 5,717.4 ns 71.87 ns 63.71 ns

Unfortunately, this optimization is not all rainbows and sunshine.

For short lines, and especially the pathological cases where the input is
nothing but "\n\n\n\n..." or "\r\n\r\n\r\n...", performance really suffers
with this patch (as seen in the benchmark results below).

Holding off on merging this until I can think up a better solution that
is better in all cases (or at least not significantly worse in the
pathological cases).

BenchmarkDotNet v0.14.0, Windows 11 (10.0.26100.3775)
Intel Core i7-9700 CPU 3.00GHz, 1 CPU, 8 logical and 8 physical cores
.NET SDK 9.0.300-preview.0.25177.5
  [Host]     : .NET 8.0.15 (8.0.1525.16413), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.15 (8.0.1525.16413), X64 RyuJIT AVX2

| Method                     | Mean       | Error     | StdDev    |
| ---------------------------|-----------:|----------:|----------:|
| Unix2Dos_LoremIpsumDos     | 4,042.9 ns |  50.29 ns |  47.04 ns |
| Unix2Dos_LoremIpsumUnix    | 2,642.5 ns |  47.31 ns |  66.33 ns |
| Unix2Dos_PathologicalDos   | 2,296.2 ns |  25.69 ns |  22.77 ns |
| Unix2Dos_PathologicalUnix  | 1,349.1 ns |  15.80 ns |  13.19 ns |
| Unix2Dos2_LoremIpsumDos    |   616.8 ns |  12.10 ns |  13.45 ns |
| Unix2Dos2_LoremIpsumUnix   |   588.5 ns |  10.54 ns |   8.80 ns |
| Unix2Dos2_PathologicalDos  | 7,154.4 ns | 122.12 ns | 114.23 ns |
| Unix2Dos2_PathologicalUnix | 5,717.4 ns |  71.87 ns |  63.71 ns |
@coveralls
Copy link

Coverage Status

coverage: 94.826% (+0.004%) from 94.822%
when pulling 648dc99 on unix2dos-indexof
into 9175336 on 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