optimize batch_and_prepare_render_phase
Objective
-
since #9685 ,bevy introduce automatic batching of draw commands,
-
batch_and_prepare_render_phasetake the responsibility for batchingphaseItem, -
GetBatchDatatrait is used for indentify each phaseitem how to batch. it defines a associated typeDataused for Query to fetch data from world. -
however,the impl of
GetBatchDatain bevy always settype Data=Entitythen we acually get following codelet entity:Entity =query.get(item.entity())that cause unnecessary overhead .
Solution
- remove associated type
DataandFilterfromGetBatchData, - change the type of the
query_itemparameter in get_batch_data fromSelf::DatatoEntity. -
batch_and_prepare_render_phaseno longer takes a query usingF::Data, F::Filter -
get_batch_datanow returnsOption<(Self::BufferData, Option<Self::CompareData>)>
Performance
based in main merged with #11290
Window 11 ,Intel 13400kf, NV 4070Ti
frame time from 3.34ms to 3 ms, ~ 10%
batch_and_prepare_render_phase from 800us ~ 400 us
Migration Guide
trait GetBatchData no longer hold associated type Data and Filter
get_batch_data query_item type from Self::Data to Entity and return Option<(Self::BufferData, Option<Self::CompareData>)>
batch_and_prepare_render_phase should not have a query
@matiqo15 Perhaps the label 'C-Performance' would be more suitable for this topic.
Could you update the "solution" part of the description with your latest changes?
done!