Title: ScheduledDataLoaderRegistry ticker mode dispatches every registered data loader on each dispatchAll(), even when nothing is queued · Issue #292 · graphql-java/java-dataloader · GitHub
Open Graph Title: ScheduledDataLoaderRegistry ticker mode dispatches every registered data loader on each dispatchAll(), even when nothing is queued · Issue #292 · graphql-java/java-dataloader
X Title: ScheduledDataLoaderRegistry ticker mode dispatches every registered data loader on each dispatchAll(), even when nothing is queued · Issue #292 · graphql-java/java-dataloader
Description: Summary In ticker mode, ScheduledDataLoaderRegistry.dispatchAll() runs a full dispatch() on every registered data loader, including loaders with nothing queued. Each empty dispatch still: does a CAS on the loader queue; reads the clock a...
Open Graph Description: Summary In ticker mode, ScheduledDataLoaderRegistry.dispatchAll() runs a full dispatch() on every registered data loader, including loaders with nothing queued. Each empty dispatch still: does a CA...
X Description: Summary In ticker mode, ScheduledDataLoaderRegistry.dispatchAll() runs a full dispatch() on every registered data loader, including loaders with nothing queued. Each empty dispatch still: does a CA...
Opengraph URL: https://github.com/graphql-java/java-dataloader/issues/292
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ScheduledDataLoaderRegistry ticker mode dispatches every registered data loader on each dispatchAll(), even when nothing is queued","articleBody":"## Summary\n\nIn ticker mode, `ScheduledDataLoaderRegistry.dispatchAll()` runs a full `dispatch()` on **every** registered data loader, including loaders with nothing queued. Each empty dispatch still:\n- does a CAS on the loader queue;\n- reads the clock and writes `lastDispatchTime`;\n- calls `instrumentation().beginDispatch(...)`;\n- attaches the end-of-dispatch callback to an empty result, allocating about 48 bytes per loader per call.\n\nThe registry also evaluates the predicate and re-arms the ticker once per loader.\n\nGraphQL servers typically register every loader the application defines in each request's registry, but a request queues keys on only a few of them. graphql-java's per-level dispatch then calls `dispatchAll()` many times per request, and the ticker calls it again every `schedule`. Nearly all of that work goes to loaders with nothing to dispatch, so the cost grows with registered loaders × `dispatchAll()` calls rather than with actual batches.\n\nVersion: `master` at da59d1d, which includes #291, and 6.0.0. We hit this through Netflix DGS 12 in ticker mode with graphql-java 25.\n\n## Where\n\n`ScheduledDataLoaderRegistry` (`master`):\n\n```java\npublic int dispatchAllWithCount() {\n int sum = 0;\n for (Map.Entry\u003cString, DataLoader\u003c?, ?>> entry : dataLoaders.entrySet()) {\n ...\n sum += dispatchOrReschedule(key, dataLoader); // shouldDispatch + dispatchWithCounts() for every loader\n }\n return sum;\n}\n```\n\nand `DataLoaderHelper.dispatch()`, which runs in full even when the queue is empty:\n\n```java\nDataLoaderInstrumentationContext\u003cDispatchResult\u003c?>> instrCtx = ctxOrNoopCtx(instrumentation().beginDispatch(dataLoader));\n...\nif (loaderQueueEntryHead == null) {\n lastDispatchTime.set(now());\n instrCtx.onDispatched();\n return endDispatchCtx(instrCtx, emptyDispatchResult());\n}\n```\n\n## Measurements\n\n**JMH, in-repo.** The proposed PR adds `ScheduledDataLoaderRegistryDispatchPerformance`. It builds a ticker-mode registry the way DGS does: `DISPATCH_NEVER` for the registry, `DISPATCH_ALWAYS` per loader, a schedule long enough that the ticker never fires during a measurement, and caching disabled so every load is queued. Each operation queues one key on N loaders, then calls `dispatchAllWithCount()`.\n\nRuns were on JDK 21, Apple M-series, `-prof gc`, two interleaved runs per variant. The figures below are from master at da59d1d:\n\n| Registered loaders | Loaders with queued keys | Time / `dispatchAll` | Allocated / `dispatchAll` |\n|---|---|---|---|\n| 20 | 0 | 853–881 ns | 960 B |\n| 200 | 0 | 9,199–9,468 ns | 9,600 B |\n| 20 | 5 | 1,129–1,199 ns | 3,920 B |\n| 200 | 5 | 9,766–10,069 ns | 16,600–16,880 B |\n\nWith 5 loaders doing real work, the 195 idle loaders account for about 85% of the time and 83% of the allocation.\n\n**Production.** In a GraphQL service with about 190 registered loaders, CPU profiles across 12 instances (154k samples) showed `dispatchAll()` visiting loaders with empty queues at **about 3.2% of total CPU**:\n\n| Where the empty-dispatch cost went | Share of total CPU |\n|---|---|\n| Empty `DataLoaderHelper.dispatch()`: CAS, `clock.instant()`, `lastDispatchTime`, instrumentation, `endDispatchCtx` | ~1.6% |\n| Iterating the `ConcurrentHashMap` of loaders | ~1.1% |\n| `shouldDispatch` predicate-map lookups | ~0.35% |\n\nAbout 62% of those calls came from graphql-java's per-level dispatch and 38% from the ticker. Code that only runs for a non-empty queue took about 0.03% of CPU, against about 0.87% for the empty path. So fewer than 3% of loader visits had anything to dispatch.\n\n## Proposal\n\nIn ticker mode, skip loaders whose `dispatchDepth()` is 0, and re-arm the ticker once per `dispatchAll()` instead of once per loader. `dispatchDepth()` is a single atomic read of the queue head.\n\nA key queued after the check is dispatched by the next tick, which is the same window as a key queued just after a dispatch today. The ticker contract is unchanged: after the first `dispatchAll()`, every loader whose predicate passes is dispatched at least every `schedule` until `close()`.\n\nThe observable differences, both on idle loaders only:\n- `lastDispatchTime` is no longer refreshed, which matters only for time-based predicates such as `DispatchPredicate.dispatchIfLongerThan`;\n- `beginDispatch` no longer fires for loaders with nothing to dispatch.\n\nNon-ticker mode would stay as it is: there, a not-yet-dispatched loader relies on its per-loader reschedule chain.\n\nI have a PR ready with a test and the JMH benchmark.\n","author":{"url":"https://github.com/Meemaw","@type":"Person","name":"Meemaw"},"datePublished":"2026-10-19T09:09:09Z","url":"https://github.com/graphql-java/java-dataloader/issues/292"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:dd6d597d-2ef5-3254-af8e-e5c4fac2df6a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DE52:14ECB:248B47C:2E6AA39:6B01883B |
| html-safe-nonce | f6ce1b9a52257cb4e80eaf6ffda9b5e821d6f5254bd292ebd785f9df8341caff |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTUyOjE0RUNCOjI0OEI0N0M6MkU2QUEzOTo2QjAxODgzQiIsInZpc2l0b3JfaWQiOiI1Nzk0ODkyOTM2OTYxNDI3NTE1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 086f2ddb66863a4e629418bb653afe41ae1203179318618f5ac634a840774d6d |
| hovercard-subject-tag | issue:5921029380 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/graphql-java/java-dataloader/292/issue_layout |
| twitter:image | https://opengraph.githubassets.com/20f069c4ab89734e0a911d320ea5aaf3f1401b13a8095ac8b53dcbc812d9a82e/graphql-java/java-dataloader/issues/292 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/20f069c4ab89734e0a911d320ea5aaf3f1401b13a8095ac8b53dcbc812d9a82e/graphql-java/java-dataloader/issues/292 |
| og:image:alt | Summary In ticker mode, ScheduledDataLoaderRegistry.dispatchAll() runs a full dispatch() on every registered data loader, including loaders with nothing queued. Each empty dispatch still: does a CA... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Meemaw |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/graphql-java/java-dataloader git https://github.com/graphql-java/java-dataloader.git |
| octolytics-dimension-user_id | 14289921 |
| octolytics-dimension-user_login | graphql-java |
| octolytics-dimension-repository_id | 97364654 |
| octolytics-dimension-repository_nwo | graphql-java/java-dataloader |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 97364654 |
| octolytics-dimension-repository_network_root_nwo | graphql-java/java-dataloader |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width