Skip to content

Conversation

makspll
Copy link
Owner

@makspll makspll commented Sep 15, 2025

Summary

THe current process for loading/unloading scripts is entirely controlled via CreateOrUpdate and Delete script commands, this is fairly simple but inflexible. Adding new callbacks requires support from the core crate.

The new and improved pipeline decentralizes the process of loading and unloading across a new ScriptProcessingSchedule::<P>.

The schedule contains a multitude of systems which process attachment/detachment and asset modification events. Callbacks themselves are now systems which react to state transitions within this schedule.

The schedule is ran manually via commands (it's not inserted into the MainScheduleOrder), specifically whether or not it is run each frame is determined by the RequestProcessingPipelineRun::<P> resource. A few "frontend" systems listen to user emitted events such as ScriptAttachmentEvent and ScriptDetachmentEvent (now split out from the ScriptEvent enum into standalone structs), and trigger processing pipeline runs.

the lifecycle commands like AddStaticScript and CreateOrUpdateScript and DeleteScript commands have been removed in favour of AttachScript and DetachScript commands, which invoke the necessary events, and immediately run the processing pipeline, resulting in more predictable loading behavior.

Copy link

semanticdiff-com bot commented Sep 15, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/bevy_mod_scripting_core/src/script/mod.rs  72% smaller
  assets/tests/add_system/added_systems_run_in_parallel.lua  72% smaller
  crates/bevy_mod_scripting_core/src/script/script_context.rs  49% smaller
  examples/game_of_life.rs  35% smaller
  crates/testing_crates/script_integration_test_harness/src/scenario.rs  26% smaller
  crates/testing_crates/script_integration_test_harness/src/lib.rs  18% smaller
  crates/bevy_mod_scripting_core/src/commands.rs  2% smaller
  crates/bevy_mod_scripting_core/src/lib.rs  1% smaller
  assets/tests/add_system/added_systems_run_in_parallel.rhai Unsupported file format
  assets/tests/lifecycle/shared/entity_script/scenario.txt Unsupported file format
  assets/tests/lifecycle/shared/static_script/scenario.txt Unsupported file format
  crates/bevy_mod_scripting_asset/src/script_asset.rs  0% smaller
  crates/bevy_mod_scripting_core/src/asset.rs  0% smaller
  crates/bevy_mod_scripting_core/src/event.rs  0% smaller
  crates/bevy_mod_scripting_core/src/pipeline/finish.rs  0% smaller
  crates/bevy_mod_scripting_core/src/pipeline/hooks.rs  0% smaller
  crates/bevy_mod_scripting_core/src/pipeline/insert.rs  0% smaller
  crates/bevy_mod_scripting_core/src/pipeline/machines.rs  0% smaller
  crates/bevy_mod_scripting_core/src/pipeline/mod.rs  0% smaller
  crates/bevy_mod_scripting_core/src/pipeline/start.rs  0% smaller
  crates/bevy_mod_scripting_core/src/pipeline/update.rs  0% smaller
  crates/bevy_mod_scripting_core/src/script/context_key.rs  0% smaller
  crates/bindings/bevy_color_bms_bindings/Cargo.toml Unsupported file format
  crates/bindings/bevy_ecs_bms_bindings/Cargo.toml Unsupported file format
  crates/bindings/bevy_image_bms_bindings/Cargo.toml Unsupported file format
  crates/bindings/bevy_math_bms_bindings/Cargo.toml Unsupported file format
  crates/bindings/bevy_reflect_bms_bindings/src/lib.rs Unsupported file format
  crates/bindings/bevy_transform_bms_bindings/Cargo.toml Unsupported file format
  crates/languages/bevy_mod_scripting_lua/src/lib.rs  0% smaller
  crates/languages/bevy_mod_scripting_rhai/src/lib.rs  0% smaller
  src/prelude.rs  0% smaller

Copy link
Contributor

github-actions bot commented Sep 18, 2025

🐰 Bencher Report

Branchfeat/improved-script-pipeline
Testbedlinux-gha

🚨 2 Alerts

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
loading/empty LuaLatency
milliseconds (ms)
📈 plot
🚷 threshold
🚨 alert (🔔)
1.34 ms
(+596.08%)Baseline: 0.19 ms
1.27 ms
(105.37%)

loading/empty RhaiLatency
milliseconds (ms)
📈 plot
🚷 threshold
🚨 alert (🔔)
1.05 ms
(+128.96%)Baseline: 0.46 ms
1.01 ms
(103.10%)

Click to view all benchmark results
BenchmarkLatencyBenchmark Result
nanoseconds (ns)
(Result Δ%)
Upper Boundary
nanoseconds (ns)
(Limit %)
component/access Lua📈 view plot
🚷 view threshold
3,667.70 ns
(-8.25%)Baseline: 3,997.39 ns
4,363.23 ns
(84.06%)
component/access Rhai📈 view plot
🚷 view threshold
5,352.00 ns
(-8.98%)Baseline: 5,879.91 ns
6,443.41 ns
(83.06%)
component/get Lua📈 view plot
🚷 view threshold
2,273.50 ns
(-5.47%)Baseline: 2,405.14 ns
2,611.90 ns
(87.04%)
component/get Rhai📈 view plot
🚷 view threshold
4,098.40 ns
(-6.91%)Baseline: 4,402.53 ns
4,892.52 ns
(83.77%)
conversions/Mut::from📈 view plot
🚷 view threshold
79.40 ns
(-7.93%)Baseline: 86.24 ns
94.48 ns
(84.04%)
conversions/Ref::from📈 view plot
🚷 view threshold
75.60 ns
(-10.94%)Baseline: 84.88 ns
97.21 ns
(77.77%)
conversions/ScriptValue::List📈 view plot
🚷 view threshold
340.69 ns
(+10.24%)Baseline: 309.05 ns
420.21 ns
(81.08%)
conversions/ScriptValue::Map📈 view plot
🚷 view threshold
1,020.60 ns
(-6.01%)Baseline: 1,085.86 ns
1,336.64 ns
(76.36%)
conversions/ScriptValue::Reference::from_into📈 view plot
🚷 view threshold
25.06 ns
(-2.52%)Baseline: 25.71 ns
31.01 ns
(80.83%)
conversions/Val::from_into📈 view plot
🚷 view threshold
267.20 ns
(-9.88%)Baseline: 296.48 ns
348.22 ns
(76.73%)
function/call 4 args Lua📈 view plot
🚷 view threshold
1,563.50 ns
(-15.52%)Baseline: 1,850.82 ns
2,150.58 ns
(72.70%)
function/call 4 args Rhai📈 view plot
🚷 view threshold
1,331.90 ns
(-11.63%)Baseline: 1,507.19 ns
1,710.50 ns
(77.87%)
function/call Lua📈 view plot
🚷 view threshold
226.36 ns
(-6.96%)Baseline: 243.28 ns
272.02 ns
(83.22%)
function/call Rhai📈 view plot
🚷 view threshold
445.50 ns
(-4.75%)Baseline: 467.71 ns
525.17 ns
(84.83%)
loading/empty Lua📈 view plot
🚷 view threshold
🚨 view alert (🔔)
1,335,700.00 ns
(+596.08%)Baseline: 191,887.90 ns
1,267,624.08 ns
(105.37%)

loading/empty Rhai📈 view plot
🚷 view threshold
🚨 view alert (🔔)
1,045,300.00 ns
(+128.96%)Baseline: 456,541.00 ns
1,013,853.69 ns
(103.10%)

math/vec mat ops Lua📈 view plot
🚷 view threshold
6,947.10 ns
(-12.28%)Baseline: 7,919.57 ns
9,349.20 ns
(74.31%)
math/vec mat ops Rhai📈 view plot
🚷 view threshold
6,107.70 ns
(-8.05%)Baseline: 6,642.50 ns
7,344.52 ns
(83.16%)
query/10 entities Lua📈 view plot
🚷 view threshold
18,598.00 ns
(-9.32%)Baseline: 20,509.10 ns
22,607.42 ns
(82.27%)
query/10 entities Rhai📈 view plot
🚷 view threshold
18,245.00 ns
(-11.44%)Baseline: 20,600.80 ns
23,054.27 ns
(79.14%)
query/100 entities Lua📈 view plot
🚷 view threshold
40,720.00 ns
(-4.78%)Baseline: 42,766.30 ns
45,572.89 ns
(89.35%)
query/100 entities Rhai📈 view plot
🚷 view threshold
29,096.00 ns
(-13.20%)Baseline: 33,521.00 ns
38,468.34 ns
(75.64%)
query/1000 entities Lua📈 view plot
🚷 view threshold
258,670.00 ns
(-6.55%)Baseline: 276,788.00 ns
300,959.12 ns
(85.95%)
query/1000 entities Rhai📈 view plot
🚷 view threshold
158,230.00 ns
(-6.20%)Baseline: 168,683.00 ns
183,678.70 ns
(86.14%)
reflection/10 Lua📈 view plot
🚷 view threshold
5,602.70 ns
(-9.63%)Baseline: 6,199.85 ns
6,854.73 ns
(81.73%)
reflection/10 Rhai📈 view plot
🚷 view threshold
14,375.00 ns
(-8.71%)Baseline: 15,746.10 ns
17,072.85 ns
(84.20%)
reflection/100 Lua📈 view plot
🚷 view threshold
48,307.00 ns
(-6.65%)Baseline: 51,748.20 ns
57,315.68 ns
(84.28%)
reflection/100 Rhai📈 view plot
🚷 view threshold
727,880.00 ns
(-5.67%)Baseline: 771,670.00 ns
854,101.06 ns
(85.22%)
resource/access Lua📈 view plot
🚷 view threshold
3,246.70 ns
(-8.62%)Baseline: 3,552.92 ns
3,889.26 ns
(83.48%)
resource/access Rhai📈 view plot
🚷 view threshold
4,824.40 ns
(-9.78%)Baseline: 5,347.53 ns
5,915.30 ns
(81.56%)
resource/get Lua📈 view plot
🚷 view threshold
1,842.70 ns
(-9.31%)Baseline: 2,031.89 ns
2,248.55 ns
(81.95%)
resource/get Rhai📈 view plot
🚷 view threshold
3,660.90 ns
(-6.95%)Baseline: 3,934.31 ns
4,357.79 ns
(84.01%)
🐰 View full continuous benchmarking report in Bencher

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant