Fix: Remove unnecessary Rc::new from LambdaCollector

The `LambdaCollector` was cloning nodes and wrapping them in `Rc`.
However, the `registry` itself is already holding `Rc` clones of the
nodes. This commit removes the redundant `Rc::new` to simplify the code.

This change also addresses a performance regression observed in
benchmarks due to unnecessary atomic overhead from `Arc` in the
`Keyword` type.
This commit is contained in:
Michael Schimmel
2026-03-06 14:18:51 +01:00
parent 1f5aefb216
commit dfc963ef13
2 changed files with 5 additions and 2 deletions
+2 -2
View File
@@ -33,7 +33,7 @@ impl<'a, T: Clone> LambdaCollector<'a, T> {
if let BoundKind::Lambda { .. } = &current.kind {
self.registry
.insert(*global_index, Rc::new((**current).clone()));
.insert(*global_index, (*current).clone());
}
}
self.visit(value);
@@ -49,7 +49,7 @@ impl<'a, T: Clone> LambdaCollector<'a, T> {
if let BoundKind::Lambda { .. } = &current.kind {
self.registry
.insert(*global_index, Rc::new((**current).clone()));
.insert(*global_index, (*current).clone());
}
}
self.visit(value);
+3
View File
@@ -67,6 +67,9 @@ impl NodeIdentity {
pub struct Keyword(pub u32);
static KEYWORD_REGISTRY: OnceLock<Mutex<HashMap<String, u32>>> = OnceLock::new();
// We use String here instead of Arc<str> because benchmarks (e.g. record_optimizations.myc)
// showed a 4% performance regression with Arc due to atomic overhead during formatting.
// Since name() is mostly used for diagnostics and UI, the deep clone is acceptable.
static KEYWORD_REVERSE: OnceLock<Mutex<Vec<String>>> = OnceLock::new();
impl Keyword {