Skip to content

Commit

Permalink
Remove dashmap (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
yamadapc authored Aug 20, 2024
1 parent a631d28 commit d2ae8a8
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 69 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.idea/
.nyc_output/
.atlaspack-cache/
.parcel-cache/
.vscode/*
!.vscode/extensions.json
coverage/
Expand Down
14 changes: 7 additions & 7 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ We are committed to making participation in this project a harassment-free exper

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery
* Personal attacks
* Trolling or insulting/derogatory comments
* Public or private harassment
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
* Submitting contributions or comments that you know to violate the intellectual property or privacy rights of others
* Other unethical or unprofessional conduct
- The use of sexualized language or imagery
- Personal attacks
- Trolling or insulting/derogatory comments
- Public or private harassment
- Publishing other's private information, such as physical or electronic addresses, without explicit permission
- Submitting contributions or comments that you know to violate the intellectual property or privacy rights of others
- Other unethical or unprofessional conduct

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
Expand Down
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Thank you for considering a contribution to Atlaspack! Unfortunately pull reques

For pull requests, please:

* Add tests for new features and bug fixes
* Follow the existing style
* Separate unrelated changes into multiple pull requests
- Add tests for new features and bug fixes
- Follow the existing style
- Separate unrelated changes into multiple pull requests

See the existing issues for things to start contributing.

Expand All @@ -18,5 +18,5 @@ Atlassian requires contributors to sign a Contributor License Agreement, known a

Prior to accepting your contributions we ask that you please follow the appropriate link below to digitally sign the CLA. The Corporate CLA is for those who are contributing as a member of an organization and the individual CLA is for those contributing as an individual.

* [CLA for corporate contributors](https://opensource.atlassian.com/corporate)
* [CLA for individuals](https://opensource.atlassian.com/individual)
- [CLA for corporate contributors](https://opensource.atlassian.com/corporate)
- [CLA for individuals](https://opensource.atlassian.com/individual)
9 changes: 3 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/atlaspack_filesystem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition = "2021"
description = "FileSystem wrapper trait for use in Atlaspack codebase."

[dependencies]
dashmap = "5.5.3"
mockall = "0.12.1"
xxhash-rust = { version = "0.8.2", features = ["xxh3"] }
anyhow = "1.0.86"
Expand Down
7 changes: 3 additions & 4 deletions crates/atlaspack_filesystem/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::collections::HashMap;
use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;

use dashmap::DashMap;
use std::sync::{Arc, RwLock};

/// In-memory file-system for testing
pub mod in_memory_file_system;
Expand All @@ -18,7 +17,7 @@ pub mod os_file_system;
pub type FileSystemRef = Arc<dyn FileSystem + Send + Sync>;

pub type FileSystemRealPathCache =
DashMap<PathBuf, Option<PathBuf>, xxhash_rust::xxh3::Xxh3Builder>;
RwLock<HashMap<PathBuf, Option<PathBuf>, xxhash_rust::xxh3::Xxh3Builder>>;

/// Trait abstracting file-system operations
/// .
Expand Down
16 changes: 11 additions & 5 deletions crates/atlaspack_filesystem/src/os_file_system/canonicalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,27 @@ pub fn canonicalize(path: &Path, cache: &FileSystemRealPathCache) -> std::io::Re
ret.push(c);

// First, check the cache for the path up to this point.
let link = if let Some(cached) = cache.get(&ret) {
if let Some(link) = &*cached {
link.clone()
let read = cache.read().unwrap();
let cached = read.get(&ret).cloned();
drop(read);
let link = if let Some(cached) = cached {
if let Some(link) = cached {
link
} else {
continue;
}
} else {
let stat = std::fs::symlink_metadata(&ret)?;
if !stat.is_symlink() {
cache.insert(ret.clone(), None);
cache.write().unwrap().insert(ret.clone(), None);
continue;
}

let link = std::fs::read_link(&ret)?;
cache.insert(ret.clone(), Some(link.clone()));
cache
.write()
.unwrap()
.insert(ret.clone(), Some(link.clone()));
link
};

Expand Down
1 change: 0 additions & 1 deletion crates/node-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ atlaspack_plugin_transformer_js = { path = "../atlaspack_plugin_transformer_js"
atlaspack_napi_helpers = { path = "../atlaspack_napi_helpers" }

anyhow = "1.0.82"
dashmap = "5.4.0"
glob = "0.3.1"
log = "0.4.21"
mockall = "0.12.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/dev-dep-resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ atlaspack-resolver = { path = "../node-resolver-rs" }
es-module-lexer = { git = "https://github.com/devongovett/es-module-lexer" }
serde_json = "1.0.91"
rayon = "1.7.0"
dashmap = "5.4.0"
glob = "0.3.1"
xxhash-rust = "0.8.12"
48 changes: 29 additions & 19 deletions packages/utils/dev-dep-resolver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::path::Component;
use std::path::Path;
use std::path::PathBuf;
use std::sync::{Arc, RwLock};

use atlaspack_resolver::CacheCow;
use atlaspack_resolver::Invalidations;
Expand All @@ -13,8 +15,6 @@ use atlaspack_resolver::ResolverError;
use atlaspack_resolver::Specifier;
use atlaspack_resolver::SpecifierError;
use atlaspack_resolver::SpecifierType;
use dashmap::DashMap;
use dashmap::DashSet;
use es_module_lexer::lex;
use es_module_lexer::ImportKind;
// use rayon::prelude::{ParallelBridge, ParallelIterator};
Expand Down Expand Up @@ -68,12 +68,12 @@ impl From<SpecifierError> for EsmGraphBuilderError {

#[derive(Default)]
pub struct Cache {
entries: DashMap<PathBuf, Invalidations>,
entries: RwLock<HashMap<PathBuf, Arc<Invalidations>, xxhash_rust::xxh3::Xxh3Builder>>,
}

struct EsmGraphBuilder<'a> {
visited: DashSet<PathBuf>,
visited_globs: DashSet<PathBuf>,
visited: RwLock<HashSet<PathBuf>>,
visited_globs: RwLock<HashSet<PathBuf>>,
invalidations: Invalidations,
cjs_resolver: Resolver<'a>,
esm_resolver: Resolver<'a>,
Expand All @@ -82,11 +82,11 @@ struct EsmGraphBuilder<'a> {

impl<'a> EsmGraphBuilder<'a> {
pub fn build(&self, file: &Path) -> Result<(), EsmGraphBuilderError> {
if self.visited.contains(file) {
if self.visited.read().unwrap().contains(file) {
return Ok(());
}

self.visited.insert(file.to_owned());
self.visited.write().unwrap().insert(file.to_owned());

if let Some(ext) = file.extension() {
if ext != "js" && ext != "cjs" && ext != "mjs" {
Expand All @@ -95,14 +95,15 @@ impl<'a> EsmGraphBuilder<'a> {
}
}

if let Some(invalidations) = self.cache.entries.get(file) {
let read = self.cache.entries.read().unwrap();
let value = read.get(file).cloned();
drop(read);
if let Some(invalidations) = value {
self.invalidations.extend(&invalidations);
for p in invalidations
.invalidate_on_file_change
.read()
.unwrap()
.iter()
{
let read = invalidations.invalidate_on_file_change.read().unwrap();
let paths: Vec<PathBuf> = read.iter().cloned().collect();
drop(read);
for p in paths {
self.build(&p)?;
}
return Ok(());
Expand Down Expand Up @@ -168,7 +169,12 @@ impl<'a> EsmGraphBuilder<'a> {
.collect::<Result<_, _>>()?;

self.invalidations.extend(&invalidations);
self.cache.entries.insert(file.to_owned(), invalidations);
self
.cache
.entries
.write()
.unwrap()
.insert(file.to_owned(), Arc::new(invalidations));
Ok(())
}

Expand Down Expand Up @@ -207,11 +213,15 @@ impl<'a> EsmGraphBuilder<'a> {
// Invalidate when new files match the glob.
invalidations.invalidate_on_glob_create(pattern.to_string_lossy());

if self.visited_globs.contains(&pattern) {
if self.visited_globs.read().unwrap().contains(&pattern) {
return Ok(());
}

self.visited_globs.insert(pattern.to_path_buf());
self
.visited_globs
.write()
.unwrap()
.insert(pattern.to_path_buf());

for path in glob::glob(pattern.to_string_lossy().as_ref())? {
let path = path?;
Expand Down Expand Up @@ -500,8 +510,8 @@ pub fn build_esm_graph(
cache: &Cache,
) -> Result<Invalidations, EsmGraphBuilderError> {
let visitor = EsmGraphBuilder {
visited: DashSet::new(),
visited_globs: DashSet::new(),
visited: RwLock::new(HashSet::new()),
visited_globs: RwLock::new(HashSet::new()),
invalidations: Invalidations::default(),
cjs_resolver: Resolver::node(
Cow::Borrowed(project_root),
Expand Down
1 change: 0 additions & 1 deletion packages/utils/node-resolver-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ atlaspack_core = { path = "../../../crates/atlaspack_core" }
atlaspack_filesystem = { path = "../../../crates/atlaspack_filesystem" }

bitflags = "1.3.2"
dashmap = "5.4.0"
glob-match = "0.2.1"
indexmap = { version = "1.9.2", features = ["serde"] }
itertools = "0.10.5"
Expand Down
Loading

0 comments on commit d2ae8a8

Please sign in to comment.