Use B-tree collections instead of Fx hash ones

This removes a dependency. Since the collections in question should
usually be pretty small, it might also reduce memory overhead at little
cost in speed. Here are some relevant performance discussions:

  https://users.rust-lang.org/t/hashmap-vs-btreemap/13804
  https://www.reddit.com/r/rust/comments/7rgowj/hashmap_vs_btreemap/
This commit is contained in:
Aaron Fenyes 2025-05-04 12:49:35 -07:00
parent c6b628d424
commit 501cd74c96
4 changed files with 6 additions and 16 deletions

7
app-proto/Cargo.lock generated
View file

@ -89,7 +89,6 @@ dependencies = [
"lazy_static",
"nalgebra",
"readonly",
"rustc-hash",
"sycamore",
"wasm-bindgen-test",
"web-sys",
@ -364,12 +363,6 @@ dependencies = [
"syn",
]
[[package]]
name = "rustc-hash"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
[[package]]
name = "safe_arch"
version = "0.7.2"

View file

@ -15,7 +15,6 @@ js-sys = "0.3.70"
lazy_static = "1.5.0"
nalgebra = "0.33.0"
readonly = "0.2.12"
rustc-hash = "2.0.0"
sycamore = "0.9.0-beta.3"
# The `console_error_panic_hook` crate provides better debugging of panics by

View file

@ -1,9 +1,8 @@
use nalgebra::{DMatrix, DVector, DVectorView};
use rustc_hash::FxHashMap;
use std::{
any::{Any, TypeId},
cell::Cell,
collections::BTreeSet,
collections::{BTreeMap, BTreeSet},
cmp::Ordering,
fmt,
fmt::{Debug, Formatter},
@ -522,7 +521,7 @@ pub struct Assembly {
pub tangent: Signal<ConfigSubspace>,
// indexing
pub elements_by_id: Signal<FxHashMap<String, Rc<dyn Element>>>
pub elements_by_id: Signal<BTreeMap<String, Rc<dyn Element>>>
}
impl Assembly {
@ -531,7 +530,7 @@ impl Assembly {
elements: create_signal(BTreeSet::new()),
regulators: create_signal(BTreeSet::new()),
tangent: create_signal(ConfigSubspace::zero(0)),
elements_by_id: create_signal(FxHashMap::default())
elements_by_id: create_signal(BTreeMap::default())
}
}

View file

@ -8,8 +8,7 @@ mod specified;
#[cfg(test)]
mod tests;
use rustc_hash::FxHashSet;
use std::rc::Rc;
use std::{collections::BTreeSet, rc::Rc};
use sycamore::prelude::*;
use add_remove::AddRemove;
@ -20,14 +19,14 @@ use outline::Outline;
#[derive(Clone)]
struct AppState {
assembly: Assembly,
selection: Signal<FxHashSet<Rc<dyn Element>>>
selection: Signal<BTreeSet<Rc<dyn Element>>>
}
impl AppState {
fn new() -> AppState {
AppState {
assembly: Assembly::new(),
selection: create_signal(FxHashSet::default())
selection: create_signal(BTreeSet::default())
}
}