L4 map use no sync fast route when enouge predict ahead

This commit is contained in:
Youmu Liu
2026-10-13 18:14:16 +08:00
parent b7f1d3d2ba
commit 6bc7224d4c
8 changed files with 39 additions and 51 deletions
@@ -35,11 +35,16 @@ namespace Nitload.Common.HighPerformance.Memory
{
try
{
Predict();
_ = Interlocked.Exchange(ref _swiss_swap_lock, 1);
while (Volatile.Read(ref _swiss_reader_counter) != 0) { }
int effectivePredictionCount = Predict();
if (effectivePredictionCount > 0)
{
_ = Interlocked.Exchange(ref _swiss_swap_lock, 1);
while (Volatile.Read(ref _swiss_reader_counter) != 0) { }
_addressMap.SwapBuffers();
Volatile.Write(ref _predict_count, effectivePredictionCount);
}
_addressMap.SwapBuffers();
if (_addressMap.TryGet(source, out handle)) {
throw new InvalidOperationException($"Unexpected map request: [address source: 0x{source.Address:x16}; layout profile: {source.Description:x16}].");
}
@@ -52,7 +57,7 @@ namespace Nitload.Common.HighPerformance.Memory
} else if (!TryGetAddress(source, out handle)) {
throw new InvalidOperationException($"Unexpected map request: [address source: 0x{source.Address:x16}; layout profile: {source.Description:x16}].");
}
} else if (!TryGetAddress(source, out handle)) {
} else if (!_addressMap.TryGet(source, out handle)) {
throw new InvalidOperationException($"Unexpected map request: [address source: 0x{source.Address:x16}; layout profile: {source.Description:x16}].");
}
@@ -16,7 +16,7 @@ namespace Nitload.Common.HighPerformance.Memory
public unsafe partial class L4
{
internal partial void Predict() { }
internal partial int Predict() => 0;
}
}
@@ -81,7 +81,7 @@ namespace Nitload.Common.HighPerformance.Memory
return _bufferAllocator.TryAlloc(size, out handle);
}
internal partial void Predict();
internal partial int Predict();
}
}