Skip to content

fix(hotspots): avoid cartesian product in getImportStringFrom (stacked on #238) - #240

Merged
felickz merged 5 commits into
mainfrom
felickz-hotspots-oom-codeql-2-27-3
Oct 27, 2026
Merged

felickz merged 5 commits into
mainfrom
felickz-hotspots-oom-codeql-2-27-3

Conversation

@felickz

@felickz felickz commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Stacked on #238 (CodeQL CLI 2.27.3 bump). Targets chore/update-codeql-cli-2.27.3, not main.

Problem

In #238 the Generate hotspots queries job fills the runner disk (/tmp/codeqldb grows ~2.4 GB/min to ~83 GB). The evaluator log (from the diagnostics artifact) shows a single unfinished predicate, the getImportStringFrom join at ql/hotspots/utils/hotspots.qll. Its plan contains JOIN WITH locations_default CARTESIAN PRODUCT: ~33k import tuples x 14.97M locations, ~5e11 tuples.

The cause is a non-equality string join: configPath.matches("%" + i.getImportString()) gives the optimizer nothing to bind on. The 2.27.2 run did not hit this. Four ql/ commits landed in github/codeql between codeql-cli/v2.27.2 and v2.27.3, so a planner change is the likely trigger (still being investigated).

Fix

  • Materialize the dotted-path suffixes of the config file in a pragma[nomagic] helper (getADottedPathSuffix).
  • Join on string equality with Import.getImportString() instead of matches("%" + ...).

Result semantics are unchanged: a suffix match becomes an equality against every suffix. The one difference is that _/% in an import string are no longer wildcards.

Temporary CI commit

hotspots-ci.yml only triggers for PRs targeting main, so this stacked PR would get no hotspots signal. The second commit widens the branch filter to chore/update-codeql-cli-*. Drop that commit before merging into the bump branch.

Validation

  • Compiles locally with codeql query compile (2.27.0 CLI against the github/codeql v2.27.3 ql pack). The wider checks need the CI run.
  • Expect Hotspots Build/Validate to finish Generate hotspots queries in about 4-5 min with 294 configuration rows (same as the 2.27.2 baseline).

felickz and others added 5 commits October 21, 2026 16:54
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
…trings

getImportStringFrom compared the config file's dotted path against
Import.getImportString() with matches("%" + importString). That non-equality
string join gives the optimizer nothing to bind on, and with CodeQL 2.27.3
(github/codeql codeql-cli/v2.27.3) it planned a cartesian product of ~33k
import tuples with the 15M-row locations_default relation, filling the runner
disk.

Materialize the config's dotted-path suffixes in a pragma[nomagic] helper and
join on string equality instead.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…anches

hotspots-ci.yml only triggers for PRs targeting main, so a PR stacked on
chore/update-codeql-cli-* would get no hotspots signal. Drop this commit before
merging the fix into the bump branch.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Completed target-CLI validation is still needed to confirm generation performance and the expected 294 configuration rows.

No open issues 🎉

What changed in this PR

This PR addresses excessive disk usage during hotspots query generation on CodeQL 2.27.3, stacked on the CLI bump in #238.

Changes:

  • Materializes configuration-path suffixes and replaces wildcard matching with an equality join to avoid the problematic Cartesian product.
  • Temporarily enables hotspots CI for CLI-update target branches; this workflow change is intended to be dropped before merging into the bump branch.
File Description
ql/​hotspots/​utils/​hotspots.qll Adds suffix helpers and uses equality to match configuration imports.
.github/​workflows/​hotspots-ci.yml Temporarily enables validation for stacked CLI-update PRs.

Review effort: Balanced

@felickz
felickz added this pull request to stack #241 October 26, 2026 15:17
Base automatically changed from chore/update-codeql-cli-2.27.3 to main October 27, 2026 19:20
@felickz
felickz merged commit 711b435 into main Oct 27, 2026
31 of 32 checks passed
@felickz
felickz deleted the felickz-hotspots-oom-codeql-2-27-3 branch October 27, 2026 19:20
felickz added a commit that referenced this pull request Oct 27, 2026
…#240) (#242)

* chore: bump pinned CodeQL CLI to v2.27.3 and release v0.8.3

* Add Hotspots query resource diagnostics

Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>

* Cap Hotspots evaluator disk cache

Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>

* fix(hotspots): avoid cartesian product when resolving config import strings

getImportStringFrom compared the config file's dotted path against
Import.getImportString() with matches("%" + importString). That non-equality
string join gives the optimizer nothing to bind on, and with CodeQL 2.27.3
(github/codeql codeql-cli/v2.27.3) it planned a cartesian product of ~33k
import tuples with the 15M-row locations_default relation, filling the runner
disk.

Materialize the config's dotted-path suffixes in a pragma[nomagic] helper and
join on string equality instead.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* ci(hotspots): TEMPORARY run Hotspots CI on PRs stacked on CLI bump branches

hotspots-ci.yml only triggers for PRs targeting main, so a PR stacked on
chore/update-codeql-cli-* would get no hotspots signal. Drop this commit before
merging the fix into the bump branch.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(ci): keep JVM warnings out of codeql test JSON reports

`ci.yml` redirects each `codeql test run --format=json` process's stdout straight into
`test_report_slice_N_of_4.json`. The JVM prints its own warnings to stdout too, so a stray
line such as

  [0.001s][warning][perf,memops] Cannot use file /tmp/hsperfdata_runner/2405 because it is
  locked by another process (errno = 11)

ahead of the JSON made `jq` fail in "Validate test results" even though every test passed.
Four JVMs start at the same instant per language job, which makes the per-PID hsperfdata
file collision possible.

1. Pass `-J=-XX:-UsePerfData` to `codeql test run` so the JVM never creates those files.
2. In "Validate test results", drop anything before the opening `[` of each report before
   running `jq`, emit a warning when something was dropped, and still fail if the remainder
   is not valid JSON.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

3 participants