Skip to content

perf: perform shadow variable update exactly once#2305

Merged
triceo merged 5 commits into
TimefoldAI:mainfrom
Christopher-Chianelli:perf/ignore-changeset-when-updating
May 14, 2026
Merged

perf: perform shadow variable update exactly once#2305
triceo merged 5 commits into
TimefoldAI:mainfrom
Christopher-Chianelli:perf/ignore-changeset-when-updating

Conversation

@Christopher-Chianelli
Copy link
Copy Markdown
Contributor

There were a couple of inefficiently discovered

  • When a declarative shadow variable changes, it goes through the same plumbing as other variables. This is wasteful, since by definition, declarative shadow variables cannot affect the structure of the graph, and the graphs already modify the queues directly.

  • When group alignment is used in a fixed graph, the same entity's update might be called multiple times. This is because the change set is a priority queue, which allows duplicate elements.

Now:

  • We shortcut before/after variable change to return immediately if the graph is currently updating

  • For fixed graphs, we have a seperate bitset to ensure the same node cannot be added to the changed queue multiple times.

There were a couple of inefficiently discovered

- When a declarative shadow variable changes, it goes through the same
  plumbing as other variables. This is wasteful, since by definition,
  declarative shadow variables cannot affect the structure of the graph,
  and the graphs already modify the queues directly.

- When group alignment is used in a fixed graph, the same entity's
  update might be called multiple times. This is because the change set
  is a priority queue, which allows duplicate elements.

Now:

- We shortcut before/after variable change to return immediately if
  the graph is currently updating

- For fixed graphs, we have a seperate bitset to ensure the same node
  cannot be added to the changed queue multiple times.
Profiling showed calculating the forward edges was taking significant
time on some datasets. Sinced fixed graphs cannot change, they can
cache each node's forward edges on construction.
Before, DefaultTopologicalOrderGraph's `nodeForwardEdges` returned
the `componentForwardEdges` instead, creating unneccessary waste and
compute.
Copy link
Copy Markdown
Collaborator

@triceo triceo left a comment

Choose a reason for hiding this comment

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

I like it! LGTM when comments resolved.

I started the microbenchmark suite; I may have some questions after I see the results.

@triceo triceo modified the milestone: v2.2.0 May 14, 2026
@sonarqubecloud
Copy link
Copy Markdown

@triceo triceo merged commit eeed053 into TimefoldAI:main May 14, 2026
19 checks passed
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.

perf: shadow variable update is unneccessary called multiple times

2 participants