Skip to content

[DRAFT] perf(n1): batch variable-metadata loads for Versions tab - #4

Draft
tuannx wants to merge 1 commit into
poc/quickperf-database-queriesfrom
poc/repro-versions-tab-n1
Draft

tuannx wants to merge 1 commit into
poc/quickperf-database-queriesfrom
poc/repro-versions-tab-n1

Conversation

@tuannx

@tuannx tuannx commented Sep 26, 2026

Copy link
Copy Markdown
Owner

Problem (hotspot A, private repro)

DatasetPage.resetVersionTabList() (DatasetPage.java:4803+) runs 2 service queries per file of every version whenever a privileged user renders the Versions tab:

fm.setVariableMetadatas(variableService.findVarMetByFileMetaId(fm.getId()));  // 1 query
fm.setVarGroups(variableService.findAllGroupsByFileMetadata(fm.getId()));     // 1 query

Measured on a 6 files x 2 versions fixture, the service-call section alone fires 86 SELECTs (24 service queries + per-row eager hydration). A 1.5K-file x 10-version dataset would issue ~30K queries here (estimated).

Fix

  • VariableServiceBean.findVarMetsByFileMetaIds() + findAllGroupsByFileMetadatas(): single IN (...) queries with to-one JOIN FETCH (fileMetadata, dataVariable, dataTable) - no cartesian product, grouping costs zero extra queries. Empty input yields empty list.
  • resetVersionTabList(): collect all file-metadata ids across versions, run the 2 batched queries, group in memory. Same lists per file as before.

Verification

  • New VersionTabVariableLoadBudgetIT (QuickPerf + testcontainers, follows the branch harness): 86 -> 2 SELECTs for the service-call section, plus a behavioral check that every v1 file still gets its 3 variable-metadata rows.
  • RED confirmed pre-fix (expected 2 batched variable-service SELECTs, but got 86), GREEN post-fix.
  • No new checkstyle violations in touched files.

Notes / follow-ups

DatasetPage.resetVersionTabList() issued 2 service queries per file of
every version (findVarMetByFileMetaId + findAllGroupsByFileMetadata).
For 6 files x 2 versions the service-call section alone fired 86 SELECTs.

- VariableServiceBean: add findVarMetsByFileMetaIds() and
  findAllGroupsByFileMetadatas() - single IN queries with to-one
  JOIN FETCH (fileMetadata, dataVariable, dataTable), so grouping the
  result costs no extra queries. Empty input yields empty list.
- DatasetPage.resetVersionTabList(): collect all file-metadata ids
  across versions, run the 2 batched queries, group in memory.
- VersionTabVariableLoadBudgetIT: QuickPerf/testcontainers repro that
  scopes measurement to the service calls: 86 -> 2 SELECTs, plus a
  behavioral check that every v1 file still gets its rows.

Draft: for private perf review; not yet proposed upstream.
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