Skip to content

perf: select better hashing algorithm for access maps #398

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

Conversation

makspll
Copy link
Owner

@makspll makspll commented Mar 29, 2025

Summary

Tries a simpler hash function for access maps specifically.

The motivation is this:

  • access maps are small, most often probably less than 10 items
  • we don't care about collisions as much because of this
  • we deal with simple u64 keys, which are unique by definition

So then:

  • using these u64's as hashes directly should make lookups faster, and collisions won't be a big deal

@makspll makspll force-pushed the feat/try-optimize-more branch from 1dc345b to aa57de4 Compare March 29, 2025 14:48
Copy link
Contributor

🐰 Bencher Report

Branchfeat/try-optimize-more
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,319.10 ns
(-16.12%)Baseline: 5,149.37 ns
6,625.45 ns
(65.19%)
component/access Rhai📈 view plot
🚷 view threshold
6,008.80 ns
(-12.58%)Baseline: 6,873.25 ns
8,308.15 ns
(72.32%)
component/get Lua📈 view plot
🚷 view threshold
2,896.40 ns
(-0.26%)Baseline: 2,904.06 ns
3,413.81 ns
(84.84%)
component/get Rhai📈 view plot
🚷 view threshold
4,625.60 ns
(-5.23%)Baseline: 4,880.81 ns
6,107.96 ns
(75.73%)
conversions/Mut::from📈 view plot
🚷 view threshold
122.01 ns
(-30.65%)Baseline: 175.92 ns
291.21 ns
(41.90%)
conversions/Ref::from📈 view plot
🚷 view threshold
120.68 ns
(-30.55%)Baseline: 173.77 ns
288.64 ns
(41.81%)
conversions/ScriptValue::List📈 view plot
🚷 view threshold
729.19 ns
(+0.87%)Baseline: 722.87 ns
911.39 ns
(80.01%)
conversions/ScriptValue::Map📈 view plot
🚷 view threshold
1,754.50 ns
(-2.01%)Baseline: 1,790.50 ns
2,380.65 ns
(73.70%)
conversions/ScriptValue::Reference::from_into📈 view plot
🚷 view threshold
44.42 ns
(+0.04%)Baseline: 44.40 ns
54.14 ns
(82.04%)
conversions/Val::from_into📈 view plot
🚷 view threshold
337.57 ns
(-4.40%)Baseline: 353.10 ns
502.07 ns
(67.24%)
function/call 4 args Lua📈 view plot
🚷 view threshold
2,076.60 ns
(-0.12%)Baseline: 2,079.12 ns
2,343.76 ns
(88.60%)
function/call 4 args Rhai📈 view plot
🚷 view threshold
1,732.10 ns
(-3.31%)Baseline: 1,791.35 ns
1,992.80 ns
(86.92%)
function/call Lua📈 view plot
🚷 view threshold
301.69 ns
(+9.55%)Baseline: 275.38 ns
310.69 ns
(97.10%)
function/call Rhai📈 view plot
🚷 view threshold
532.43 ns
(+0.72%)Baseline: 528.64 ns
658.64 ns
(80.84%)
math/vec mat ops Lua📈 view plot
🚷 view threshold
7,400.40 ns
(-5.11%)Baseline: 7,799.29 ns
9,404.21 ns
(78.69%)
math/vec mat ops Rhai📈 view plot
🚷 view threshold
6,923.30 ns
(-6.56%)Baseline: 7,408.98 ns
8,532.69 ns
(81.14%)
query/10 entities Lua📈 view plot
🚷 view threshold
24,844.00 ns
(-1.23%)Baseline: 25,154.21 ns
30,205.66 ns
(82.25%)
query/10 entities Rhai📈 view plot
🚷 view threshold
23,205.00 ns
(-4.83%)Baseline: 24,381.63 ns
29,100.68 ns
(79.74%)
query/100 entities Lua📈 view plot
🚷 view threshold
52,269.00 ns
(+1.62%)Baseline: 51,436.00 ns
62,179.50 ns
(84.06%)
query/100 entities Rhai📈 view plot
🚷 view threshold
38,536.00 ns
(-5.84%)Baseline: 40,926.42 ns
49,607.18 ns
(77.68%)
query/1000 entities Lua📈 view plot
🚷 view threshold
276,520.00 ns
(-12.35%)Baseline: 315,480.53 ns
408,985.77 ns
(67.61%)
query/1000 entities Rhai📈 view plot
🚷 view threshold
242,010.00 ns
(+0.18%)Baseline: 241,580.53 ns
308,151.88 ns
(78.54%)
reflection/10 Lua📈 view plot
🚷 view threshold
5,847.70 ns
(-12.10%)Baseline: 6,652.67 ns
7,874.26 ns
(74.26%)
reflection/10 Rhai📈 view plot
🚷 view threshold
14,757.00 ns
(-9.67%)Baseline: 16,336.11 ns
18,405.41 ns
(80.18%)
reflection/100 Lua📈 view plot
🚷 view threshold
49,145.00 ns
(-6.45%)Baseline: 52,535.16 ns
59,535.36 ns
(82.55%)
reflection/100 Rhai📈 view plot
🚷 view threshold
655,590.00 ns
(-6.83%)Baseline: 703,636.84 ns
835,649.28 ns
(78.45%)
resource/access Lua📈 view plot
🚷 view threshold
3,817.50 ns
(-15.75%)Baseline: 4,531.35 ns
5,690.37 ns
(67.09%)
resource/access Rhai📈 view plot
🚷 view threshold
5,233.20 ns
(-16.06%)Baseline: 6,234.44 ns
7,842.03 ns
(66.73%)
resource/get Lua📈 view plot
🚷 view threshold
2,342.70 ns
(-3.38%)Baseline: 2,424.76 ns
2,870.83 ns
(81.60%)
resource/get Rhai📈 view plot
🚷 view threshold
3,927.50 ns
(-8.43%)Baseline: 4,289.05 ns
5,514.78 ns
(71.22%)
🐰 View full continuous benchmarking report in Bencher

@makspll makspll enabled auto-merge (squash) March 29, 2025 15:13
@makspll makspll changed the title perf: try play with hashing for access maps perf: select better hashing algorithm for access maps Mar 29, 2025
@makspll makspll merged commit 5a6e4b3 into main Mar 29, 2025
25 checks passed
@makspll makspll deleted the feat/try-optimize-more branch March 29, 2025 15:30
@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 <makspl17@gmail.com>
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