-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove petgraph
from bevy_ecs
#15519
base: main
Are you sure you want to change the base?
Remove petgraph
from bevy_ecs
#15519
Conversation
Replaced with specialised solution based on original types.
You probably want to verify that |
I do agree, Additionally, adding a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very pleased to see this trimmed down. I think there's a good chance we want a more prinicipled bevy_graph
at some point (or just use systems-as-entities), but this is an excellent ECS code quality / maintainability change in its own right, independent of the no_std implications.
@DasLixou if you're around, I'd appreciate your eyes here :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting change, I wonder how it performs and how much is really stripped away.
Also good to know that a bevy graph crate could need such fine grained specialization, that's something I had in mind, but I'm currently a bit "frustrated" at coding, no bevy graph in near time so this is cool to have :D
|
||
iter.copied() | ||
.map(CompactNodeIdAndDirection::load) | ||
.filter_map(|(n, dir)| (!DIRECTED || dir == Outgoing).then_some(n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we only use Outgoing edges for directed graphs? aren't neighbors also incoming edges?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a hangover from petgraph
, but I believe the rationale is that a neighbour is something you can go to from your current node. So in a <-> b
, both a
and b
are neighbours. Whereas, in a --> b
, b
is a neighbour of a
, but not the other way around. I could change this, but I wanted to keep the API here as-close-as possible to petgraph
to avoid subtle translation errors for contributors moving to the new type.
- Removed instances of `&NodeId` in function arguments since `NodeId` is copy and only two `usize`'s wide. - Changed documentation references to `O(V)` to `O(N)` (nodes instead of verticies) Co-Authored-By: Lixou <82600264+DasLixou@users.noreply.github.com>
Co-Authored-By: Lixou <82600264+DasLixou@users.noreply.github.com>
I haven't tested the performance myself (currently only have access to a pretty mediocre laptop!) but I suspect a marginal performance improvement at runtime, and a negligible compilation boost (I observed Packing the
I am hoping that bringing this type in-tree and specialising to just empty edges and |
Allows for a minimal-allocation iterator interface. Also switched to `SmallVec` to improve performance in sparse graphs (the more likely use-case)
Ok so I did some benchmarking and it appears that this change might've been more impactful than I had planned! cargo bench -- schedule --load-baseline NoPetgraph --baseline Main
For benchmarks that run in less a few milliseconds, I'd call that a wash (plus or minus 10% is within variance that I'd expect from the binary layout changing). However, for the |
Did some additional testing on my desktop (Ryzen 5950X, Windows 10, 64GB or RAM) to see if the benchmark results were repeatable: cargo bench -- schedule --load-baseline NoPetgraph --baseline Main
Looks like that ~30% performance uplift is repeatable (in this case up to 45% even!), so I'm more confident in saying there's a fairly significant performance boost here. Looking at the
As to why there's a performance uplift, I can think of a couple changes I made which might be the reason:
Aside from the above, I'm not sure what else could really affect performance this drastically. Aside from the |
Will this effect the toposort? The current toposort isn't stable, but we do eventually want to make the topo sort stable. So users don't get their game randomly behaving differently in different |
No, actually! The reason is the nodes are all sorted in an |
The `nocase` naming was a hangover from the `petgraph` migration. Co-Authored-By: vero <11307157+atlv24@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't do a super close review of the graph algorithms, but otherwise looks good.
Waiting until 0.16 for stability reasons, but I will merge this. |
Objective
no_std
Bevy #15460Solution
petgraph
as a dependency from thebevy_ecs
crate.TarjanScc
andGraphMap
with specialised in-tree alternatives.Testing
petgraph
is no longer present incargo tree -p bevy_ecs
Migration Guide
The
Dag::graph
method no longer returns apetgraph
DiGraph
and instead returns the newDiGraph
type withinbevy_ecs
. Edge and node iteration methods are provided so conversion to thepetgraph
type should be trivial if required.Notes
indexmap
was already in the dependency graph forbevy_ecs
, so its inclusion here makes no difference to compilation time for Bevy.Graph
is heavily inspired from thepetgraph
original, with specialisations added to simplify and improve the type.petgraph
does have public plans forno_std
support, however there is no timeframe on if or when that functionality will be available. Moving to an in-house solution in the interim allows Bevy to continue developing itsno_std
offerings and further explore alternate graphing options.