File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed
Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -235,8 +235,13 @@ impl AppBuilder {
235235 where
236236 R : FromResources + Send + Sync + ' static ,
237237 {
238- let resource = R :: from_resources ( & self . app . resources ) ;
239- self . app . resources . insert ( resource) ;
238+ // PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed not to
239+ // modify the map. However, we would need to be borrowing resources both mutably and immutably,
240+ // so we would need to be extremely certain this is correct
241+ if !self . resources ( ) . contains :: < R > ( ) {
242+ let resource = R :: from_resources ( & self . resources ( ) ) ;
243+ self . add_resource ( resource) ;
244+ }
240245
241246 self
242247 }
@@ -245,8 +250,11 @@ impl AppBuilder {
245250 where
246251 R : FromResources + ' static ,
247252 {
248- let resource = R :: from_resources ( & self . app . resources ) ;
249- self . app . resources . insert_thread_local ( resource) ;
253+ // See perf comment in init_resource
254+ if self . app . resources . get_thread_local :: < R > ( ) . is_none ( ) {
255+ let resource = R :: from_resources ( & self . app . resources ) ;
256+ self . app . resources . insert_thread_local ( resource) ;
257+ }
250258
251259 self
252260 }
Original file line number Diff line number Diff line change @@ -177,9 +177,7 @@ impl Plugin for RenderPlugin {
177177 shader:: clear_shader_defs_system. system ( ) ,
178178 ) ;
179179
180- if app. resources ( ) . get :: < Msaa > ( ) . is_none ( ) {
181- app. init_resource :: < Msaa > ( ) ;
182- }
180+ app. init_resource :: < Msaa > ( ) ;
183181
184182 if let Some ( ref config) = self . base_render_graph_config {
185183 let resources = app. resources ( ) ;
You can’t perform that action at this time.
0 commit comments