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 of clearAllBlockInfoAtChunk, don't get immutable map #3905

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

WalshyDev
Copy link
Member

@WalshyDev WalshyDev commented Jul 11, 2023

Description

We're currently getting our ImmutableMap clone in clearAllBlockInfoAtChunk, instead we can unsafely get the storage and save the overhead of duplicating the map (which for large servers is massive).

Right now it's taking basically all of the compute time:
image

Proposed changes

Unsafely get the raw storage instead of our safe ImmutableMap.

Related Issues (if applicable)

Resolves #3432

Checklist

  • I have fully tested the proposed changes and promise that they will not break everything into chaos.
  • I have also tested the proposed changes in combination with various popular addons and can confirm my changes do not break them.
  • I have made sure that the proposed changes do not break compatibility across the supported Minecraft versions (1.16.* - 1.20.*).
  • I followed the existing code standards and didn't mess up the formatting.
  • I did my best to add documentation to any public classes or methods I added.
  • I have added Nonnull and Nullable annotations to my methods to indicate their behaviour for null values
  • I added sufficient Unit Tests to cover my code.

@WalshyDev WalshyDev requested a review from a team as a code owner July 11, 2023 00:55
@github-actions github-actions bot added the 🧹 Chores Refactoring / Cleanup. label Jul 11, 2023
@github-actions
Copy link
Contributor

Your Pull Request was automatically labelled as: "🧹 Chores"
Thank you for contributing to this project! ❤️

@WalshyDev
Copy link
Member Author

cc: @md5sha256 - not sure if you had any specific reason to use getRawStorage instead of accessing it directly.
I believe we should be safe to use this though, we're only doing reads, not attempting any writes and aren't passing the ref down anywhere.

@github-actions
Copy link
Contributor

Slimefun preview build

A Slimefun preview build is available for testing!
Commit: 1b2eb20b

https://preview-builds.walshy.dev/download/Slimefun/3905/1b2eb20b

Note: This is not a supported build and is only here for the purposes of testing.
Do not run this on a live server and do not report bugs anywhere but this PR!

@sonarcloud
Copy link

sonarcloud bot commented Jul 11, 2023

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 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@WalshyDev
Copy link
Member Author

WalshyDev commented Jul 11, 2023

Timing courtesy of @Skizzles - https://spark.lucko.me/5ZX5HHHvHi

clearAllBlockInfoAtChunk went from 52.67% 44440ms (self: 3404ms - 4.03%) -> 32.51% 11580ms (self: 112ms - 0.31%)

44s -> 11s

We're now hitting Javaland code taking the rest of the majority:
image

22.03% (7.8s) from ConcurrentHashMap.get()

BlockStorage rewrite wen:tm:

@md5sha256
Copy link
Contributor

md5sha256 commented Jul 11, 2023

cc: @md5sha256 - not sure if you had any specific reason to use getRawStorage instead of accessing it directly. I believe we should be safe to use this though, we're only doing reads, not attempting any writes and aren't passing the ref down anywhere.

Either an oversight or I was erring on the side of caution. Either way, the performance benefit outweighs the perceived safety of operating on #getRawStorage

The only comment I have-ish, (and I've never done this, there was a reason why) but is it good practice/possible to just store (cache) the immutable map in the BlockStorage instance since it's basically just a wrapper? This might become obsolete in the future, however.

@WalshyDev
Copy link
Member Author

The only comment I have-ish, (and I've never done this, there was a reason why) but is it good practice/possible to just store (cache) the immutable map in the BlockStorage instance since it's basically just a wrapper? This might become obsolete in the future, however.

probably but we'd really want to have partial updates done when needed to it (which kinda breaks the immutable part as it isn't fully) and afaik you can't do that with any Java-native implementations today.

There's also just the issue of added memory :(

@md5sha256
Copy link
Contributor

Yeah, fair enough. In that case LGTM

Copy link
Contributor

@JustAHuman-xD JustAHuman-xD left a comment

Choose a reason for hiding this comment

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

LGTM

@WalshyDev WalshyDev merged commit e00cac4 into master Jul 11, 2023
14 checks passed
@WalshyDev WalshyDev deleted the chore/dont-get-immutable-map branch July 11, 2023 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧹 Chores Refactoring / Cleanup.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance impact when clearing blockdata from a whole chunk
4 participants