Skip to content

perf: less PositionInList allocations - #2681

Merged
triceo merged 5 commits into
TimefoldAI:mainfrom
triceo:perf/position-in-list-allocations
Sep 22, 2026
Merged

triceo merged 5 commits into
TimefoldAI:mainfrom
triceo:perf/position-in-list-allocations

Conversation

@triceo

@triceo triceo commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@triceo
triceo requested review from a team and a lite review from Copilot September 21, 2026 09:34
@triceo
triceo removed the request for review from Christopher-Chianelli September 21, 2026 09:35
@triceo triceo self-assigned this Sep 21, 2026
@triceo triceo added this to the v2.8.0-rc-1 milestone Sep 21, 2026

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.

Copilot review overview

🟡 Changes recommended

The updated Javadoc code block uses invalid HTML nesting that may render incorrectly in generated documentation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

This PR reduces runtime allocations related to list variable element position lookups by switching hot-path code from ElementPosition materialization to direct inverse lookups, and adds regression tests to ensure consistency between these APIs.

Changes:

  • Replace getElementPosition(... ) instanceof PositionInList usage with getInverseSingleton(...) in FilteringValueRangeSelector to avoid allocating PositionInList.
  • Simplify pinned-element filtering in ListChangeMoveSelector by delegating to ListVariableState.isPinned(...) (avoids per-candidate ElementPosition allocation).
  • Add tests verifying getInverseSingleton(...) and getElementPosition(...) stay consistent, including when inverse is externalized.
File Description
core/​src/​test/​java/​ai/​timefold/​solver/​core/​impl/​domain/​variable/​DefaultListVariableStateTest.java Adds coverage to ensure inverse lookups and element-position reporting remain consistent across internal/externalized storage.
core/​src/​main/​java/​ai/​timefold/​solver/​core/​impl/​heuristic/​selector/​value/​decorator/​FilteringValueRangeSelector.java Uses inverse lookups instead of element position objects on the reachability path to reduce allocations; updates Javadoc example formatting.
core/​src/​main/​java/​ai/​timefold/​solver/​core/​impl/​heuristic/​selector/​move/​generic/​list/​ListChangeMoveSelector.java Switches pinned filtering to ListVariableState.isPinned(...) to avoid allocating element position objects per candidate.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@triceo
triceo marked this pull request as draft September 21, 2026 10:51
@triceo
triceo marked this pull request as ready for review September 21, 2026 11:56
Copilot AI review requested due to automatic review settings September 21, 2026 11:56

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.

Copilot review overview

🔵 Needs a closer look

The updated Javadoc uses invalid HTML nesting and there is avoidable allocation overhead introduced in a performance-sensitive initialization branch.

Review effort: Lite
Findings: 1 Low severity

Open (1)
Previously missed (1)

In code that hasn't changed since last review

Low severity Avoid allocating unused unassigned value set

core/​src/​main/​java/​ai/​timefold/​solver/​core/​impl/​domain/​variable/​ListVariableStateCarrier.java:107

When shouldUnassignElements is false (first initialization with expectShadowVariablesInCorrectState() true), unassignedValueSet is still allocated at initialUnassignedCount capacity even though it is never used, which is avoidable overhead on a performance-sensitive path.

Copilot AI review requested due to automatic review settings September 22, 2026 06:32
@triceo
triceo requested review from Christopher-Chianelli and removed request for Christopher-Chianelli September 22, 2026 06:33
@triceo
triceo dismissed Christopher-Chianelli’s stale review September 22, 2026 06:34

The review comments have been accepted and resolved.
In order to not let this PR stay open any longer, and considering this PR has another approving review already, I will merge as is.

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.

Copilot review overview

🔵 Needs a closer look

The updated Javadoc example in FilteringValueRangeSelector uses invalid HTML tag nesting that should be corrected to avoid doclint/Javadoc rendering issues.

Review effort: Lite
Findings: 1 Low severity

Open (1)

Copilot AI review requested due to automatic review settings September 22, 2026 06:37

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.

Copilot review overview

🔵 Needs a closer look

It changes core list-variable shadow initialization/reset semantics and selection behavior on performance-sensitive paths, warranting final human review.

Review effort: Lite
Findings: None

Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 22, 2026 06:42

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.

Copilot review overview

🟢 Approval recommended

The changes are performance-focused, maintain behavioral intent, and are backed by new tests covering key consistency and reset edge cases.

Review effort: Lite
Findings: None

@triceo
triceo merged commit a283288 into TimefoldAI:main Sep 22, 2026
26 of 28 checks passed
@triceo
triceo deleted the perf/position-in-list-allocations branch September 22, 2026 07:23

This branch was successfully deployed

1 active deployment
internal 74f0da6f Deployed Sep 22, 2026 by triceo via approval_required #4858
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.

4 participants