Skip to content

Commit 3238617

Browse files
committed
2 parents c099807 + 040cc4a commit 3238617

File tree

166 files changed

+6234
-2918
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+6234
-2918
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Run benchmarks on PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, edited, synchronize]
6+
7+
jobs:
8+
benchmark_fork_pr_branch:
9+
name: Run Fork PR Benchmarks
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Rust Cache
14+
uses: Swatinem/[email protected]
15+
with:
16+
# reasoning: we want to cache xtask, most of the jobs in the matrix will be sped up a good bit thanks to that
17+
save-if: ${{ github.ref == 'refs/heads/main' }}
18+
cache-all-crates: true
19+
- name: Run `cargo xtask init`
20+
run: |
21+
cargo xtask init
22+
- name: Run `cargo xtask bench` and save results
23+
run: |
24+
cargo xtask bench > benchmark_results.txt
25+
- name: Upload Benchmark Results
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: benchmark_results.txt
29+
path: ./benchmark_results.txt
30+
- name: Upload GitHub Pull Request Event
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: event.json
34+
path: ${{ github.event_path }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
on:
2+
pull_request_target:
3+
types: [closed]
4+
5+
jobs:
6+
archive_fork_pr_branch:
7+
name: Archive closed fork PR branch with Bencher
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: bencherdev/bencher@main
12+
- name: Archive closed fork PR branch with Bencher
13+
run: |
14+
bencher archive \
15+
--project bms \
16+
--token '${{ secrets.BENCHER_API_TOKEN }}' \
17+
--branch "$GITHUB_HEAD_REF"
18+
continue-on-error: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Upload benchmarks to bencher
2+
3+
on:
4+
workflow_run:
5+
workflows: [Run benchmarks on PR]
6+
types: [completed]
7+
8+
permissions: write-all
9+
10+
jobs:
11+
track_fork_pr_branch:
12+
if: github.event.workflow_run.conclusion == 'success'
13+
runs-on: ubuntu-latest
14+
env:
15+
BENCHMARK_RESULTS: benchmark_results.txt
16+
PR_EVENT: event.json
17+
steps:
18+
- name: Download Benchmark Results
19+
uses: dawidd6/action-download-artifact@v6
20+
with:
21+
name: ${{ env.BENCHMARK_RESULTS }}
22+
run_id: ${{ github.event.workflow_run.id }}
23+
- name: Download PR Event
24+
uses: dawidd6/action-download-artifact@v6
25+
with:
26+
name: ${{ env.PR_EVENT }}
27+
run_id: ${{ github.event.workflow_run.id }}
28+
- name: Export PR Event Data
29+
uses: actions/github-script@v6
30+
with:
31+
script: |
32+
let fs = require('fs');
33+
let prEvent = JSON.parse(fs.readFileSync(process.env.PR_EVENT, {encoding: 'utf8'}));
34+
core.exportVariable("PR_HEAD", prEvent.pull_request.head.ref);
35+
core.exportVariable("PR_BASE", prEvent.pull_request.base.ref);
36+
core.exportVariable("PR_BASE_SHA", prEvent.pull_request.base.sha);
37+
core.exportVariable("PR_NUMBER", prEvent.number);
38+
- uses: bencherdev/bencher@main
39+
- name: Track Benchmarks with Bencher
40+
run: |
41+
bencher run \
42+
--project bms \
43+
--token '${{ secrets.BENCHER_API_TOKEN }}' \
44+
--branch "$PR_HEAD" \
45+
--start-point "$PR_BASE" \
46+
--start-point-hash "$PR_BASE_SHA" \
47+
--start-point-clone-thresholds \
48+
--start-point-reset \
49+
--testbed linux-gha \
50+
--err \
51+
--adapter rust_criterion \
52+
--github-actions '${{ secrets.GITHUB_TOKEN }}' \
53+
--ci-number "$PR_NUMBER" \
54+
--file "$BENCHMARK_RESULTS"

.github/workflows/bevy_mod_scripting.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ env:
1616
IMAGE_NAME: bevy-mod-scripting
1717
CODEGEN_BRANCH_NAME: __update-bevy-bindings-${{ github.head_ref || github.ref_name }}
1818
GH_TOKEN: ${{ github.token }}
19-
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
BENCHER_API_TOKEN: ${{ secrets.BENCHER_API_TOKEN }}
21+
2022
concurrency:
2123
# Use github.run_id on main branch
2224
# Use github.event.pull_request.number on pull requests, so it's unique per pull request
@@ -79,6 +81,7 @@ jobs:
7981
pull-requests: write
8082
contents: write
8183
issues: write
84+
checks: write
8285
name: Check - ${{ matrix.run_args.name }}
8386
runs-on: ${{ matrix.run_args.os }}
8487
strategy:

.github/workflows/mdbook.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ on:
99
- 'docs/**'
1010
- 'crates/xtask/**'
1111
- '.github/workflows/mdbook.yml'
12+
- 'crates/bevy_mod_scripting_functions/**'
1213
pull_request:
1314
branches:
1415
- "**"
1516
paths:
1617
- 'docs/**'
1718
- 'crates/xtask/**'
1819
- '.github/workflows/mdbook.yml'
20+
- 'crates/bevy_mod_scripting_functions/**'
1921

2022
jobs:
2123

.github/workflows/pr-titles.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ jobs:
2727
test
2828
docs
2929
refactor
30+
perf
3031
3132
scopes: |
3233
ladfile
3334
ladfile_builder
34-
bms
35+
bms

CHANGELOG.md

+49
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,54 @@
11
# Changelog
22

3+
## [0.12.0](https://github.com/makspll/bevy_mod_scripting/compare/v0.11.1...v0.12.0) - 2025-04-07
4+
5+
### Added
6+
7+
- improve errors when entity is unavailable ([#410](https://github.com/makspll/bevy_mod_scripting/pull/410))
8+
- [**breaking**] Add `BMSPlugin` group, feature flag for bindings per bevy crate & add script global filter options ([#408](https://github.com/makspll/bevy_mod_scripting/pull/408))
9+
- The CoreScriptGlobalsPlugin now also stores options for filtering registered globals, which can be changed.
10+
- add option to emit response event on each callback & `RunScriptCallback` command for "once-off" callbacks ([#403](https://github.com/makspll/bevy_mod_scripting/pull/403))
11+
### Fixed
12+
13+
- `lua54` feature being forced ([#413](https://github.com/makspll/bevy_mod_scripting/pull/413))
14+
- `GetTypeDependency` derive macro using the wrong path for `bms_core` ([#409](https://github.com/makspll/bevy_mod_scripting/pull/409))
15+
16+
### Other
17+
18+
- add script loading benchmark ([#411](https://github.com/makspll/bevy_mod_scripting/pull/411))
19+
- refactor `ReflectReference` internally ([#406](https://github.com/makspll/bevy_mod_scripting/pull/406))
20+
- reduces size of `ScriptValue` to 64 bytes, moves some dynamic function methods into function info ([#404](https://github.com/makspll/bevy_mod_scripting/pull/404))
21+
22+
## [0.11.1](https://github.com/makspll/bevy_mod_scripting/compare/v0.11.0...v0.11.1) - 2025-03-29
23+
24+
### Added
25+
26+
- bump bevy to 0.15.3 ([#401](https://github.com/makspll/bevy_mod_scripting/pull/401))
27+
28+
## [0.11.0](https://github.com/makspll/bevy_mod_scripting/compare/v0.10.0...v0.11.0) - 2025-03-29
29+
30+
### Added
31+
32+
- allow the conversion of lua functions into `ScriptValue` via `DynamicScriptFunction` ([#396](https://github.com/makspll/bevy_mod_scripting/pull/396))
33+
- improve tracing spans, add more benchmarks ([#394](https://github.com/makspll/bevy_mod_scripting/pull/394))
34+
- add `profile_with_tracy` feature which plays nicely with bevy's `bevy/trace_tracy` feature ([#393](https://github.com/makspll/bevy_mod_scripting/pull/393))
35+
- Add initial benchmarks, integrate them into CI & add getters/settters for `Scripts` resource ([#381](https://github.com/makspll/bevy_mod_scripting/pull/381))
36+
- :sparkles: Dynamic Script Components, `register_new_component` binding, `remove_component` no longer requires `ReflectComponent` data ([#379](https://github.com/makspll/bevy_mod_scripting/pull/379))
37+
- [**breaking**] optimize `get` and `set` functions, add `MagicFunctions` sub-registry ([#397](https://github.com/makspll/bevy_mod_scripting/pull/397))
38+
- optimize access map ([#395](https://github.com/makspll/bevy_mod_scripting/pull/395))
39+
- add ScriptValue override for printing opaque values ([#380](https://github.com/makspll/bevy_mod_scripting/pull/380))
40+
- overhaul mdbook preprocessor, prettify generated docs, support dummy globals ([#377](https://github.com/makspll/bevy_mod_scripting/pull/377))
41+
42+
### Fixed
43+
44+
- fix global type cache not containing generic types ([#388](https://github.com/makspll/bevy_mod_scripting/pull/388))
45+
46+
### Other
47+
48+
- switch to hashbrown hashmap in the function registry ([#399](https://github.com/makspll/bevy_mod_scripting/pull/399))
49+
- try play with hashing for access maps ([#398](https://github.com/makspll/bevy_mod_scripting/pull/398))
50+
- allow check creation for bencher
51+
352
## [0.10.0](https://github.com/makspll/bevy_mod_scripting/compare/v0.9.11...v0.10.0) - 2025-03-16
453

554
### Added

Cargo.toml

+49-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_mod_scripting"
3-
version = "0.10.0"
3+
version = "0.12.0"
44
authors = ["Maksymilian Mozolewski <[email protected]>"]
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
@@ -15,15 +15,28 @@ include = ["readme.md", "/src", "/examples", "/assets", "LICENSE", "/badges"]
1515
[lib]
1616
name = "bevy_mod_scripting"
1717
path = "src/lib.rs"
18+
bench = false
1819

1920
[package.metadata."docs.rs"]
2021
features = ["lua54", "rhai"]
2122

2223
[features]
23-
default = ["core_functions", "bevy_bindings"]
24+
default = [
25+
"core_functions",
26+
"bevy_core_bindings",
27+
"bevy_ecs_bindings",
28+
"bevy_hierarchy_bindings",
29+
"bevy_input_bindings",
30+
"bevy_math_bindings",
31+
"bevy_reflect_bindings",
32+
"bevy_time_bindings",
33+
"bevy_transform_bindings",
34+
]
2435

25-
## lua
26-
lua = ["bevy_mod_scripting_lua", "bevy_mod_scripting_functions/lua_bindings"]
36+
lua = [
37+
"bevy_mod_scripting_lua",
38+
"bevy_mod_scripting_functions/lua_bindings",
39+
] ## lua
2740
# one of these must be selected
2841
lua51 = ["bevy_mod_scripting_lua/lua51", "lua"]
2942
lua52 = ["bevy_mod_scripting_lua/lua52", "lua"]
@@ -35,7 +48,14 @@ luau = ["bevy_mod_scripting_lua/luau", "lua"]
3548

3649
# bindings
3750
core_functions = ["bevy_mod_scripting_functions/core_functions"]
38-
bevy_bindings = ["bevy_mod_scripting_functions/bevy_bindings"]
51+
bevy_core_bindings = ["bevy_mod_scripting_functions/bevy_core"]
52+
bevy_ecs_bindings = ["bevy_mod_scripting_functions/bevy_ecs"]
53+
bevy_hierarchy_bindings = ["bevy_mod_scripting_functions/bevy_hierarchy"]
54+
bevy_input_bindings = ["bevy_mod_scripting_functions/bevy_input"]
55+
bevy_math_bindings = ["bevy_mod_scripting_functions/bevy_math"]
56+
bevy_reflect_bindings = ["bevy_mod_scripting_functions/bevy_reflect"]
57+
bevy_time_bindings = ["bevy_mod_scripting_functions/bevy_time"]
58+
bevy_transform_bindings = ["bevy_mod_scripting_functions/bevy_transform"]
3959

4060
# optional
4161
unsafe_lua_modules = ["bevy_mod_scripting_lua?/unsafe_lua_modules"]
@@ -50,21 +70,24 @@ rhai = ["bevy_mod_scripting_rhai", "bevy_mod_scripting_functions/rhai_bindings"]
5070
## rune
5171
# rune = ["bevy_mod_scripting_rune"]
5272

73+
### Profiling
74+
profile_with_tracy = ["bevy/trace_tracy"]
75+
5376
[dependencies]
5477
bevy = { workspace = true }
5578
bevy_mod_scripting_core = { workspace = true }
56-
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.10.0", optional = true }
57-
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.10.0", optional = true }
79+
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.12.0", optional = true }
80+
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.12.0", optional = true }
5881
# bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.9.0-alpha.2", optional = true }
5982
bevy_mod_scripting_functions = { workspace = true }
6083
bevy_mod_scripting_derive = { workspace = true }
6184

6285
[workspace.dependencies]
6386
profiling = { version = "1.0" }
64-
bevy = { version = "0.15.2", default-features = false }
65-
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.10.0" }
66-
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.10.0", default-features = false }
67-
bevy_mod_scripting_derive = { path = "crates/bevy_mod_scripting_derive", version = "0.10.0" }
87+
bevy = { version = "0.15.3", default-features = false }
88+
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.12.0" }
89+
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.12.0", default-features = false }
90+
bevy_mod_scripting_derive = { path = "crates/bevy_mod_scripting_derive", version = "0.12.0" }
6891

6992
# test utilities
7093
script_integration_test_harness = { path = "crates/testing_crates/script_integration_test_harness" }
@@ -76,8 +99,14 @@ clap = { version = "4.1", features = ["derive"] }
7699
rand = "0.8.5"
77100
bevy_console = "0.13"
78101
# rhai-rand = "0.1"
102+
criterion = { version = "0.5" }
79103
ansi-parser = "0.9"
80-
ladfile_builder = { path = "crates/ladfile_builder", version = "0.2.6" }
104+
ladfile_builder = { path = "crates/ladfile_builder", version = "0.3.2" }
105+
script_integration_test_harness = { workspace = true }
106+
test_utils = { workspace = true }
107+
libtest-mimic = "0.8"
108+
tracing-tracy = "0.11"
109+
regex = "1.11"
81110

82111
[workspace]
83112
members = [
@@ -149,3 +178,11 @@ todo = "deny"
149178

150179
[workspace.lints.rust]
151180
missing_docs = "deny"
181+
182+
[[bench]]
183+
name = "benchmarks"
184+
harness = false
185+
186+
[[test]]
187+
name = "script_tests"
188+
harness = false
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
local entity_with_component = world._get_entity_with_test_component("TestComponent")
2+
3+
function bench()
4+
local strings = world.get_component(entity_with_component, types.TestComponent).strings
5+
end
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let entity_with_component = world._get_entity_with_test_component.call("TestComponent");
2+
3+
fn bench(){
4+
let strings = world.get_component.call(entity_with_component, types.TestComponent).strings;
5+
}

assets/benchmarks/component/get.lua

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
local entity_with_component = world._get_entity_with_test_component("TestComponent")
2+
3+
function bench()
4+
world.get_component(entity_with_component, types.TestComponent)
5+
end

assets/benchmarks/component/get.rhai

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let entity_with_component = world._get_entity_with_test_component.call("TestComponent");
2+
3+
fn bench(){
4+
world.get_component.call(entity_with_component, types.TestComponent);
5+
}

assets/benchmarks/function/call.lua

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function bench()
2+
noop()
3+
end

assets/benchmarks/function/call.rhai

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn bench(){
2+
noop.call();
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function bench()
2+
noop_4_args(1,"asd",{1,2,3}, {asd = 1})
3+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn bench(){
2+
noop_4_args.call(1,"asd",[1,2,3],#{ asd: 1});
3+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
reseed()
3+
4+
local matrix = nil
5+
local vector = nil
6+
function pre_bench()
7+
-- generate random 3x3 matrix and 3x1 vec
8+
vector = Vec3.new(random(1,999), random(1,999), random(1,999))
9+
matrix = Mat3.from_cols(
10+
Vec3.new(random(1,999), random(1,999), random(1,999)),
11+
Vec3.new(random(1,999), random(1,999), random(1,999)),
12+
Vec3.new(random(1,999), random(1,999), random(1,999))
13+
)
14+
end
15+
16+
function bench()
17+
local mul = matrix * vector
18+
local add = matrix + vector
19+
local div = vector / matrix
20+
end

0 commit comments

Comments
 (0)