#Optimisation related to queries

9 messages · Page 1 of 1 (latest)

chrome briar
#

Hello, I am currently writing a physics engine for a school project, and I am looking to optimize my iterations, mostly on queries.
I use the same query type for my systems so it's easier when refactoring (early on in the project), and i wonder if naming the potentially unused variables (such as _transform if i don't need it) will be optimized away ? Or if i should discard the name (such as _)
I'm not familiar enough with profiling and assembly, so I'm not able to analyze and confirm if that's the case.

I know this is more a rust question than a bevy one, but perhaps this is a common problem

Thank you !

tame ore
#

those components won't be optimized away, no. If you specify that a query contains a component then it will always fetch that component, which has a (relatively small) amount of overhead and more importantly can inhibit parallelization. It's recommended to query for what you need, not a premade set of components, for best performance. Using .for_each() instead of for loops can also improve performance.

#

there's also no difference between transform, _transform, and _; if it can optimize out one, it will optimize out all. In this case it can't optimize any out though

#

(and you'll get a warning lint for transform most likely)

chrome briar
#

Okay, i think i'll custom fit the queries then. (The transform lint is exactly what made me ask if using _ hinted/allowed the compiler to optimize away)

#

Can i query multiple time the same component in the same system if it's not mutable ?

tame ore
#

yes

#

but only if it's not mutable. Any mutable accesses will have to be the only access

chrome briar
#

Thanks, I managed to grab ~5/10% by rearranging queries 🥳