Skip to content

feat: optimize access map #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2025
Merged

feat: optimize access map #395

merged 1 commit into from
Mar 29, 2025

Conversation

makspll
Copy link
Owner

@makspll makspll commented Mar 27, 2025

Summary

Removes some unnecessary code in access maps to improve performance slightly.
Also refactors area slightly to make it easier to modify in the future

Copy link
Contributor

github-actions bot commented Mar 27, 2025

🐰 Bencher Report

Branchfeat/optimize-access-map-2
Testbedlinux-gha

🚨 1 Alert

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
function/call LuaLatency
nanoseconds (ns)
📈 plot
🚷 threshold
🚨 alert (🔔)
301.77 ns
(+10.82%)Baseline: 272.31 ns
300.75 ns
(100.34%)

Click to view all benchmark results
BenchmarkLatencyBenchmark Result
nanoseconds (ns)
(Result Δ%)
Upper Boundary
nanoseconds (ns)
(Limit %)
component/access Lua📈 view plot
🚷 view threshold
4,182.80 ns
(-19.23%)Baseline: 5,178.73 ns
6,744.14 ns
(62.02%)
component/access Rhai📈 view plot
🚷 view threshold
6,236.70 ns
(-9.49%)Baseline: 6,890.55 ns
8,373.37 ns
(74.48%)
component/get Lua📈 view plot
🚷 view threshold
2,767.10 ns
(-3.99%)Baseline: 2,882.02 ns
3,412.37 ns
(81.09%)
component/get Rhai📈 view plot
🚷 view threshold
4,715.90 ns
(-2.81%)Baseline: 4,852.47 ns
6,121.52 ns
(77.04%)
conversions/Mut::from📈 view plot
🚷 view threshold
134.22 ns
(-26.25%)Baseline: 181.98 ns
306.01 ns
(43.86%)
conversions/Ref::from📈 view plot
🚷 view threshold
121.66 ns
(-31.64%)Baseline: 177.97 ns
307.14 ns
(39.61%)
conversions/ScriptValue::List📈 view plot
🚷 view threshold
722.72 ns
(-0.85%)Baseline: 728.91 ns
922.72 ns
(78.33%)
conversions/ScriptValue::Map📈 view plot
🚷 view threshold
1,545.60 ns
(-13.23%)Baseline: 1,781.28 ns
2,496.53 ns
(61.91%)
conversions/ScriptValue::Reference::from_into📈 view plot
🚷 view threshold
42.41 ns
(-3.94%)Baseline: 44.15 ns
55.15 ns
(76.91%)
conversions/Val::from_into📈 view plot
🚷 view threshold
336.84 ns
(-6.79%)Baseline: 361.38 ns
523.69 ns
(64.32%)
function/call 4 args Lua📈 view plot
🚷 view threshold
1,997.60 ns
(-2.96%)Baseline: 2,058.45 ns
2,314.15 ns
(86.32%)
function/call 4 args Rhai📈 view plot
🚷 view threshold
1,729.80 ns
(-3.04%)Baseline: 1,784.09 ns
1,988.25 ns
(87.00%)
function/call Lua📈 view plot
🚷 view threshold
🚨 view alert (🔔)
301.77 ns
(+10.82%)Baseline: 272.31 ns
300.75 ns
(100.34%)

