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:
@@ -33,7 +33,7 @@ impl<'a, T: Clone> LambdaCollector<'a, T> {
|
|||||||
|
|
||||||
if let BoundKind::Lambda { .. } = ¤t.kind {
|
if let BoundKind::Lambda { .. } = ¤t.kind {
|
||||||
self.registry
|
self.registry
|
||||||
.insert(*global_index, Rc::new((**current).clone()));
|
.insert(*global_index, (*current).clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.visit(value);
|
self.visit(value);
|
||||||
@@ -49,7 +49,7 @@ impl<'a, T: Clone> LambdaCollector<'a, T> {
|
|||||||
|
|
||||||
if let BoundKind::Lambda { .. } = ¤t.kind {
|
if let BoundKind::Lambda { .. } = ¤t.kind {
|
||||||
self.registry
|
self.registry
|
||||||
.insert(*global_index, Rc::new((**current).clone()));
|
.insert(*global_index, (*current).clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.visit(value);
|
self.visit(value);
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ impl NodeIdentity {
|
|||||||
pub struct Keyword(pub u32);
|
pub struct Keyword(pub u32);
|
||||||
|
|
||||||
static KEYWORD_REGISTRY: OnceLock<Mutex<HashMap<String, u32>>> = OnceLock::new();
|
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();
|
static KEYWORD_REVERSE: OnceLock<Mutex<Vec<String>>> = OnceLock::new();
|
||||||
|
|
||||||
impl Keyword {
|
impl Keyword {
|
||||||
|
|||||||
Reference in New Issue
Block a user