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.

Migration Guide

Use AttachScript and DetachScript in favour of AddStaticScript RemovStaticScript, CreateOrUpdateScript and DeleteScript

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  54% smaller
  crates/bevy_mod_scripting_core/src/script/script_context.rs  49% smaller
  examples/game_of_life.rs  37% smaller
  crates/testing_crates/script_integration_test_harness/src/scenario.rs  30% smaller
  crates/testing_crates/script_integration_test_harness/src/lib.rs  15% smaller
  crates/bevy_mod_scripting_core/src/commands.rs  4% smaller
  crates/testing_crates/script_integration_test_harness/src/parse.rs  2% smaller
  crates/bevy_mod_scripting_core/src/lib.rs  1% smaller
  crates/bevy_mod_scripting_core/src/event.rs  1% smaller
  .github/workflows/bevy_mod_scripting.yml Unsupported file format
  assets/tests/add_system/added_systems_run_in_parallel.rhai Unsupported file format
  assets/tests/lifecycle/default/entity_script/callback/scenario.txt Unsupported file format
  assets/tests/lifecycle/default/static_script/callback/scenario.txt 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
  assets/tests/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/pipeline/hooks.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/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
  docs/book.toml Unsupported file format
  docs/mermaid-init.js  0% smaller
  docs/mermaid.min.js Unsupported file format
  docs/src/ReleaseNotes/0.15-to-0.16.md Unsupported file format
  docs/src/ReleaseNotes/0.16.0.md Unsupported file format
  docs/src/SUMMARY.md Unsupported file format
  docs/src/ScriptPipeline/pipeline.md Unsupported file format
  docs/src/Summary/contexts.md Unsupported file format
  docs/src/Summary/customizing-script-contexts.md Unsupported file format
  docs/src/Summary/managing-scripts.md Unsupported file format
  docs/src/Summary/running-scripts.md Unsupported file format
  src/prelude.rs  0% smaller
  xtask/src/main.rs  0% smaller

Copy link
Contributor

github-actions bot commented Sep 18, 2025

🐰 Bencher Report