function/call Rhai📈 view plot
🚷 view threshold
565.53 ns
(+7.96%)Baseline: 523.85 ns
654.29 ns
(86.43%)
math/vec mat ops Lua📈 view plot
🚷 view threshold
7,428.70 ns
(-4.24%)Baseline: 7,757.46 ns
9,414.41 ns
(78.91%)
math/vec mat ops Rhai📈 view plot
🚷 view threshold
6,655.00 ns
(-9.58%)Baseline: 7,360.22 ns
8,583.97 ns
(77.53%)
query/10 entities Lua📈 view plot
🚷 view threshold
23,221.00 ns
(-6.79%)Baseline: 24,913.06 ns
30,300.63 ns
(76.64%)
query/10 entities Rhai📈 view plot
🚷 view threshold
23,034.00 ns
(-4.43%)Baseline: 24,101.47 ns
28,665.58 ns
(80.35%)
query/100 entities Lua📈 view plot
🚷 view threshold
48,693.00 ns
(-4.35%)Baseline: 50,905.53 ns
62,180.57 ns
(78.31%)
query/100 entities Rhai📈 view plot
🚷 view threshold
36,868.00 ns
(-9.69%)Baseline: 40,821.71 ns
50,329.60 ns
(73.25%)
query/1000 entities Lua📈 view plot
🚷 view threshold
368,240.00 ns
(+15.83%)Baseline: 317,902.35 ns
411,876.26 ns
(89.41%)
query/1000 entities Rhai📈 view plot
🚷 view threshold
222,430.00 ns
(-8.30%)Baseline: 242,562.35 ns
312,934.72 ns
(71.08%)
reflection/10 Lua📈 view plot
🚷 view threshold
5,996.00 ns
(-10.22%)Baseline: 6,678.38 ns
7,943.37 ns
(75.48%)
reflection/10 Rhai📈 view plot
🚷 view threshold
15,760.00 ns
(-3.53%)Baseline: 16,336.00 ns
18,298.47 ns
(86.13%)
reflection/100 Lua📈 view plot
🚷 view threshold
51,604.00 ns
(-1.50%)Baseline: 52,390.41 ns
59,245.69 ns
(87.10%)
reflection/100 Rhai📈 view plot
🚷 view threshold
672,050.00 ns
(-3.77%)Baseline: 698,351.76 ns
828,872.24 ns
(81.08%)
resource/access Lua📈 view plot
🚷 view threshold
3,796.90 ns
(-16.69%)Baseline: 4,557.37 ns
5,777.05 ns
(65.72%)
resource/access Rhai📈 view plot
🚷 view threshold
5,470.10 ns
(-12.75%)Baseline: 6,269.66 ns
7,925.91 ns
(69.02%)
resource/get Lua📈 view plot
🚷 view threshold
2,306.40 ns
(-3.99%)Baseline: 2,402.13 ns
2,848.88 ns
(80.96%)
resource/get Rhai📈 view plot
🚷 view threshold
4,105.60 ns
(-4.14%)Baseline: 4,282.87 ns
5,568.97 ns
(73.72%)
🐰 View full continuous benchmarking report in Bencher

@makspll makspll force-pushed the feat/optimize-access-map-2 branch 4 times, most recently from 94d6baa to 1657e22 Compare March 29, 2025 11:32
@makspll makspll force-pushed the feat/optimize-access-map-2 branch from 1657e22 to 1a4ad4d Compare March 29, 2025 12:19
@makspll makspll merged commit de824aa into main Mar 29, 2025
23 checks passed
@makspll makspll deleted the feat/optimize-access-map-2 branch March 29, 2025 14:05
@github-actions github-actions bot mentioned this pull request Mar 29, 2025
makspll added a commit that referenced this pull request Mar 29, 2025
## 🤖 New release

* `bevy_mod_scripting_derive`: 0.10.0 -> 0.11.0
* `bevy_mod_scripting_core`: 0.10.0 -> 0.11.0 (✓ API compatible changes)
* `bevy_mod_scripting_lua`: 0.10.0 -> 0.11.0 (✓ API compatible changes)
* `bevy_mod_scripting_rhai`: 0.10.0 -> 0.11.0 (✓ API compatible changes)
* `bevy_mod_scripting_functions`: 0.10.0 -> 0.11.0 (✓ API compatible
changes)
* `ladfile`: 0.4.0 -> 0.5.0 (⚠ API breaking changes)
* `mdbook_lad_preprocessor`: 0.1.4 -> 0.1.5 (✓ API compatible changes)
* `ladfile_builder`: 0.2.6 -> 0.3.0 (⚠ API breaking changes)
* `bevy_mod_scripting`: 0.10.0 -> 0.11.0 (✓ API compatible changes)

### ⚠ `ladfile` breaking changes

