Skip to content

Optimize cached online user lookups#6595

Open
NeglectDream wants to merge 2 commits into
EssentialsX:2.xfrom
NeglectDream:2.x
Open

Optimize cached online user lookups#6595
NeglectDream wants to merge 2 commits into
EssentialsX:2.xfrom
NeglectDream:2.x

Conversation

@NeglectDream

Copy link
Copy Markdown

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 the User is already backed by the same Player instance.

This is particularly inefficient for frequently fired events such as FoodLevelChangeEvent, player movement, entity damage, teleportation, and player interaction events. Each lookup can unnecessarily call loadUncachedUser(Player), update the UUID/name cache, and put the same User back into the Guava cache.

This PR adds a small cache-hit fast path to ModernUserMap#getUser(Player). When the cached User is already backed by the exact same Player instance, 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

  • Most recent Paper version (XX.YY.Z, git-Paper-BUILD)
  • CraftBukkit/Spigot/Paper 1.12.2
  • CraftBukkit 1.8.8
  • Leaf version 1.21.11-172-ver/1.21.11@33ce487
image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant