Skip to content

Commit

Permalink
Improves TraitMap cloning performance.
Browse files Browse the repository at this point in the history
By using im::Vector inside TypeMap we avoid cloning everything when
cloning namespaces.

Fixes #6470.
  • Loading branch information
esdrubal committed Aug 27, 2024
1 parent ddad3aa commit 9ed2785
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions sway-core/src/language/ty/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub struct TyModule {
pub attributes: transform::AttributesMap,
}

unsafe impl Send for TyModule {}
unsafe impl Sync for TyModule {}

impl TyModule {
/// Iter on all constants in this module, which means, globals constants and
/// local constants, but it does not enter into submodules.
Expand Down
12 changes: 6 additions & 6 deletions sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::{
sync::Arc,
};

use hashbrown::HashSet;
use sway_error::{
error::CompileError,
handler::{ErrorEmitted, Handler},
Expand Down Expand Up @@ -126,7 +125,7 @@ struct TraitEntry {
}

/// Map of trait name and type to [TraitItems].
type TraitImpls = Vec<TraitEntry>;
type TraitImpls = im::Vector<TraitEntry>;

/// Map holding trait implementations for types.
///
Expand All @@ -135,7 +134,7 @@ type TraitImpls = Vec<TraitEntry>;
#[derive(Clone, Debug, Default)]
pub(crate) struct TraitMap {
trait_impls: TraitImpls,
satisfied_cache: hashbrown::HashSet<u64>,
satisfied_cache: im::HashSet<u64>,
}

pub(crate) enum IsImplSelf {
Expand Down Expand Up @@ -412,10 +411,11 @@ impl TraitMap {
impl_span,
};
let entry = TraitEntry { key, value };
let trait_impls: TraitImpls = vec![entry];
let mut trait_impls: TraitImpls = im::Vector::new();
trait_impls.push_back(entry);
let trait_map = TraitMap {
trait_impls,
satisfied_cache: HashSet::default(),
satisfied_cache: im::HashSet::default(),
};

self.extend(trait_map, engines);
Expand Down Expand Up @@ -540,7 +540,7 @@ impl TraitMap {
.as_ref()
.map_or(false, |span| span == &trait_decl_span)
{
trait_map.trait_impls.push(entry.clone());
trait_map.trait_impls.push_back(entry.clone());
}
}
trait_map
Expand Down

0 comments on commit 9ed2785

Please sign in to comment.