Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance in Map.Update #22

Merged
merged 29 commits into from
Oct 23, 2023
Merged

Improve performance in Map.Update #22

merged 29 commits into from
Oct 23, 2023

Conversation

MeikelLP
Copy link
Owner

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:

  • Improve PlayerEntity.GetPoint by preloading values and just returning the current state. Weapon damage may change if the item is switched. An event has been created in the Inventory class
  • Some closure improvements by not using LINQ
  • Replaced all async calls with sync calls which for sending packages will write to a concurrent queue instead of directly writing to the network. A background task is started which will try to process the queue or wait for 1ms if none exists. Packets will come in quite frequently that's why the wait time is so small.

@MeikelLP MeikelLP self-assigned this Oct 20, 2023
@MeikelLP MeikelLP added the type/enhancement Improve an existing feature label Oct 21, 2023
Copy link
Collaborator

@NoFr1ends NoFr1ends left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Core/Extensions/ConnectionExtensions.cs Outdated Show resolved Hide resolved
Core/Core/Networking/Connection.cs Outdated Show resolved Hide resolved
@MeikelLP
Copy link
Owner Author

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

Thanks for your feedback

@MeikelLP MeikelLP requested a review from NoFr1ends October 21, 2023 23:36
# Conflicts:
#	Executables/Game/Services/AtlasProvider.cs
#	Executables/Game/World/Map.cs
#	Executables/Game/World/World.cs
@rausc-daniel
Copy link
Collaborator

rausc-daniel commented Oct 22, 2023

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 :)

Copy link
Collaborator

@rausc-daniel rausc-daniel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing here that would prevent me from approving. Just a few small suggestions and things to consider. Good work!

Core/Core/Networking/Connection.cs Show resolved Hide resolved
Core/Core/Networking/Connection.cs Outdated Show resolved Hide resolved
Core/Core/Networking/Connection.cs Outdated Show resolved Hide resolved
Executables/Game/ParserUtils.cs Outdated Show resolved Hide resolved
Executables/Game/Services/AtlasProvider.cs Outdated Show resolved Hide resolved
Executables/Game/World/Entities/PlayerEntity.cs Outdated Show resolved Hide resolved
@MeikelLP MeikelLP removed the request for review from Jafah October 23, 2023 20:48
@sonarqubecloud
Copy link

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

@MeikelLP MeikelLP merged commit 4179eed into master Oct 23, 2023
4 checks passed
@MeikelLP MeikelLP deleted the performance branch October 23, 2023 20:50
@MeikelLP MeikelLP added the area/performance Improves performance label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/performance Improves performance type/enhancement Improve an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants