bevy icon indicating copy to clipboard operation
bevy copied to clipboard

optimize batch_and_prepare_render_phase

Open re0312 opened this issue 2 years ago • 2 comments

Objective

  • since #9685 ,bevy introduce automatic batching of draw commands,

  • batch_and_prepare_render_phase take the responsibility for batching phaseItem,

  • GetBatchData trait is used for indentify each phaseitem how to batch. it defines a associated type Data used for Query to fetch data from world.

  • however,the impl of GetBatchData in bevy always set type Data=Entity then we acually get following code let entity:Entity =query.get(item.entity()) that cause unnecessary overhead .

Solution

  • remove associated type Data and Filter from GetBatchData ,
  • change the type of the query_item parameter in get_batch_data from Self::Data to Entity.
  • batch_and_prepare_render_phase no longer takes a query using F::Data, F::Filter
  • get_batch_data now returns Option<(Self::BufferData, Option<Self::CompareData>)>

Performance

based in main merged with #11290 Window 11 ,Intel 13400kf, NV 4070Ti image frame time from 3.34ms to 3 ms, ~ 10%

image 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

re0312 avatar Jan 13 '24 05:01 re0312

@matiqo15 Perhaps the label 'C-Performance' would be more suitable for this topic.

re0312 avatar Jan 13 '24 15:01 re0312

Could you update the "solution" part of the description with your latest changes?

done!

re0312 avatar Jan 18 '24 20:01 re0312