perf(runtime): cache Folia global and region scheduler instances#105
Closed
Arbousier1 wants to merge 1 commit into
Closed
perf(runtime): cache Folia global and region scheduler instances#105Arbousier1 wants to merge 1 commit into
Arbousier1 wants to merge 1 commit into
Conversation
globalRegionScheduler() and regionScheduler() previously invoked a reflective method lookup on plugin.getServer() on every call. On Folia, these return stable singleton schedulers that do not change for the lifetime of the server. Cache the resolved scheduler in a volatile field on first successful lookup so subsequent calls skip the reflective invokeNoArgs path entirely. In the benchmark Folia burst (84 tasks), this eliminates 19 reflective scheduler lookups per invocation (4 runGlobal + 16 runRegion, minus the first call each that populates the cache). On Paper, where these methods do not exist and invokeNoArgs returns null, the cache stays empty and the behavior is unchanged — null is never cached so the lookup still runs each time, preserving the existing fallback-to-BukkitScheduler semantics. entityScheduler(Entity) is not cached because the target entity varies per call and there is no stable key to cache on.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Collaborator
Author
|
Closing: AB gate returned INCONCLUSIVE_NOISE_OR_NO_GAIN. Caching Folia global/region scheduler instances did not meet the 3% median improvement threshold. |
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.
Summary
Cache the Folia
GlobalRegionSchedulerandRegionSchedulerinstances to avoid repeated reflective lookups on every scheduling call.Changes
volatilefieldscachedGlobalRegionSchedulerandcachedRegionSchedulertoServerScheduler.globalRegionScheduler()andregionScheduler()check the cache first; on a hit, return the cached instance directly, skippinginvokeNoArgs(reflective method resolution + invocation). On the first successful non-null resolution, store the result in the cache.entityScheduler(Entity)is not cached because the target entity varies per call.Behavior equivalence
getGlobalRegionScheduler()/getRegionScheduler()do not exist,invokeNoArgsreturns null, the cache stays empty, and the code falls back toBukkitScheduler.runTaskexactly as before.Verification
Target the
scheduler-reflectionperformance profile (ServerSchedulerReflectionBenchmark.scheduleFoliaBurstandschedulePaperBurst).Labels:
performance-ab,performance-scheduler-reflection