Skip to content
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

Consider making mutating Assets<T> more Scheduler friendly #8

Closed
cart opened this issue May 17, 2020 · 5 comments
Closed

Consider making mutating Assets<T> more Scheduler friendly #8

cart opened this issue May 17, 2020 · 5 comments
Labels
A-Assets Load files from disk to use for things like images, models, and sounds A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times S-Needs-Design This issue requires design work to think about how it would best be accomplished

Comments

@cart
Copy link
Member

cart commented May 17, 2020

Modifying an asset currently requires grabbing a mutable reference to Assets<T>. This makes sense conceptually, but Legion's Scheduler (correctly) synchronizes when a mutable reference is grabbed. This means multiple systems requiring mut access to the same Assets<T> storage cant run in parallel.

It is worth adding some interior mutability / RwLocks to Assets<T> to see if this improves performance for common use cases.

@Moxinilian
Copy link
Member

Wouldn’t it encourage making large systems? To me making small systems is good practice because it makes parallelism better and as a result should reduce the cost of mutable asset modification, maybe?

@cart
Copy link
Member Author

cart commented Jun 25, 2020

Whats your definition of "system size" in this case? Number of Resource dependencies or number entities matching a query?

I agree that keeping the Resource dependency count down is a good idea (for the reasons you state), but that holds true no matter what. I'm not convinced artificially making it harder to use specific resource types is a productive mindset. The change above would also enable inner-system parallelism (query.par_iter) when mutating Assets, which I think by itself justifies the change and offsets the cost of making it easier to take dependencies on more resources.

@Moxinilian
Copy link
Member

Moxinilian commented Jun 25, 2020

System size to me is the amount of work it does on a run. In a sense this is somewhat linked to the amount of dependencies but not really.

But come to think of it, if it’s an optional way to optimize some really specific cases that can’t be solved otherwise, it seems okay to me.

@karroffel karroffel added A-Assets Load files from disk to use for things like images, models, and sounds A-ECS Entities, components, systems, and events labels Aug 12, 2020
@alice-i-cecile alice-i-cecile added the C-Performance A change motivated by improving speed, memory usage or compile times label Mar 7, 2021
superdump referenced this issue in superdump/bevy Jul 2, 2021
cart pushed a commit that referenced this issue Jul 24, 2021
cart pushed a commit that referenced this issue Jul 24, 2021
@alice-i-cecile alice-i-cecile added the S-Needs-Investigation This issue requires detective work to figure out what's going wrong label Dec 12, 2021
@alice-i-cecile alice-i-cecile added S-Needs-Design This issue requires design work to think about how it would best be accomplished and removed S-Needs-Investigation This issue requires detective work to figure out what's going wrong labels Apr 26, 2022
@alice-i-cecile alice-i-cecile moved this to Wishlist in Asset Pipeline Jul 17, 2022
jespersm pushed a commit to jespersm/bevy that referenced this issue Oct 22, 2022
@alice-i-cecile
Copy link
Member

alice-i-cecile commented Oct 27, 2022

We encountered this in #6341, where there were a large number of spurious system order ambiguities caused by Assets<Image>.

@cart
Copy link
Member Author

cart commented Aug 12, 2023

Closing this because I'm not convinced it is worth solving. The odds of multiple systems writing assets at the same time (and that being a bottleneck) is slim, whereas something like RwLock-ing everything would be a constant overhead.

If this ever shows up in benchmarks we can reconsider.

@cart cart closed this as completed Aug 12, 2023
nicoburns pushed a commit to nicoburns/bevy that referenced this issue Jun 19, 2024
tychedelia pushed a commit to tychedelia/bevy that referenced this issue Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times S-Needs-Design This issue requires design work to think about how it would best be accomplished
Projects
Status: Wishlist
Development

No branches or pull requests

4 participants