```text
--- failure constructible_struct_adds_field: externally-constructible struct adds field ---

Description:
A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/constructible_struct_adds_field.ron

Failed in:
  field LadType.generated in /tmp/.tmpI1fySQ/bevy_mod_scripting/crates/ladfile/src/lib.rs:458
  field LadType.insignificance in /tmp/.tmpI1fySQ/bevy_mod_scripting/crates/ladfile/src/lib.rs:465

--- failure method_parameter_count_changed: pub method parameter count changed ---

Description:
A publicly-visible method now takes a different number of parameters.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#fn-change-arity
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/method_parameter_count_changed.ron

Failed in:
  ladfile::LadFile::get_type_identifier now takes 3 parameters instead of 2, in /tmp/.tmpI1fySQ/bevy_mod_scripting/crates/ladfile/src/lib.rs:55
```

### ⚠ `ladfile_builder` breaking changes

```text
--- failure constructible_struct_adds_field: externally-constructible struct adds field ---

Description:
A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/constructible_struct_adds_field.ron

Failed in:
  field LadFileSettings.exclude_types_containing_unregistered in /tmp/.tmpI1fySQ/bevy_mod_scripting/crates/ladfile_builder/src/plugin.rs:42

--- failure method_parameter_count_changed: pub method parameter count changed ---

Description:
A publicly-visible method now takes a different number of parameters.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#fn-change-arity
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/method_parameter_count_changed.ron

Failed in:
  ladfile_builder::plugin::ScriptingDocgenPlugin::new now takes 4 parameters instead of 3, in /tmp/.tmpI1fySQ/bevy_mod_scripting/crates/ladfile_builder/src/plugin.rs:61
```

<details><summary><i><b>Changelog</b></i></summary><p>

## `bevy_mod_scripting_derive`

<blockquote>

##
[0.11.0](bevy_mod_scripting_derive-v0.10.0...bevy_mod_scripting_derive-v0.11.0)
- 2025-03-29

### Added

