Skip to content

Commit d3b1b03

Browse files
committed
OnHeadersComplete improve speculation and memory ordering (VTune)
1 parent b2ac2b4 commit d3b1b03

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestHeaders.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,22 @@ public HttpRequestHeaders(bool reuseHeaderValues = true, bool useLatin1 = false)
2727

2828
public void OnHeadersComplete()
2929
{
30-
var bitsToClear = _previousBits & ~_bits;
30+
var newHeaderFlags = _bits;
31+
var previousHeaderFlags = _previousBits;
3132
_previousBits = 0;
3233

33-
if (bitsToClear != 0)
34+
var headersToClear = (~newHeaderFlags) & previousHeaderFlags;
35+
if (headersToClear == 0)
3436
{
35-
// Some previous headers were not reused or overwritten.
36-
37-
// While they cannot be accessed by the current request (as they were not supplied by it)
38-
// there is no point in holding on to them, so clear them now,
39-
// to allow them to get collected by the GC.
40-
Clear(bitsToClear);
37+
// All headers were resued.
38+
return;
4139
}
40+
41+
// Some previous headers were not reused or overwritten.
42+
// While they cannot be accessed by the current request (as they were not supplied by it)
43+
// there is no point in holding on to them, so clear them now,
44+
// to allow them to get collected by the GC.
45+
Clear(headersToClear);
4246
}
4347

4448
protected override void ClearFast()

0 commit comments

Comments
 (0)