Skip to content

Conversation

makspll
Copy link
Owner

@makspll makspll commented Oct 19, 2025

Summary

Adds ReferencePath and ReferencePart structs, which serve as alternatives to ParsedPath from bevy. These do not make assumptions about the pointed to type, i.e. IntegerAccess versus FieldAccess, allowing for more flexibility, and removing the need for underscores like _1 in accessing tuples and tuple structs.

Adds Map and Set support to references. (Except for mutable references into sets, which apparently don't have Reflection support 🤷)

Note this allows refing into maps and sets with arbitrary types (say custom structs) but functions still only support string Key'ed HashMaps

Why

Bevy reflection paths are not particularly well suited to this crate, they make the assumption that the consumer knows the structure of your types, which in the case of scripting is not always the case. Ideally the path system should be flexible, and forgivable, while also allowing any kind of access into your types.

Bevy currently does not support Maps or Sets in ParsedPath, which historically meant that you were stuck using map_get bindings and pass by value semantics (no modifying the upstream values by reference).

With this change, consumers will be able to:

  • modify through Map types
  • reference into Map types with arbitrary values (see tests)
  • Reference through Set types (but not modify, due to other reflection limitations)

Migration Guide

Replace accesses to tuple structs, and tuples containing underscores, i.e. instead of my_tuple._1 use my_tuple[1]

@semanticdiff-com
Copy link

semanticdiff-com bot commented Oct 19, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  assets/tests/construct/construct_enum.lua  96% smaller
  assets/tests/get_component/component_no_component_data.lua  96% smaller
  assets/tests/add_default_component/component_with_default_and_component_data_adds_default.lua  94% smaller
  assets/tests/add_default_component/component_with_from_world_and_component_data_adds_default.lua  94% smaller
  crates/bevy_mod_scripting_bindings/src/error.rs  78% smaller
  crates/testing_crates/script_integration_test_harness/src/scenario.rs  75% smaller
  crates/bevy_mod_scripting_bindings/src/function/from_ref.rs  75% smaller
  crates/testing_crates/script_integration_test_harness/src/parse.rs  55% smaller
  crates/bevy_mod_scripting_bindings/src/reference.rs  33% smaller
  crates/bevy_mod_scripting_bindings/src/function/into_ref.rs  30% smaller
  crates/bevy_mod_scripting_bindings/src/function/magic_functions.rs  29% smaller
  assets/tests/display/print_value_by_default.lua  22% smaller
  crates/bevy_mod_scripting_asset/src/language.rs  21% smaller
  crates/testing_crates/test_utils/src/test_data.rs  13% smaller
  assets/tests/query/query_can_access_components.lua  7% smaller
  crates/bevy_mod_scripting_bindings/src/query.rs  7% smaller
  crates/bevy_mod_scripting_bindings/src/function/from.rs  1% smaller
  crates/bevy_mod_scripting_bindings/src/script_value.rs  1% smaller
  crates/bevy_mod_scripting_bindings/src/world.rs  1% smaller
  assets/tests/add_default_component/component_with_default_and_component_data_adds_default.rhai Unsupported file format
  assets/tests/add_default_component/component_with_from_world_and_component_data_adds_default.rhai Unsupported file format
  assets/tests/construct/construct_tuple_struct.lua  0% smaller
  assets/tests/construct/simple_enum.rhai Unsupported file format
  assets/tests/construct/simple_tuple_struct.rhai Unsupported file format
  assets/tests/get_component/component_no_component_data.rhai Unsupported file format
  assets/tests/get_resource/no_resource_data_returns_resource.lua  0% smaller
  assets/tests/get_resource/no_resource_data_returns_resource.rhai Unsupported file format
  assets/tests/query/query_can_access_components.rhai Unsupported file format
  assets/tests/set/set_primitives_works.lua  0% smaller
  crates/bevy_mod_scripting_bindings/src/conversions/mod.rs  0% smaller
  crates/bevy_mod_scripting_bindings/src/conversions/primitive.rs  0% smaller
  crates/bevy_mod_scripting_bindings/src/function/script_function.rs  0% smaller
  crates/bevy_mod_scripting_bindings/src/lib.rs  0% smaller
  crates/bevy_mod_scripting_bindings/src/path/mod.rs  0% smaller
  crates/bevy_mod_scripting_bindings/src/reflection_extensions.rs  0% smaller
  crates/bevy_mod_scripting_display/src/impls/bevy_reflect.rs  0% smaller

@makspll
Copy link
Owner Author

makspll commented Oct 19, 2025

Tackles parts of #487 and #341 (FYI @aggyomfg)

@github-actions
Copy link
Contributor

github-actions bot commented Oct 19, 2025

🐰 Bencher Report

Branchfeat/overhauled-references
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
3,666.20 ns
(-10.61%)Baseline: 4,101.16 ns
4,731.86 ns
(77.48%)
component/access Rhai📈 view plot
🚷 view threshold
5,592.50 ns
(-5.95%)Baseline: 5,946.04 ns
6,310.98 ns
(88.62%)
component/get Lua📈 view plot
🚷 view threshold
2,381.90 ns
(-4.10%)Baseline: 2,483.72 ns
2,786.35 ns
(85.48%)
component/get Rhai📈 view plot
🚷 view threshold
4,221.90 ns
(-5.43%)Baseline: 4,464.28 ns
4,839.05 ns
(87.25%)
conversions/Mut::from📈 view plot
🚷 view threshold
94.78 ns
(+6.69%)Baseline: 88.84 ns
96.13 ns
(98.60%)
conversions/Ref::from📈 view plot
🚷 view threshold
91.22 ns
(+4.58%)Baseline: 87.22 ns
96.46 ns
(94.56%)
conversions/ScriptValue::List📈 view plot
🚷 view threshold
374.86 ns
(+9.04%)Baseline: 343.77 ns
462.81 ns
(81.00%)
conversions/ScriptValue::Map📈 view plot
🚷 view threshold
975.99 ns
(-9.99%)Baseline: 1,084.29 ns
1,228.61 ns
(79.44%)
conversions/ScriptValue::Reference::from_into📈 view plot
🚷 view threshold
27.77 ns
(+3.18%)Baseline: 26.91 ns
30.06 ns
(92.39%)
conversions/Val::from_into📈 view plot
🚷 view threshold
264.57 ns
(-12.78%)Baseline: 303.34 ns
361.77 ns
(73.13%)
function/call 4 args Lua📈 view plot
🚷 view threshold
1,692.60 ns
(-10.10%)Baseline: 1,882.78 ns
2,118.77 ns
(79.89%)
function/call 4 args Rhai📈 view plot
🚷 view threshold
1,409.10 ns
(-6.56%)Baseline: 1,507.98 ns
1,650.40 ns
(85.38%)
function/call Lua📈 view plot
🚷 view threshold
234.67 ns
(-5.72%)Baseline: 248.91 ns
272.91 ns
(85.99%)
function/call Rhai📈 view plot
🚷 view threshold
442.97 ns
(-2.69%)Baseline: 455.20 ns
537.69 ns
(82.38%)
loading/empty Lua📈 view plot
🚷 view threshold
791,080.00 ns
(+67.08%)Baseline: 473,471.80 ns
1,636,227.73 ns
(48.35%)
loading/empty Rhai📈 view plot
🚷 view threshold
942,470.00 ns
(+32.38%)Baseline: 711,922.00 ns
1,628,241.01 ns
(57.88%)
math/vec mat ops Lua📈 view plot
🚷 view threshold
6,863.30 ns
(-13.32%)Baseline: 7,917.52 ns
9,360.95 ns
(73.32%)
math/vec mat ops Rhai📈 view plot
🚷 view threshold
6,262.90 ns
(-8.62%)Baseline: 6,853.37 ns
7,672.49 ns
(81.63%)
query/10 entities Lua📈 view plot
🚷 view threshold
19,684.00 ns
(-7.13%)Baseline: 21,194.20 ns
24,114.59 ns
(81.63%)
query/10 entities Rhai📈 view plot
🚷 view threshold
19,203.00 ns
(-8.64%)Baseline: 21,018.40 ns
22,992.81 ns
(83.52%)
query/100 entities Lua📈 view plot
🚷 view threshold
40,027.00 ns
(-7.41%)Baseline: 43,232.30 ns
46,883.04 ns
(85.38%)
query/100 entities Rhai📈 view plot
🚷 view threshold
31,540.00 ns
(-8.87%)Baseline: 34,611.50 ns
37,910.99 ns
(83.19%)
query/1000 entities Lua📈 view plot
🚷 view threshold
245,530.00 ns
(-12.81%)Baseline: 281,589.00 ns
325,308.44 ns
(75.48%)
query/1000 entities Rhai📈 view plot
🚷 view threshold
162,140.00 ns
(-5.95%)Baseline: 172,406.00 ns
189,660.23 ns
(85.49%)
reflection/10 Lua📈 view plot
🚷 view threshold
5,534.90 ns
(-12.34%)Baseline: 6,314.29 ns
7,088.64 ns
(78.08%)
reflection/10 Rhai📈 view plot
🚷 view threshold
14,858.00 ns
(-6.67%)Baseline: 15,920.50 ns
17,003.84 ns
(87.38%)
reflection/100 Lua📈 view plot
🚷 view threshold
47,685.00 ns
(-10.19%)Baseline: 53,094.10 ns
58,752.47 ns
(81.16%)
reflection/100 Rhai📈 view plot
🚷 view threshold
712,240.00 ns
(-9.04%)Baseline: 782,997.00 ns
856,341.64 ns
(83.17%)
resource/access Lua📈 view plot
🚷 view threshold
3,291.90 ns
(-9.77%)Baseline: 3,648.51 ns
4,151.56 ns
(79.29%)
resource/access Rhai📈 view plot
🚷 view threshold
5,131.80 ns
(-5.74%)Baseline: 5,444.06 ns
5,814.85 ns
(88.25%)
resource/get Lua📈 view plot
🚷 view threshold
1,847.40 ns
(-11.38%)Baseline: 2,084.63 ns
2,405.74 ns
(76.79%)
resource/get Rhai📈 view plot
🚷 view threshold
3,836.30 ns
(-3.70%)Baseline: 3,983.77 ns
4,261.57 ns
(90.02%)
🐰 View full continuous benchmarking report in Bencher

@makspll
Copy link
Owner Author

makspll commented Oct 20, 2025

That should do it for map and set references

@makspll makspll changed the title feat: implement custom reference paths, support Map and Set referneces feat: Replace ParsedPath with custom ReferencePath, support Map and Set references with arbitrary types Oct 21, 2025
@makspll makspll enabled auto-merge (squash) October 21, 2025 06:52
@makspll makspll merged commit ab3d48c into main Oct 21, 2025
32 of 36 checks passed
@makspll makspll deleted the feat/overhauled-references branch October 21, 2025 07:50
@github-actions github-actions bot mentioned this pull request Oct 21, 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