Skip to content

Java: Fix performance issue in type flow library#21987

Open
hvitved wants to merge 3 commits into
github:mainfrom
hvitved:type-flow-ranking
Open

Java: Fix performance issue in type flow library#21987
hvitved wants to merge 3 commits into
github:mainfrom
hvitved:type-flow-ranking

Conversation

@hvitved

@hvitved hvitved commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

This PR fixes the performance issue reported here.

The issue is that UniversalFlow.qll uses purely location-based ranking, which doesn't work well when many entities have the same location information (as is the case for certain compiler-generated methods in Kotlin). The fix is to add an escape hatch to UniversalFlow.qll (and TypeFlow.qll), which allows for language-specific ranking.

@github-actions github-actions Bot added the Java label Jun 15, 2026
Comment thread java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll Fixed
Comment thread java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll Fixed
Comment thread java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll Fixed
Comment thread shared/typeflow/codeql/typeflow/UniversalFlow.qll
Co-authored-by: Anders Schack-Mulligen <aschackmull@users.noreply.github.com>
Comment thread java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll Outdated
Co-authored-by: Anders Schack-Mulligen <aschackmull@users.noreply.github.com>
@hvitved

hvitved commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author
Rerun has been triggered: 2 restarted 🚀

@hvitved hvitved added the no-change-note-required This PR does not need a change note label Jun 15, 2026
@hvitved hvitved marked this pull request as ready for review June 15, 2026 18:27
@hvitved hvitved requested a review from a team as a code owner June 15, 2026 18:27
Copilot AI review requested due to automatic review settings June 15, 2026 18:27
@hvitved hvitved requested a review from a team as a code owner June 15, 2026 18:27

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.

Pull request overview

This PR addresses the Java/Kotlin analysis performance regression described in #21874 by adding an optional, language-provided node-identifier hook to the shared type flow framework so ranking can avoid degenerating when many nodes share the same location (for example, compiler-generated Kotlin methods).

Changes:

  • Adds optional node ID predicates to UniversalFlowInput and TypeFlowInput to allow stable, language-specific ranking with a location-based fallback.
  • Wires the new hook through the shared TypeFlowImpl adapter so TypeFlow can pass language-provided IDs into UniversalFlow.
  • Implements/provides a Java-side node ID strategy and threads it into affected Java libraries/modules.
Show a summary per file
File Description
shared/typeflow/codeql/typeflow/UniversalFlow.qll Adds an optional getFlowNodeId hook and updates ranking to use it with a location fallback.
shared/typeflow/codeql/typeflow/TypeFlow.qll Adds an optional getTypeFlowNodeId hook to the TypeFlow input signature.
shared/typeflow/codeql/typeflow/internal/TypeFlowImpl.qll Connects TypeFlowInput.getTypeFlowNodeId into the universal-flow adapter layer.
java/ql/lib/semmle/code/java/security/ListOfConstantsSanitizer.qll Plumbs Java’s flow-node ID into the module’s UniversalFlow input.
java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll Adds a Java implementation of getFlowNodeId and exposes it via getTypeFlowNodeId.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 3

Comment on lines +48 to +51
/**
* Gets an identifier for node `n`, if any. When not implemented for a given node,
* the library will use location-based ranking.
*/
Comment on lines +32 to +35
/**
* Gets an identifier for node `n`, if any. When not implemented for a given node,
* the library will use location-based ranking.
*/
a = 0 and
idOf(n0.asField(), b)
or
// no case for `n0.asSsa()`; here we rely on the built-in location-based ranking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants