Repository navigation
feat: perf improvements #minor - #79
Merged
Merged
Conversation
…cher and update replay benchmark
…op and add benchmark
…e.As enum parsing, and zero-copy ReadMemory
…y temp ends, and FillBitsFrom
…oup mapping and add benchmark
… bunch reuse, and lazy vector allocation
…and span-based AES decryption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Performance & Memory Allocation Improvements
This PR optimizes the IO, memory slicing, and bitstream parsing hot paths in the replay reader. By replacing reflection and allocating operations with
Span<byte>,ReadOnlyMemory<byte>,BinaryPrimitives, zero-copy buffer slicing, and reusable object pools, end-to-end replay parsing is significantly faster and allocates ~34% to 38% less managed heap memory.Benchmark & Real-World Results
1. Recent Replay Comparison 16.03 MB)
master(Baseline)perf-improvementsSummary of Changes
1.
Unreal.Core(IO & Bitstream)BitConverterand sliced allocations withBinaryPrimitives.Read*LittleEndiandirectly overBytes.Span.Enum.ToObject(typeof(T), byte)withUnsafe.As<byte, T>andUnsafe.As<uint, T>, eliminating boxing and reflection.ReadBitsToIntandReadBitsToLongwith unaligned 64-bit word reads (BinaryPrimitives.ReadUInt64LittleEndian) and bitwise shifts (7.3x faster).FillBitsFromto deserialize property bunches directly into internal reusable buffers instead of allocating a newbyte[]for every property.Dictionary<FBitArchiveEndIndex, int>with a fixedint[4]array for bunch temp ends (4.6x faster)..Where(...).Any()inRemoveAllPathPrefixeswith an allocation-freeReadOnlySpan<string>loop (-95.4% allocations).ReadMemory(byteCount)inFArchiveandBinaryReaderto slice underlying buffers without copying.2.
Unreal.Core(Replication & Guidance)ReceivedRawPacket(ReadOnlyMemory<byte>), eliminating hundreds of thousands of packet array allocations per replay._currentBunchfor non-partial bunches, saving ~350,000 bunch object allocations per parse.ConditionallySerializeQuantizedVectornow avoids instantiating defaultnew FVector()instances when no delta was serialized (-50% vector allocations)._netFieldExportGroupFromIndex) to bypass 2-step dictionary lookups (2.1x faster).3.
FortniteReplayReaderFile.ReadAllByteswith zero-copy chunk slices and in-placeAes.DecryptEcbover spans.4.
BenchmarkReader& TestingProgram.csto top-level statements delegating toBenchmarkDotNet.Running.BenchmarkSwitcher. Allows interactively selecting any benchmark or passing CLI filters (e.g.,-- 4or--filter *BenchmarkEnumParsing*).Unreal.Core.Testasserting functional parity and zero heap allocations (GC.GetAllocatedBytesForCurrentThread() == 0).