MeikelLP / quantum-core-x

Metin2 open source server implementation
https://meikellp.github.io/quantum-core-x/
Mozilla Public License 2.0
35 stars 9 forks source link

Improve performance in `Map.Update` #22

Closed MeikelLP closed 11 months ago

MeikelLP commented 12 months ago

This PR depends on #21

I created benchmarks in the Game.Benchmarks project. These can be executed on the master branch as well (some minor adjustments needed). These benchmark results show massive improvements in tick time and allocations.

Before

Method MobAmount PlayerAmount Mean Error StdDev Gen0 Gen1 Allocated
World_Tick 0 0 64.42 ns 1.850 ns 2.770 ns - - -
World_Tick 0 1 1,491.87 ns 25.327 ns 37.908 ns 0.0896 0.0305 752 B
World_Tick 0 10 14,845.21 ns 721.294 ns 1,057.264 ns 0.8545 0.2747 7304 B
World_Tick 100 0 700.16 ns 3.674 ns 5.028 ns 0.0219 - 184 B
World_Tick 100 1 2,435.19 ns 57.915 ns 86.685 ns 0.1068 0.0343 912 B
World_Tick 100 10 15,474.01 ns 659.433 ns 966.588 ns 0.8850 0.3052 7464 B
World_Tick 1000 0 714.64 ns 7.332 ns 10.279 ns 0.0219 - 184 B
World_Tick 1000 1 2,558.69 ns 219.188 ns 321.284 ns 0.1068 0.0343 912 B
World_Tick 1000 10 18,889.50 ns 1,817.647 ns 2,720.568 ns 0.8850 0.3052 7464 B

image

After

Method MobAmount PlayerAmount Mean Error StdDev Median Allocated
World_Tick 0 0 16.96 ns 0.049 ns 0.065 ns 16.94 ns -
World_Tick 0 1 26.09 ns 0.570 ns 0.799 ns 25.52 ns -
World_Tick 0 10 127.43 ns 0.439 ns 0.601 ns 127.48 ns -
World_Tick 100 0 213.19 ns 1.000 ns 1.497 ns 213.10 ns -
World_Tick 100 1 245.09 ns 0.899 ns 1.260 ns 245.26 ns -
World_Tick 100 10 332.89 ns 2.116 ns 3.101 ns 331.81 ns -
World_Tick 1000 0 213.36 ns 0.908 ns 1.273 ns 213.23 ns -
World_Tick 1000 1 245.70 ns 0.609 ns 0.834 ns 245.53 ns -
World_Tick 1000 10 332.92 ns 1.640 ns 2.403 ns 332.01 ns -

image

Changes

The following changes where made:

MeikelLP commented 12 months ago

Impressive work, except for the two small minor changes it looks good 👍

Thanks for your feedback

rausc-daniel commented 11 months ago

Very impressive improvements indeed 💪 If you manage to clean up the calls to Task.Wait() and Task.Result that for now seem to not be easily avoidable it would be even more impressive ;)

Also have you considered adding some documentation here and there? Maybe just on class level. For me as an outsider it was quite hard to understand what the purpose of a SpawnGroup or the AtlasProvider is. Some documentation would make this at-a-glance informantion :)

sonarcloud[bot] commented 11 months ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 12 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication