Skip to content

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

Open
jstedfast wants to merge 1 commit into
masterfrom
unix2dos-indexof
Open

Optimized Unix2DosFilter to use Span<T>.IndexOf() and CopyTo()#1163
jstedfast wants to merge 1 commit into
masterfrom
unix2dos-indexof

Conversation

@jstedfast
Copy link
Copy Markdown
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
Copy Markdown

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