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 {
235
235
where
236
236
R : FromResources + Send + Sync + ' static ,
237
237
{
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
+ }
240
245
241
246
self
242
247
}
@@ -245,8 +250,11 @@ impl AppBuilder {
245
250
where
246
251
R : FromResources + ' static ,
247
252
{
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
+ }
250
258
251
259
self
252
260
}
Original file line number Diff line number Diff line change @@ -177,9 +177,7 @@ impl Plugin for RenderPlugin {
177
177
shader:: clear_shader_defs_system. system ( ) ,
178
178
) ;
179
179
180
- if app. resources ( ) . get :: < Msaa > ( ) . is_none ( ) {
181
- app. init_resource :: < Msaa > ( ) ;
182
- }
180
+ app. init_resource :: < Msaa > ( ) ;
183
181
184
182
if let Some ( ref config) = self . base_render_graph_config {
185
183
let resources = app. resources ( ) ;
You can’t perform that action at this time.
0 commit comments