Skip to content

Improved graph.luau performance#77

Closed
Olaroll wants to merge 2 commits into
centau:mainfrom
Olaroll:graph-performance
Closed

Improved graph.luau performance#77
Olaroll wants to merge 2 commits into
centau:mainfrom
Olaroll:graph-performance

Conversation

@Olaroll

@Olaroll Olaroll commented Jul 7, 2026

Copy link
Copy Markdown

This PR should significantly increase Vide's performance, especially in cases where sources are being updated every frame.

In our game, I noticed that upon updating lots of camera distance sources every frame, there was a lot of performance being lost to Vide's source update internals, before it even got to my effect callbacks. Upon drilling down, I found the main culprit to be the find_and_swap_pop() function, because it was doing removals with table.find().

I did a pass on the whole graph.luau file, keeping all behavior the same overall, but removing all cases of table.find() and unoptimized loops. For our game, this made the aforementioned camera distance updates 4x faster.

Here's the thoughts behind the changes:

  1. Main thing was to rework node children and owned table from an array into a set ({ Node } -> { [Node]: true }). This means iteration becomes unordered, but that should be fine because find_and_swap_pop() was changing the order arbitrarily anyway.
  2. There was another table.find() being used on scopes, so I added an accompanying active_nodes set, which can be used to easily check if a node is present in scopes.
  3. I deleted get_children() entirely because it isn't used anywhere in the codebase and I figured the main reason for its existence was that the children were stored as a mixed table. Now they can just be indexed directly via node.children. Didn't see it was used for tests. Re-implemented as get_children_as_array() to make it clear it's not free and a transformation is happening under the hood.

@Olaroll

Olaroll commented Jul 7, 2026

Copy link
Copy Markdown
Author

Oh I see, the get_children() function was used for tests, I had my global search filtered to /src. I'll re-implement it.

@Olaroll

Olaroll commented Jul 7, 2026

Copy link
Copy Markdown
Author

Found out there's a benchmark in the repo which ended up revealing some performance regressions in other areas. Sadly there doesn't seem to be any obvious way of fixing the regressions, so I'll have to take another look another day. I'll close the PR for now. If I find some breakthrough, I'll make a new one.

@Olaroll Olaroll closed this Jul 7, 2026
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.

2 participants