diff --git a/assets/macro_benchmarks/loading/empty.lua b/assets/macro_benchmarks/loading/empty.lua new file mode 100644 index 0000000000..5c34ba5ce7 --- /dev/null +++ b/assets/macro_benchmarks/loading/empty.lua @@ -0,0 +1,2 @@ +function on_script_loaded() +end \ No newline at end of file diff --git a/assets/macro_benchmarks/loading/empty.rhai b/assets/macro_benchmarks/loading/empty.rhai new file mode 100644 index 0000000000..38c0148929 --- /dev/null +++ b/assets/macro_benchmarks/loading/empty.rhai @@ -0,0 +1,3 @@ +fn on_script_loaded(){ + +} \ No newline at end of file diff --git a/benches/benchmarks.rs b/benches/benchmarks.rs index d4b96f391f..c69109c5e5 100644 --- a/benches/benchmarks.rs +++ b/benches/benchmarks.rs @@ -11,7 +11,8 @@ use criterion::{BatchSize, BenchmarkFilter}; use regex::Regex; use script_integration_test_harness::test_functions::rand::Rng; use script_integration_test_harness::{ - perform_benchmark_with_generator, run_lua_benchmark, run_rhai_benchmark, + make_test_lua_plugin, make_test_rhai_plugin, perform_benchmark_with_generator, + run_lua_benchmark, run_plugin_script_load_benchmark, run_rhai_benchmark, }; use std::collections::HashMap; use std::{path::PathBuf, sync::LazyLock, time::Duration}; @@ -241,6 +242,34 @@ fn conversion_benchmarks(criterion: &mut Criterion) { ); } +fn script_load_benchmarks(criterion: &mut Criterion) { + let mut group = criterion.benchmark_group("loading"); + let reload_probability = 0.5; + // lua + let plugin = make_test_lua_plugin(); + let content = include_str!("../assets/macro_benchmarks/loading/empty.lua"); + run_plugin_script_load_benchmark( + plugin, + "empty Lua", + content, + &mut group, + |rand| format!("{rand}.lua"), + reload_probability, + ); + + // rhai + let plugin = make_test_rhai_plugin(); + let content = include_str!("../assets/macro_benchmarks/loading/empty.rhai"); + run_plugin_script_load_benchmark( + plugin, + "empty Rhai", + content, + &mut group, + |rand| format!("{rand}.rhai"), + reload_probability, + ); +} + pub fn benches() { maybe_with_profiler(|_profiler| { let mut criterion: criterion::Criterion<_> = (criterion::Criterion::default()) @@ -265,6 +294,7 @@ pub fn benches() { script_benchmarks(&mut criterion, filter); conversion_benchmarks(&mut criterion); + script_load_benchmarks(&mut criterion); }); } criterion_main!(benches); diff --git a/crates/testing_crates/script_integration_test_harness/src/lib.rs b/crates/testing_crates/script_integration_test_harness/src/lib.rs index 7a2ebe890a..fa039361e7 100644 --- a/crates/testing_crates/script_integration_test_harness/src/lib.rs +++ b/crates/testing_crates/script_integration_test_harness/src/lib.rs @@ -14,10 +14,12 @@ use bevy::{ event::{Event, Events}, schedule::{IntoSystemConfigs, SystemConfigs}, system::{IntoSystem, Local, Res, Resource, SystemState}, - world::{FromWorld, Mut}, + world::{Command, FromWorld, Mut}, }, + log::Level, prelude::{Entity, World}, reflect::{Reflect, TypeRegistry}, + utils::tracing, }; use bevy_mod_scripting_core::{ asset::ScriptAsset, @@ -26,6 +28,7 @@ use bevy_mod_scripting_core::{ ReflectAccessId, WorldAccessGuard, WorldGuard, }, callback_labels, + commands::CreateOrUpdateScript, error::{InteropError, ScriptError}, event::{IntoCallbackLabel, ScriptErrorEvent}, extractors::{HandlerContext, WithWorldGuard}, @@ -68,6 +71,22 @@ impl TestCallbackBuilder } } +pub fn install_test_plugin( + app: &mut bevy::app::App, + plugin: P, + include_test_functions: bool, +) { + app.add_plugins(( + ScriptFunctionsPlugin, + CoreScriptGlobalsPlugin::default(), + BMSScriptingInfrastructurePlugin, + plugin, + )); + if include_test_functions { + register_test_functions(app); + } +} + #[cfg(feature = "lua")] pub fn make_test_lua_plugin() -> bevy_mod_scripting_lua::LuaScriptingPlugin { use bevy_mod_scripting_core::{bindings::WorldContainer, ConfigureScriptPlugin}; @@ -203,14 +222,7 @@ pub fn execute_integration_test< let mut app = setup_integration_test(init); - app.add_plugins(( - ScriptFunctionsPlugin, - CoreScriptGlobalsPlugin::default(), - BMSScriptingInfrastructurePlugin, - plugin, - )); - - register_test_functions(&mut app); + install_test_plugin(&mut app, plugin, true); app.add_event::(); @@ -411,13 +423,7 @@ where let mut app = setup_integration_test(|_, _| {}); - app.add_plugins(( - ScriptFunctionsPlugin, - CoreScriptGlobalsPlugin::default(), - BMSScriptingInfrastructurePlugin, - plugin, - )); - register_test_functions(&mut app); + install_test_plugin(&mut app, plugin, true); let script_id = script_id.to_owned(); let script_id_clone = script_id.clone(); @@ -468,6 +474,55 @@ where } } +pub fn run_plugin_script_load_benchmark< + P: IntoScriptPluginParams + Plugin + FromWorld, + M: Measurement, +>( + plugin: P, + benchmark_id: &str, + content: &str, + criterion: &mut criterion::BenchmarkGroup, + script_id_generator: impl Fn(u64) -> String, + reload_probability: f32, +) { + let mut app = setup_integration_test(|_, _| {}); + install_test_plugin(&mut app, plugin, false); + let mut rng_guard = RNG.lock().unwrap(); + *rng_guard = rand_chacha::ChaCha12Rng::from_seed([42u8; 32]); + drop(rng_guard); + criterion.bench_function(benchmark_id, |c| { + c.iter_batched( + || { + let mut rng = RNG.lock().unwrap(); + let is_reload = rng.random_range(0f32..=1f32) < reload_probability; + let random_id = if is_reload { 0 } else { rng.random::() }; + + let random_script_id = script_id_generator(random_id); + // we manually load the script inside a command + let content = content.to_string().into_boxed_str(); + ( + CreateOrUpdateScript::

::new( + random_script_id.into(), + content.clone().into(), + None, + ), + is_reload, + ) + }, + |(command, _is_reload)| { + tracing::event!( + Level::TRACE, + "profiling_iter {} is reload?: {}", + benchmark_id, + _is_reload + ); + command.apply(app.world_mut()); + }, + BatchSize::LargeInput, + ); + }); +} + pub fn perform_benchmark_with_generator< M: Measurement, I, diff --git a/docs/generated_docs.html b/docs/generated_docs.html deleted file mode 100644 index e03efd0dd1..0000000000 --- a/docs/generated_docs.html +++ /dev/null @@ -1,237 +0,0 @@ - - - - - - Generated Docs - Bevy Scripting - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - -
- -
- - - - - - - - -
-
-

Generated Docs

-

Contents

-

This is an automatically generated file, you'll find links to the contents below

- -
- - -
-
- - - -
- - - - - - - - - - - - - - - - - - - - - -
- -