- overhaul mdbook preprocessor, prettify generated docs, support dummy
globals ([#377](#377))
</blockquote>

## `bevy_mod_scripting_core`

<blockquote>

##
[0.11.0](bevy_mod_scripting_core-v0.10.0...bevy_mod_scripting_core-v0.11.0)
- 2025-03-29

### Added

- optimize access map
([#395](#395))
- optimize `get` and `set` functions, add `MagicFunctions` sub-registry
([#397](#397))
- improve tracing spans, add `profile_with_tracy` feature flag
([#394](#394))
- add `profile_with_tracy` feature which plays nicely with bevy's
`bevy/trace_tracy` feature
([#393](#393))
- Add initial benchmarks, integrate them into CI & add getters/settters
for `Scripts` resource
([#381](#381))
- add ScriptValue override for printing opaque values
([#380](#380))
- ✨ Dynamic Script Components, `register_new_component`
binding, `remove_component` no longer requires `ReflectComponent` data
([#379](#379))
- overhaul mdbook preprocessor, prettify generated docs, support dummy
globals ([#377](#377))

### Fixed

- fix global type cache not containing generic types
([#388](#388))

### Other

- switch to hashbrown hashmap in the function registry
([#399](#399))
- try play with hashing for access maps
([#398](#398))
- allow check creation for bencher
</blockquote>

## `bevy_mod_scripting_lua`

<blockquote>

##
[0.11.0](bevy_mod_scripting_lua-v0.10.0...bevy_mod_scripting_lua-v0.11.0)
- 2025-03-29

### Added

- optimize `get` and `set` functions, add `MagicFunctions` sub-registry
([#397](#397))
- allow the conversion of lua functions into `ScriptValue` via
`DynamicScriptFunction`
([#396](#396))
- Add initial benchmarks, integrate them into CI & add getters/settters
for `Scripts` resource
([#381](#381))
- ✨ Dynamic Script Components, `register_new_component`
binding, `remove_component` no longer requires `ReflectComponent` data
([#379](#379))
</blockquote>

## `bevy_mod_scripting_rhai`

<blockquote>

##
[0.11.0](bevy_mod_scripting_rhai-v0.10.0...bevy_mod_scripting_rhai-v0.11.0)
- 2025-03-29

### Added

- [**breaking**] bump bersion
- optimize `get` and `set` functions, add `MagicFunctions` sub-registry
([#397](#397))
- Add initial benchmarks, integrate them into CI & add getters/settters
for `Scripts` resource
([#381](#381))
</blockquote>

## `bevy_mod_scripting_functions`

<blockquote>

##
[0.11.0](bevy_mod_scripting_functions-v0.10.0...bevy_mod_scripting_functions-v0.11.0)
- 2025-03-29

### Added

- optimize `get` and `set` functions, add `MagicFunctions` sub-registry
([#397](#397))
- ✨ Dynamic Script Components, `register_new_component`
binding, `remove_component` no longer requires `ReflectComponent` data
([#379](#379))
- overhaul mdbook preprocessor, prettify generated docs, support dummy
globals ([#377](#377))
</blockquote>

## `ladfile`

<blockquote>

##
[0.5.0](v0.4.0-ladfile...v0.5.0-ladfile)
- 2025-03-29

### Added

- overhaul mdbook preprocessor, prettify generated docs, support dummy
globals ([#377](#377))
</blockquote>

## `mdbook_lad_preprocessor`

<blockquote>

##
[0.1.5](v0.1.4-mdbook_lad_preprocessor...v0.1.5-mdbook_lad_preprocessor)
- 2025-03-29

### Added

- overhaul mdbook preprocessor, prettify generated docs, support dummy
globals ([#377](#377))

### Fixed

- make all links in the mdbook preprocessor relative
([#392](#392))
- mdbook preprocessor links not taking into account root url
([#391](#391))
</blockquote>

## `ladfile_builder`

<blockquote>

##
[0.3.0](v0.2.6-ladfile_builder...v0.3.0-ladfile_builder)
- 2025-03-29

### Added

- overhaul mdbook preprocessor, prettify generated docs, support dummy
globals ([#377](#377))
</blockquote>

## `bevy_mod_scripting`

<blockquote>

##
[0.11.0](v0.10.0...v0.11.0)
- 2025-03-29

### Added

- allow the conversion of lua functions into `ScriptValue` via
`DynamicScriptFunction`
([#396](#396))
- improve tracing spans, add `profile_with_tracy` feature flag
([#394](#394))
- add `profile_with_tracy` feature which plays nicely with bevy's
`bevy/trace_tracy` feature
([#393](#393))
- Add initial benchmarks, integrate them into CI & add getters/settters
for `Scripts` resource
([#381](#381))
- ✨ Dynamic Script Components, `register_new_component`
binding, `remove_component` no longer requires `ReflectComponent` data
([#379](#379))
- optimize `get` and `set` functions, add `MagicFunctions` sub-registry
([#397](#397))
- optimize access map
([#395](#395))
- add ScriptValue override for printing opaque values
([#380](#380))
- overhaul mdbook preprocessor, prettify generated docs, support dummy
globals ([#377](#377))
- [**breaking**] bump bersion

### Fixed

- fix global type cache not containing generic types
([#388](#388))

### Other

- switch to hashbrown hashmap in the function registry
([#399](#399))
- try play with hashing for access maps
([#398](#398))
- allow check creation for bencher
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Maksymilian Mozolewski <[email protected]>
makspll pushed a commit that referenced this pull request Mar 30, 2025
## 🤖 New release

* `bevy_mod_scripting_derive`: 0.11.0 -> 0.11.1
* `bevy_system_reflection`: 0.1.0 -> 0.1.1 (✓ API compatible changes)
* `bevy_mod_scripting_core`: 0.11.0 -> 0.11.1 (✓ API compatible changes)
* `bevy_mod_scripting_lua`: 0.11.0 -> 0.11.1 (✓ API compatible changes)
* `bevy_mod_scripting_rhai`: 0.11.0 -> 0.11.1 (✓ API compatible changes)
* `bevy_mod_scripting_functions`: 0.11.0 -> 0.11.1 (✓ API compatible
changes)
* `ladfile_builder`: 0.3.0 -> 0.3.1 (✓ API compatible changes)
* `bevy_mod_scripting`: 0.11.0 -> 0.11.1 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

## `bevy_mod_scripting_derive`

<blockquote>

##
[0.11.0](bevy_mod_scripting_derive-v0.10.0...bevy_mod_scripting_derive-v0.11.0)
- 2025-03-29

### Added

- overhaul mdbook preprocessor, prettify generated docs, support dummy
globals ([#377](#377))
</blockquote>


## `bevy_mod_scripting_core`

<blockquote>

##
[0.11.0](bevy_mod_scripting_core-v0.10.0...bevy_mod_scripting_core-v0.11.0)
- 2025-03-29

### Added

- optimize access map
([#395](#395))
- optimize `get` and `set` functions, add `MagicFunctions` sub-registry
([#397](#397))
- improve tracing spans, add `profile_with_tracy` feature flag
([#394](#394))
- add `profile_with_tracy` feature which plays nicely with bevy's
`bevy/trace_tracy` feature
([#393](#393))
- Add initial benchmarks, integrate them into CI & add getters/settters
for `Scripts` resource
([#381](#381))
- add ScriptValue override for printing opaque values
([#380](#380))
- ✨ Dynamic Script Components, `register_new_component`
binding, `remove_component` no longer requires `ReflectComponent` data
([#379](#379))
- overhaul mdbook preprocessor, prettify generated docs, support dummy
globals ([#377](#377))

### Fixed

- fix global type cache not containing generic types
([#388](#388))

### Other

- switch to hashbrown hashmap in the function registry
([#399](#399))
- try play with hashing for access maps
([#398](#398))
- allow check creation for bencher
</blockquote>

## `bevy_mod_scripting_lua`

<blockquote>

##
[0.11.0](bevy_mod_scripting_lua-v0.10.0...bevy_mod_scripting_lua-v0.11.0)
- 2025-03-29

### Added

- optimize `get` and `set` functions, add `MagicFunctions` sub-registry
([#397](#397))
- allow the conversion of lua functions into `ScriptValue` via
`DynamicScriptFunction`
([#396](#396))
- Add initial benchmarks, integrate them into CI & add getters/settters
for `Scripts` resource
([#381](#381))
- ✨ Dynamic Script Components, `register_new_component`
binding, `remove_component` no longer requires `ReflectComponent` data
([#379](#379))
</blockquote>

## `bevy_mod_scripting_rhai`

<blockquote>

##
[0.11.0](bevy_mod_scripting_rhai-v0.10.0...bevy_mod_scripting_rhai-v0.11.0)
- 2025-03-29

### Added

- [**breaking**] bump bersion
- optimize `get` and `set` functions, add `MagicFunctions` sub-registry
([#397](#397))
- Add initial benchmarks, integrate them into CI & add getters/settters
for `Scripts` resource
([#381](#381))
</blockquote>

## `bevy_mod_scripting_functions`

<blockquote>

##
[0.11.0](bevy_mod_scripting_functions-v0.10.0...bevy_mod_scripting_functions-v0.11.0)
- 2025-03-29

### Added

- optimize `get` and `set` functions, add `MagicFunctions` sub-registry
([#397](#397))
- ✨ Dynamic Script Components, `register_new_component`
binding, `remove_component` no longer requires `ReflectComponent` data
([#379](#379))
- overhaul mdbook preprocessor, prettify generated docs, support dummy
globals ([#377](#377))
</blockquote>

## `ladfile_builder`

<blockquote>

##
[0.3.1](v0.3.0-ladfile_builder...v0.3.1-ladfile_builder)
- 2025-03-29

### Added

- bump bevy to 0.15.3
([#401](#401))
</blockquote>

## `bevy_mod_scripting`

<blockquote>

##
[0.11.1](v0.11.0...v0.11.1)
- 2025-03-29

### Added

- bump bevy to 0.15.3
([#401](#401))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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