Skip to content

Comments

Server GridFixtureSystem Optimizations#6415

Open
Aidenkrz wants to merge 1 commit intospace-wizards:masterfrom
Aidenkrz:GridStuff
Open

Server GridFixtureSystem Optimizations#6415
Aidenkrz wants to merge 1 commit intospace-wizards:masterfrom
Aidenkrz:GridStuff

Conversation

@Aidenkrz
Copy link
Contributor

@Aidenkrz Aidenkrz commented Feb 8, 2026

About the PR

Optimizes GridFixtureSystem in a few hot paths that were doing more work (and allocating more garbage) than they really needed to.

Why / Balance

One of my maintainers pointed out that there was some evil LINQ garbage in this system that called .Sum() a bajillion times whenever CheckSplits ran. Not the end of the world, but also easily avoidable. This cleans that up and makes the whole thing scale way better without changing behavior. Also noticed system was allocating new collections constantly, so i changed that as well.

Technical details

  • The BFS scratch structures (_splitFrontier queue and _splitGrids list) are now reused as class fields instead of being allocated every CheckSplits call.

  • The sort comparator was doing repeated LINQ .Sum() calls, resulting in something like
    $O(N \times M \times \log N)$ work.
    This is now replaced with a precomputed gridSizes dictionary, bringing it down to
    $O(N \times M + N \times \log N)$.

    As a rough example:

    • For N = 50 grids with M = 100 tiles each, this cuts the comparator work by ~90%.
    • For N = 200 grids with M = 250 tiles each, it’s closer to a ~97% reduction.

    I didn't do any real benchmarking as I don't have dottrace, but I mean, the math checks out.

  • In CreateNodes, the tile HashSet now only tracks non-empty tiles (capacity set to chunk.FilledTiles) instead of blindly allocating for all 256 chunk positions.

  • Cross-chunk neighbor detection now bails early for interior tiles, since only edge tiles can possibly have neighbors in adjacent chunks.

@Aidenkrz
Copy link
Contributor Author

Aidenkrz commented Feb 8, 2026

accidentally left the PR title as the commit name and cant change it now 👎

@ArtisticRoomba
Copy link
Member

github stays winning

@Tayrtahn
Copy link
Member

Tayrtahn commented Feb 8, 2026

Apparently you can still change it from the mobile app. You can also just tell me what title you'd like and I'll change it for you.

@Aidenkrz Aidenkrz changed the title Optimization pass Server GridFixtureSystem Optimizations Feb 8, 2026
@Aidenkrz
Copy link
Contributor Author

Aidenkrz commented Feb 8, 2026

Apparently you can still change it from the mobile app. You can also just tell me what title you'd like and I'll change it for you.

Thanks I used GitHub mobile

Copy link
Contributor

@moonheart08 moonheart08 left a comment

Choose a reason for hiding this comment

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

Looking for footage of this being tested, ideally, just as a "this obviously works". The changes lgtm though.

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