@@ -4,7 +4,6 @@ pub mod test_functions;
44
55use std:: {
66 path:: PathBuf ,
7- sync:: Mutex ,
87 time:: { Duration , Instant } ,
98} ;
109
@@ -21,9 +20,7 @@ use ::{
2120 } ,
2221 bevy_reflect:: Reflect ,
2322} ;
24- use bevy_app:: PreUpdate ;
2523use bevy_asset:: Assets ;
26- use bevy_ecs:: world:: World ;
2724use bevy_mod_scripting_asset:: ScriptAsset ;
2825use bevy_mod_scripting_bindings:: {
2926 CoreScriptGlobalsPlugin , ReflectAccessId , ThreadWorldContainer , WorldAccessGuard ,
@@ -341,73 +338,40 @@ where
341338
342339pub fn run_plugin_script_load_benchmark <
343340 P : IntoScriptPluginParams + Plugin + FromWorld ,
341+ F : Fn ( ) -> P ,
344342 M : Measurement ,
345343> (
346- plugin : P ,
344+ plugin_maker : F ,
347345 benchmark_id : & str ,
348346 content : & str ,
349347 criterion : & mut criterion:: BenchmarkGroup < M > ,
350- reload_probability : f32 ,
351348) {
352- let mut app = setup_integration_test ( |_, _| { } ) ;
353- install_test_plugin ( & mut app, false ) ;
354- app. add_plugins ( plugin) ;
355349 let content_boxed = content. to_string ( ) . into_bytes ( ) . into_boxed_slice ( ) ;
356- let mut rng_guard = RNG . lock ( ) . unwrap ( ) ;
357- * rng_guard = rand_chacha:: ChaCha12Rng :: from_seed ( [ 42u8 ; 32 ] ) ;
358- drop ( rng_guard) ;
359350
360- let world_ptr = app. world_mut ( ) as * mut World ;
361- let world_guard = Mutex :: < ( ) > :: new ( ( ) ) ;
362351 criterion. bench_function ( benchmark_id, |c| {
363352 c. iter_batched (
364353 || {
365- let mut rng = RNG . lock ( ) . unwrap ( ) ;
366- let is_reload = rng. random_range ( 0f32 ..=1f32 ) < reload_probability;
354+ let mut app = setup_integration_test ( |_, _| { } ) ;
355+ install_test_plugin ( & mut app, false ) ;
356+ app. add_plugins ( plugin_maker ( ) ) ;
367357
368- // println!("Setup {idx}, {is_reload}");
369- let guard = world_guard. lock ( ) . unwrap ( ) ;
370358 // Safety: we claimed a unique guard, only code accessing this will need to do the same
371- let world = unsafe { & mut * world_ptr } ;
359+ let world = app . world_mut ( ) ;
372360 let mut assets = world. get_resource_or_init :: < Assets < ScriptAsset > > ( ) ;
373361
374- let id = is_reload
375- . then ( || assets. ids ( ) . next ( ) )
376- . flatten ( )
377- . and_then ( |id| assets. get_strong_handle ( id) )
378- . unwrap_or_else ( || {
379- assets. add ( ScriptAsset {
380- content : content_boxed. clone ( ) ,
381- language : P :: LANGUAGE ,
382- } )
383- } ) ;
384- // otherwise causes random overflows due to a u16 tracking strong handles
385-
386- // also remove assets apart from the first two
387- assets
388- . ids ( )
389- . skip ( 2 )
390- . collect :: < Vec < _ > > ( )
391- . into_iter ( )
392- . for_each ( |asset| _ = assets. remove ( asset) ) ;
393-
394- // run track assets (lives in PreUpdate), so handles can be dropped internally
395- world. run_schedule ( PreUpdate ) ;
396- drop ( guard) ;
362+ let id = assets. add ( ScriptAsset {
363+ content : content_boxed. clone ( ) ,
364+ language : P :: LANGUAGE ,
365+ } ) ;
397366
398367 // We manually load the script inside a command.
399368 (
369+ app,
400370 AttachScript :: < P > :: new ( ScriptAttachment :: StaticScript ( id) ) ,
401- is_reload,
402371 )
403372 } ,
404- |( command, _is_reload) | {
405- tracing:: event!(
406- Level :: TRACE ,
407- "profiling_iter {} is reload?: {}" ,
408- benchmark_id,
409- _is_reload
410- ) ;
373+ |( mut app, command) | {
374+ tracing:: event!( Level :: TRACE , "profiling_iter {}" , benchmark_id) ;
411375 command. apply ( app. world_mut ( ) ) ;
412376 } ,
413377 BatchSize :: LargeInput ,
0 commit comments