perf(hash): swap std HashMap/HashSet for rustc-hash FxHash

Phase 4.1. Handle / u64 keys dominate the hot maps (block_defn,
hatch / image / mesh caches, draw-depth map, viewport wire caches);
the default SipHash is wasted work on integer keys. Alias the std
types to rustc_hash::FxHashMap / FxHashSet crate-wide so every map and
set — including the cross-module draw-depth map shared between scene
and the GPU pipelines — uses the faster hasher consistently.

Mechanical: no behavioural change. Constructors moved from ::new() to
::default() (Fx variants carry no RandomState). Build + 13 tests green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-06-05 00:35:53 +03:00
commit 70702d063f
30 changed files with 102 additions and 98 deletions

View file

@ -118,7 +118,7 @@ impl OpenCADStudio {
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
} else {
let layers: std::collections::HashSet<String> = self.tabs[i]
let layers: rustc_hash::FxHashSet<String> = self.tabs[i]
.scene
.selected_entities()
.into_iter()
@ -153,7 +153,7 @@ impl OpenCADStudio {
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
} else {
let layers: std::collections::HashSet<String> = self.tabs[i]
let layers: rustc_hash::FxHashSet<String> = self.tabs[i]
.scene
.selected_entities()
.into_iter()
@ -188,7 +188,7 @@ impl OpenCADStudio {
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
} else {
let layers: std::collections::HashSet<String> = self.tabs[i]
let layers: rustc_hash::FxHashSet<String> = self.tabs[i]
.scene
.selected_entities()
.into_iter()
@ -278,7 +278,7 @@ impl OpenCADStudio {
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
} else {
let layers: std::collections::HashSet<String> = self.tabs[i]
let layers: rustc_hash::FxHashSet<String> = self.tabs[i]
.scene
.selected_entities()
.into_iter()
@ -299,7 +299,7 @@ impl OpenCADStudio {
// LAYISO — turn off all layers except those used by selected entities
"LAYISO" => {
let sel_layers: std::collections::HashSet<String> = self.tabs[i]
let sel_layers: rustc_hash::FxHashSet<String> = self.tabs[i]
.scene
.selected_entities()
.into_iter()
@ -3090,10 +3090,10 @@ impl OpenCADStudio {
// including ones not yet in the table, which sort by
// their own handle. (min_eff, max_eff) over siblings.
let fb_baseline: Option<(u64, u64)> = if to_front_opt.is_some() {
let selected_set: std::collections::HashSet<u64> =
let selected_set: rustc_hash::FxHashSet<u64> =
selected.iter().map(|h| h.value()).collect();
let doc_ref = &self.tabs[i].scene.document;
let overrides: std::collections::HashMap<u64, u64> = doc_ref
let overrides: rustc_hash::FxHashMap<u64, u64> = doc_ref
.objects
.values()
.find_map(|obj| {
@ -4358,7 +4358,7 @@ impl OpenCADStudio {
let all = sub == "ALL" || sub.is_empty();
// Collect names in use (immutable borrows — done in their own scope)
let used_layers: std::collections::HashSet<String> = self.tabs[i]
let used_layers: rustc_hash::FxHashSet<String> = self.tabs[i]
.scene
.document
.entities()
@ -4371,7 +4371,7 @@ impl OpenCADStudio {
}
})
.collect();
let used_text_styles: std::collections::HashSet<String> = self.tabs[i]
let used_text_styles: rustc_hash::FxHashSet<String> = self.tabs[i]
.scene
.document
.entities()
@ -4382,7 +4382,7 @@ impl OpenCADStudio {
})
.filter(|s| !s.is_empty())
.collect();
let used_linetypes: std::collections::HashSet<String> = self.tabs[i]
let used_linetypes: rustc_hash::FxHashSet<String> = self.tabs[i]
.scene
.document
.entities()

View file

@ -171,7 +171,7 @@ pub(super) fn entities_centroid(wires: &[WireModel]) -> glam::Vec3 {
/// Generate the next available auto group name ("*A1", "*A2", …).
pub(super) fn next_group_auto_name(scene: &crate::scene::Scene) -> String {
let existing: std::collections::HashSet<String> =
let existing: rustc_hash::FxHashSet<String> =
scene.groups().map(|g| g.name.clone()).collect();
for n in 1..=9999 {
let name = format!("*A{n}");

View file

@ -1,5 +1,5 @@
use super::{document::HistorySnapshot, OpenCADStudio};
use std::collections::HashSet;
use rustc_hash::FxHashSet as HashSet;
impl OpenCADStudio {
pub(super) fn history_label_from_active_cmd(&self, i: usize, fallback: &'static str) -> String {

View file

@ -378,7 +378,7 @@ pub(super) struct OpenCADStudio {
// ── Keyboard Shortcut Editor ──────────────────────────────────────────
/// User-defined function-key overrides: "F3" → command string.
shortcut_overrides: std::collections::HashMap<String, String>,
shortcut_overrides: rustc_hash::FxHashMap<String, String>,
// ── Layout Manager Panel ──────────────────────────────────────────────
layout_manager_selected: String,
@ -1324,7 +1324,7 @@ impl OpenCADStudio {
// Color scheme (default: dark CAD-style)
active_theme: Theme::Dark,
// Keyboard shortcuts
shortcut_overrides: std::collections::HashMap::new(),
shortcut_overrides: rustc_hash::FxHashMap::default(),
// Layout Manager
layout_manager_selected: "Model".to_string(),
layout_manager_rename_buf: String::new(),

View file

@ -214,7 +214,7 @@ impl OpenCADStudio {
self.tabs[i].scene.meshes = caches.meshes;
// Invalidate the wire cache so the new document is tessellated.
self.tabs[i].scene.bump_geometry();
self.tabs[i].scene.selected = std::collections::HashSet::new();
self.tabs[i].scene.selected = rustc_hash::FxHashSet::default();
self.tabs[i].scene.preview_wires = vec![];
self.tabs[i].scene.current_layout = "Model".to_string();
crate::linetypes::populate_document(&mut self.tabs[i].scene.document);