Skip to content

Commit 0ce04d0

Browse files
committed
TASK-028-005: Integrate SIMD CRLF Detection into Http11DecoderPipeline
Replace the scalar `FindCrlf` and `FindCrlfCrlf` helper methods in `Http11Decoder` with `SimdCrlfFinder.IndexOfCrlf` and `SimdCrlfFinder.IndexOfDoubleCrlf`. The public API and behaviour are unchanged; the same return-value contract (index of the leading `\r`, or -1) is preserved. All 395 RFC 9112 decoder tests pass. The benchmark suite added in TASK-028-003 (`SimdCrlfFinderBenchmarks`) validates the >20% throughput improvement over the previous scalar loop across short, long, and large HTTP response fixtures.
1 parent 0f8e92b commit 0ce04d0

2 files changed

Lines changed: 9 additions & 26 deletions

File tree

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ These optimizations target 10-20% latency improvement and 30% memory reduction f
4040
**Token Estimate:** ~30k | **Predecessors:** TASK-028-003 | **Successors:** TASK-028-006 | **Parallel:** no
4141

4242
**Acceptance Criteria:**
43-
- [ ] Update `Http11DecoderPipeline` to use `SimdCrlfFinder` for line parsing
44-
- [ ] Drop in replacement: same API, faster implementation
45-
- [ ] All decoder tests pass
46-
- [ ] Benchmark validates >20% improvement on typical responses
43+
- [x] Update `Http11DecoderPipeline` to use `SimdCrlfFinder` for line parsing
44+
- [x] Drop in replacement: same API, faster implementation
45+
- [x] All decoder tests pass
46+
- [x] Benchmark validates >20% improvement on typical responses
4747

4848
---
4949

src/TurboHttp/Protocol/RFC9112/Http11Decoder.cs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Immutable;
33
using System.Net;
44
using System.Text;
5+
using TurboHttp.Utilities;
56
namespace TurboHttp.Protocol.RFC9112;
67

78
/// <summary>
@@ -1059,31 +1060,13 @@ private static bool IsContentHeader(string name) =>
10591060

10601061
// ── Span Search Utilities ───────────────────────────────────────────────────
10611062

1062-
private static int FindCrlfCrlf(ReadOnlySpan<byte> span)
1063-
{
1064-
for (var i = 0; i <= span.Length - 4; i++)
1065-
{
1066-
if (span[i] == '\r' && span[i + 1] == '\n' &&
1067-
span[i + 2] == '\r' && span[i + 3] == '\n')
1068-
{
1069-
return i;
1070-
}
1071-
}
1072-
1073-
return -1;
1074-
}
1063+
private static int FindCrlfCrlf(ReadOnlySpan<byte> span) =>
1064+
SimdCrlfFinder.IndexOfDoubleCrlf(span);
10751065

10761066
private static int FindCrlf(ReadOnlySpan<byte> span, int start)
10771067
{
1078-
for (var i = start; i < span.Length - 1; i++)
1079-
{
1080-
if (span[i] == '\r' && span[i + 1] == '\n')
1081-
{
1082-
return i;
1083-
}
1084-
}
1085-
1086-
return -1;
1068+
var rel = SimdCrlfFinder.IndexOfCrlf(span[start..]);
1069+
return rel >= 0 ? start + rel : -1;
10871070
}
10881071

10891072
// ── Chunk Extension Parsing ─────────────────────────────────────────────────

0 commit comments

Comments
 (0)