Skip to content

perf(scheduler): cache scheduler-capability lookups by target identity#108

Closed
Arbousier1 wants to merge 1 commit into
devfrom
codex/perf-scheduler-identity-cache
Closed

perf(scheduler): cache scheduler-capability lookups by target identity#108
Arbousier1 wants to merge 1 commit into
devfrom
codex/perf-scheduler-identity-cache

Conversation

@Arbousier1

Copy link
Copy Markdown
Collaborator

Add single-slot identity caches for globalRegionScheduler(),
egionScheduler(), and entityScheduler(entity) to skip reflective MethodResolution.invoke dispatch on repeat calls with the same target.

In the render hot path and ServerSchedulerReflectionBenchmark, a burst of 84 scheduling calls (4 global + 16 region + 64 entity) all hit the same server/entity targets. With the identity cache, only the first call per target performs reflective dispatch; subsequent calls return the cached scheduler handle.

Identity equality (==) is correct because the server instance is stable for the plugin's lifetime and entity schedulers are stable per entity. Fields are volatile for cross-thread visibility.

Targets the scheduler-reflection profile (both scheduler.folia.time and scheduler.paper.time must pass).

The three scheduler-capability accessors (globalRegionScheduler,
regionScheduler, entityScheduler) re-resolve the same reflective method
and re-invoke it on the same target on every call. In the render hot
path and ServerSchedulerReflectionBenchmark, a burst of 84 scheduling
calls (4 global + 16 region + 64 entity) all hit the same server/entity
targets.

Add single-slot identity caches keyed on the target object reference:
- globalRegionScheduler caches on plugin.getServer() identity
- regionScheduler caches on plugin.getServer() identity
- entityScheduler caches on the entity identity

On a cache hit the reflective MethodResolution.invoke dispatch is skipped
entirely, returning the previously resolved scheduler handle. Identity
equality (==) is correct because the server instance is stable for the
plugin's lifetime and entity schedulers are stable per entity.

Fields are volatile for cross-thread visibility; a torn read at worst
causes a cache miss (recompute) or returns a stale handle for one call,
both safe because scheduler handles are stable references.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Arbousier1 Arbousier1 added performance-ab Run the base-owned paired performance gate performance-scheduler-reflection Use the scheduler reflection performance profile labels Jul 18, 2026
@Arbousier1

Copy link
Copy Markdown
Collaborator Author

Closing per the performance and correctness gates. The complete 8-shard paired run finished as INCONCLUSIVE_NOISE_OR_NO_GAIN, matching the prior finding that scheduler reflection is already a ~20 ns deferred hotspot. The separately published volatile entity target/scheduler fields can also pair a new target with the previous scheduler under concurrency, which is unsafe for Folia entity scheduling.

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

Labels

performance-ab Run the base-owned paired performance gate performance-scheduler-reflection Use the scheduler reflection performance profile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant