ethanmoffat / EndlessClient

An open source client for Endless Online written in C#
MIT License
34 stars 16 forks source link

Fix animation timing issues. Reduce heap allocations when loading GFX #306

Closed ethanmoffat closed 1 year ago

ethanmoffat commented 1 year ago

This change includes timing updates as well as performance updates to reduce the number of garbage collections happening in the background.

Timing Updates

Completely reworked my timing system to be tick-based like the vanilla client.

Timestamp measurements:

Action Original Client EndlessClient
Walk 48 48
Attack 60 61

Approach:

The end result is that there's a single place where animation timings are tracked. The behavior is now significantly more consistent and closer to vanilla.

Fixes #299

Memory usage updates

Updated PELoaderLib to use Span<T> and Memory<T> to load data, and removed ImageSharp as a dependency in the texture loading pipeline. This reduces the number of intermediate heap allocations and data copies when converting a texture from a PE resource to a Texture2D. This relies on some unsafe code and pointer arithmetic for high performance and reduced memory footprint

Additionally, found a couple memory hotspots where lots of allocations were happening:

StatusBarLabel texture is now just loaded once, and NPCs now use an LRU caching mechanism to store the pixel data of the underlying textures. This has an increased memory footprint, but reduces the number of GetData calls needed, which reduces the number of heap allocations and eventual garbage collections.

This partially addresses #230 but more work still needs to be done