Optimize cached online user lookups#6595
Open
NeglectDream wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Information
This PR fixes performance issue.
Details
Proposed fix:
ModernUserMap#getUser(Player)currently performs the full user lookup and cache update path for every call, even when the requested player is already cached and theUseris already backed by the samePlayerinstance.This is particularly inefficient for frequently fired events such as
FoodLevelChangeEvent, player movement, entity damage, teleportation, and player interaction events. Each lookup can unnecessarily callloadUncachedUser(Player), update the UUID/name cache, and put the sameUserback into the Guava cache.This PR adds a small cache-hit fast path to
ModernUserMap#getUser(Player). When the cachedUseris already backed by the exact samePlayerinstance, the existing user is returned immediately.The fast path deliberately uses reference identity rather than
Player#equals. This ensures that reconnects, replaced player objects, proxy player implementations, cache misses, and first-time loads continue through the existing lookup and update path.The fallback behavior is unchanged, and this PR does not modify any public API, configuration option, cache lifetime, user data format, or persistence behavior.
The change avoids redundant calls to:
ModernUserMap#loadUncachedUser(Player)LoadingCache#get(UUID)ModernUUIDCache#updateCache(UUID, String)LoadingCache#put(UUID, User)Only the production lookup path is changed.
Environments tested:
OS: Ubuntu 24.04.2 LTS
Java version: Zulu 25