perf: skip org unit/period resolution in dimension recommendations#24264
Open
jason-p-pickering wants to merge 3 commits into
Open
perf: skip org unit/period resolution in dimension recommendations#24264jason-p-pickering wants to merge 3 commits into
jason-p-pickering wants to merge 3 commits into
Conversation
The /api/dimensions/recommendations endpoint resolved every dimension on the request via DataQueryService.getFromRequest, including ou:LEVEL-*. On a large hierarchy this hydrates all org units at the level as full entities and sorts them (~4.5s CPU, ~3.2 GB allocated in production profiling) — but getRecommendedDimensions only reads the data (dx) dimension's data elements/program indicators, so the org unit (and period) resolution is discarded. Scope the request to the dx dimension before resolving, so getFromRequest never resolves/hydrates the unused dimensions. Behaviour-equivalent for the sole caller (DimensionController sets only the dimension param), with no change to DataQueryService/getOrganisationUnitsAtLevels callers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
netroms
approved these changes
Jun 23, 2026
|
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
Fixes https://dhis2.atlassian.net/browse/DHIS2-21671
/api/dimensions/recommendationsresolved every dimension on the request viaDataQueryService.getFromRequest, includingou:LEVEL-*. On a large hierarchy this hydrates all orgunits at that level as full Hibernate entities and sorts them — ~4.5s CPU and ~3.2 GB allocated in
production profiling (Nigeria EMIS) — yet the result is discarded:
getRecommendedDimensionsonly reads the data (
dx) dimension's data elements / program indicators (plus org unit group setsloaded separately). The org unit and period dimensions are never read.
This PR scopes the request to the
dxdimension before resolving it, sogetFromRequestneverresolves/hydrates the unused dimensions.
Profiling (before)
Flame graph hot path:
getFromRequest→getOrgUnitDimension→getOrganisationUnitsAtLevels→HibernateOrganisationUnitStore.getOrganisationUnits(full-entity hydration) →
ComparableTimSort/Collections.sort.Change
The sole caller (
DimensionController) sets only thedimensionparam, so this isbehaviour-equivalent for everything the endpoint consumes. No change to
DataQueryService,getOrganisationUnitsAtLevels, orHibernateOrganisationUnitStore— zero blast radius on other callers.Tests
New unit test
DefaultAnalyticsDimensionServiceTest.getRecommendedDimensionsResolvesOnlyDataDimensioncaptures the
DataQueryRequestpassed togetFromRequestand asserts only thedxparam survives(
ou/pestripped). Verified failing before the fix, passing after.Notes
getMetaData OUG-count issues — but here the work is pure dead work, not a needed result.
🤖 Generated with Claude Code