Skip to content

perf: switch to hashbrown hashmap in the function registry #399

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 2 commits into from
Mar 29, 2025

Conversation

makspll
Copy link
Owner

@makspll makspll commented Mar 29, 2025

Summary

The function registry as well as the allocator used the standard std hashmap, which by default uses a secure but slow hash. We don't need to worry about security here, so switching to hashbrown should give us a fair bit of speed up for free.

Copy link
Contributor

github-actions bot commented Mar 29, 2025

🐰 Bencher Report

Branchperf/script-function-registry-hashing
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,277.70 ns
(-16.64%)Baseline: 5,131.57 ns
6,586.37 ns
(64.95%)
component/access Rhai📈 view plot
🚷 view threshold
6,254.00 ns
(-8.98%)Baseline: 6,870.75 ns
8,238.38 ns
(75.91%)
component/get Lua📈 view plot
🚷 view threshold
2,681.70 ns
(-7.72%)Baseline: 2,906.10 ns
3,434.87 ns
(78.07%)
component/get Rhai📈 view plot
🚷 view threshold
5,026.50 ns
(+2.60%)Baseline: 4,899.34 ns
6,087.15 ns
(82.58%)
conversions/Mut::from📈 view plot
🚷 view threshold
124.28 ns
(-27.62%)Baseline: 171.70 ns
286.72 ns
(43.34%)
conversions/Ref::from📈 view plot
🚷 view threshold
119.97 ns
(-29.19%)Baseline: 169.41 ns
284.49 ns
(42.17%)
conversions/ScriptValue::List📈 view plot
🚷 view threshold
705.98 ns
(-3.76%)Baseline: 733.59 ns
945.73 ns
(74.65%)
conversions/ScriptValue::Map📈 view plot
🚷 view threshold
1,583.90 ns
(-10.35%)Baseline: 1,766.85 ns
2,348.24 ns
(67.45%)
conversions/ScriptValue::Reference::from_into📈 view plot
🚷 view threshold
47.83 ns
(+7.00%)Baseline: 44.70 ns
54.23 ns
(88.21%)
conversions/Val::from_into📈 view plot
🚷 view threshold
312.15 ns
(-11.02%)Baseline: 350.82 ns
494.08 ns
(63.18%)
function/call 4 args Lua📈 view plot
🚷 view threshold
2,035.00 ns
(-2.42%)Baseline: 2,085.51 ns
2,360.23 ns
(86.22%)
function/call 4 args Rhai📈 view plot
🚷 view threshold
1,852.00 ns
(+2.73%)Baseline: 1,802.79 ns
2,005.73 ns
(92.34%)
function/call Lua📈 view plot
🚷 view threshold
280.58 ns
(+1.30%)Baseline: 276.99 ns
320.09 ns
(87.66%)
function/call Rhai📈 view plot
🚷 view threshold
476.21 ns
(-9.48%)Baseline: 526.06 ns
655.44 ns
(72.66%)
math/vec mat ops Lua📈 view plot
🚷 view threshold
7,833.90 ns
(+0.09%)Baseline: 7,826.99 ns
9,366.82 ns
(83.63%)
math/vec mat ops Rhai📈 view plot
🚷 view threshold
7,004.40 ns
(-5.96%)Baseline: 7,448.02 ns
8,593.55 ns
(81.51%)
query/10 entities Lua📈 view plot
🚷 view threshold
22,778.00 ns
(-9.47%)Baseline: 25,160.35 ns
30,388.27 ns
(74.96%)
query/10 entities Rhai📈 view plot
🚷 view threshold
24,970.00 ns
(+1.92%)Baseline: 24,500.30 ns
29,043.04 ns
(85.98%)
query/100 entities Lua📈 view plot
🚷 view threshold
48,039.00 ns
(-6.65%)Baseline: 51,459.10 ns
62,374.17 ns
(77.02%)
query/100 entities Rhai📈 view plot
🚷 view threshold
37,318.00 ns
(-8.56%)Baseline: 40,811.85 ns
49,385.59 ns
(75.56%)
query/1000 entities Lua📈 view plot
🚷 view threshold
350,790.00 ns
(+10.45%)Baseline: 317,604.50 ns
409,428.75 ns
(85.68%)
query/1000 entities Rhai📈 view plot
🚷 view threshold
219,260.00 ns
(-8.60%)Baseline: 239,902.00 ns
305,840.53 ns
(71.69%)
reflection/10 Lua📈 view plot
🚷 view threshold
5,967.70 ns
(-10.20%)Baseline: 6,645.38 ns
7,815.06 ns
(76.36%)
reflection/10 Rhai📈 view plot
🚷 view threshold
15,031.00 ns
(-8.12%)Baseline: 16,360.20 ns
18,305.01 ns
(82.11%)
reflection/100 Lua📈 view plot
🚷 view threshold
50,676.00 ns
(-4.02%)Baseline: 52,800.25 ns
59,701.25 ns
(84.88%)
reflection/100 Rhai📈 view plot
🚷 view threshold
655,260.00 ns
(-7.22%)Baseline: 706,219.00 ns
837,471.81 ns
(78.24%)
resource/access Lua📈 view plot
🚷 view threshold
3,764.10 ns
(-16.68%)Baseline: 4,517.59 ns
5,661.07 ns
(66.49%)
resource/access Rhai📈 view plot
🚷 view threshold
5,571.00 ns
(-10.48%)Baseline: 6,223.32 ns
7,761.64 ns
(71.78%)
resource/get Lua📈 view plot
🚷 view threshold
2,272.60 ns
(-6.66%)Baseline: 2,434.65 ns
2,899.04 ns
(78.39%)
resource/get Rhai📈 view plot
🚷 view threshold
4,367.20 ns
(+1.43%)Baseline: 4,305.78 ns
5,480.77 ns
(79.68%)
🐰 View full continuous benchmarking report in Bencher

@makspll makspll merged commit 54742c6 into main Mar 29, 2025
25 checks passed
@makspll makspll deleted the perf/script-function-registry-hashing branch March 29, 2025 17:01
@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