LorisYounger / VPet

虚拟桌宠模拟器 一个开源的桌宠软件, 可以内置到任何WPF应用程序
Apache License 2.0
4.64k stars 465 forks source link

建议:减少第一次加载时内存使用 #135

Closed MJEdwin closed 10 months ago

MJEdwin commented 10 months ago

https://github.com/LorisYounger/VPet/blob/bceb7699f352e3e1ff096e6f22d332667f826050/VPet-Simulator.Core/Graph/PNGAnimation.cs#L194-L216

PNGAnimation中的startup过程进行了图片合并,该过程内存消耗过大,运行时间较长,png图片无需一下子加载进内存,可以加载一张、合并一张、销毁一张

LorisYounger commented 10 months ago

会不会导致加载速度变慢 其实我觉得除了32位需要限制下速度,其他的应该不需要,加载越快越好,免得玩家以为桌宠卡了

MJEdwin commented 10 months ago

如果担心的话可以弄个benchmark测试一下两个方法的性能

MJEdwin commented 10 months ago

BenchmarkDotNet v0.13.7, Windows 10 (10.0.19045.3324/22H2/2022Update)
Intel Core i5-7400 CPU 3.00GHz (Kaby Lake), 1 CPU, 4 logical and 4 physical cores
  [Host]               : .NET Framework 4.8.1 (4.8.9181.0), X64 RyuJIT VectorSize=256
  .NET Framework 4.6.2 : .NET Framework 4.8.1 (4.8.9181.0), X64 RyuJIT VectorSize=256

Job=.NET Framework 4.6.2  Runtime=.NET Framework 4.6.2  
Method Mean Error StdDev Allocated native memory Native memory leak Allocated
MergeByLoadAllFiles 322.9 ms 1.25 ms 1.04 ms 6,922 KB - 12 KB
MergeByLoopLoadFiles 307.4 ms 1.64 ms 1.46 ms 6,903 KB - 12 KB
MergeByLoopParallelLoadFiles 253.1 ms 1.09 ms 0.91 ms 1,986 KB - 44 KB

以上是我的测试结果 MergeByLoadAllFiles 为当前加载方式 MergeByLoopLoadFiles 为打开一张,合并一张,销毁一张 MergeByLoopParallelLoadFiles 是将上面过程并行化 测试代码可见 https://github.com/MJEdwin/VPet.Benchmark

MJEdwin commented 10 months ago

或者建议将该过程移动至mod制作过程中,使用tool工具先将动画合并完成,程序只要加载即可。 当然为了考虑兼容性,当前加载方式依然保留,然后通过文件数量或者文件名区分是否需要合并

LorisYounger commented 10 months ago

那就用MergeByLoopParallelLoadFiles吧, 你既然都写了不如pr下?