Branchfeat/improved-script-pipeline
Testbedlinux-gha
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
nanoseconds (ns)
(Result Δ%)
Upper Boundary
nanoseconds (ns)
(Limit %)
component/access Lua📈 view plot
🚷 view threshold
4,517.30 ns
(+10.65%)Baseline: 4,082.35 ns
4,535.15 ns
(99.61%)
component/access Rhai📈 view plot
🚷 view threshold
5,532.40 ns
(-6.20%)Baseline: 5,897.95 ns
6,332.95 ns
(87.36%)
component/get Lua📈 view plot
🚷 view threshold
2,355.40 ns
(-2.40%)Baseline: 2,413.33 ns
2,587.65 ns
(91.02%)
component/get Rhai📈 view plot
🚷 view threshold
4,276.70 ns
(-3.25%)Baseline: 4,420.36 ns
4,840.52 ns
(88.35%)
conversions/Mut::from📈 view plot
🚷 view threshold
79.33 ns
(-8.01%)Baseline: 86.23 ns
94.52 ns
(83.93%)
conversions/Ref::from📈 view plot
🚷 view threshold
77.19 ns
(-9.23%)Baseline: 85.04 ns
96.45 ns
(80.03%)
conversions/ScriptValue::List📈 view plot
🚷 view threshold
347.88 ns
(+12.30%)Baseline: 309.76 ns
422.71 ns
(82.30%)
conversions/ScriptValue::Map📈 view plot
🚷 view threshold
1,140.60 ns
(+3.89%)Baseline: 1,097.86 ns
1,344.32 ns
(84.85%)
conversions/ScriptValue::Reference::from_into📈 view plot
🚷 view threshold
26.55 ns
(+2.67%)Baseline: 25.86 ns
31.16 ns
(85.20%)
conversions/Val::from_into📈 view plot
🚷 view threshold
299.21 ns
(-0.16%)Baseline: 299.68 ns
343.49 ns
(87.11%)
function/call 4 args Lua📈 view plot
🚷 view threshold
1,553.80 ns
(-16.00%)Baseline: 1,849.85 ns
2,157.03 ns
(72.03%)
function/call 4 args Rhai📈 view plot
🚷 view threshold
1,365.20 ns
(-9.62%)Baseline: 1,510.52 ns
1,691.73 ns
(80.70%)
function/call Lua📈 view plot
🚷 view threshold
222.55 ns
(-8.38%)Baseline: 242.90 ns
273.54 ns
(81.36%)
function/call Rhai📈 view plot
🚷 view threshold
454.00 ns
(-3.11%)Baseline: 468.56 ns
523.81 ns
(86.67%)
loading/empty Lua📈 view plot
🚷 view threshold
898.23 ns
(-98.46%)Baseline: 58,407.72 ns
112,585.00 ns
(0.80%)
loading/empty Rhai📈 view plot
🚷 view threshold
853.22 ns
(-99.76%)Baseline: 352,096.32 ns
688,427.78 ns
(0.12%)
math/vec mat ops Lua📈 view plot
🚷 view threshold
7,029.10 ns
(-11.34%)Baseline: 7,927.77 ns
9,314.03 ns
(75.47%)
math/vec mat ops Rhai📈 view plot
🚷 view threshold
6,372.80 ns
(-4.44%)Baseline: 6,669.01 ns
7,232.45 ns
(88.11%)
query/10 entities Lua📈 view plot
🚷 view threshold
17,944.00 ns
(-12.23%)Baseline: 20,443.70 ns
23,032.00 ns
(77.91%)
query/10 entities Rhai📈 view plot
🚷 view threshold
18,435.00 ns
(-10.60%)Baseline: 20,619.80 ns
22,929.07 ns
(80.40%)
query/100 entities Lua📈 view plot
🚷 view threshold
38,294.00 ns
(-9.95%)Baseline: 42,523.70 ns
46,995.53 ns
(81.48%)
query/100 entities Rhai📈 view plot
🚷 view threshold
33,280.00 ns
(-1.94%)Baseline: 33,939.40 ns
36,685.60 ns
(90.72%)
query/1000 entities Lua📈 view plot
🚷 view threshold
279,440.00 ns
(+0.21%)Baseline: 278,865.00 ns
296,016.90 ns
(94.40%)
query/1000 entities Rhai📈 view plot
🚷 view threshold
170,960.00 ns
(+0.59%)Baseline: 169,956.00 ns
181,318.99 ns
(94.29%)
reflection/10 Lua📈 view plot
🚷 view threshold
5,570.60 ns
(-10.10%)Baseline: 6,196.64 ns
6,874.97 ns
(81.03%)
reflection/10 Rhai📈 view plot
🚷 view threshold
14,823.00 ns
(-6.13%)Baseline: 15,790.90 ns
16,753.25 ns
(88.48%)
reflection/100 Lua📈 view plot
🚷 view threshold
48,128.00 ns
(-6.96%)Baseline: 51,730.30 ns
57,387.20 ns
(83.87%)
reflection/100 Rhai📈 view plot
🚷 view threshold
731,160.00 ns
(-5.29%)Baseline: 771,998.00 ns
853,077.67 ns
(85.71%)
resource/access Lua📈 view plot
🚷 view threshold
3,240.80 ns
(-8.77%)Baseline: 3,552.33 ns
3,892.96 ns
(83.25%)
resource/access Rhai📈 view plot
🚷 view threshold
5,123.40 ns
(-4.72%)Baseline: 5,377.43 ns
5,748.08 ns
(89.13%)
resource/get Lua📈 view plot
🚷 view threshold
1,897.50 ns
(-6.87%)Baseline: 2,037.37 ns
2,217.88 ns
(85.55%)
resource/get Rhai📈 view plot
🚷 view threshold
3,842.70 ns
(-2.78%)Baseline: 3,952.49 ns
4,304.46 ns
(89.27%)
🐰 View full continuous benchmarking report in Bencher

@makspll makspll enabled auto-merge (squash) September 22, 2025 15:53
@makspll makspll disabled auto-merge September 22, 2025 17:54
@makspll makspll merged commit 9b8ad29 into main Sep 22, 2025
4 checks passed
@makspll makspll deleted the feat/improved-script-pipeline branch September 22, 2025 17:54
This was referenced Sep 22, 2025
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