SceneGate / Yarhl

Framework for the implementation of format converters like game assets or media files
https://scenegate.github.io/Yarhl/
MIT License
60 stars 10 forks source link

:racehorse: Improve memory consumption of DataStream.WriteTo #183

Closed pleonex closed 2 years ago

pleonex commented 2 years ago

Description

Consecutive calls to DataStream.WriteTo were allocating arrays upto 70 KB each time. When the number of calls is big, this could cause an unnecessary performance issues, especially impacting the memory. For instance, in Ekona generating some ROMs with a lot of files, due to the WriteTo we required 256 MB in the RAM. Now, we reuse arrays between calls with the library System.Buffers. The memory was reduced to 70 MB in the same test.

Example

Internal improvement, API is the same.