Skip to content

Switched to BTreeMap and BTreeSet#207

Merged
197g merged 1 commit into
image-rs:masterfrom
bushrat011899:btreemap_instead_of_hashmap
May 17, 2025
Merged

Switched to BTreeMap and BTreeSet#207
197g merged 1 commit into
image-rs:masterfrom
bushrat011899:btreemap_instead_of_hashmap

Conversation

@bushrat011899
Copy link
Copy Markdown
Contributor

Objective

For no_std compatibility it would be useful to move away from HashMap and HashSet, and instead use either hashbrown or alloc::collections::BTreeMap/Set. Since the cases where HashMap and HashSet are used are compatible with BTreeMap and BTreeSet, we should use those instead of introducing a new dependency.

Solution

  • Replaced std::collections::HashMap with alloc::collections::BTreeMap
  • Replaced std::collections::HashSet with alloc::collections::BTreeSet
  • Confirmed no performance change using cargo bench rgb_frame (the only benchmark that hits this code-path).

Notes

On my Intel i5-1240p laptop I observed no difference in performance due to this PR:

rgb_frame/test.png      time:   [43.728 ms 44.277 ms 44.856 ms]
                        thrpt:  [116.15 MiB/s 117.67 MiB/s 119.15 MiB/s]
                 change:
                        time:   [-1.9516% -0.2032% +1.6099%] (p = 0.82 > 0.05)
                        thrpt:  [-1.5844% +0.2036% +1.9904%]
                        No change in performance detected.

It's possible other platforms may show a more pronounced performance delta, but without evidence I think the tradeoff between possible performance loss vs increased platform compatibility is worth it here.

`HashMap` and `HashSet` are not available in `no_std`
@bushrat011899
Copy link
Copy Markdown
Contributor Author

See #206 for CI failure details.

@197g 197g merged commit dfa7e3b into image-rs:master May 17, 2025
7 of 13 checks passed
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.

4 participants