Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(es): Cache current_dir() system calls #9683

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/swc/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,9 @@ pub struct CallerOptions {

#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
fn default_cwd() -> PathBuf {
::std::env::current_dir().unwrap()
static CWD: Lazy<PathBuf> = Lazy::new(|| ::std::env::current_dir().unwrap());

CWD.clone()
}

/// `.swcrc` file
Expand Down
12 changes: 9 additions & 3 deletions crates/swc_common/src/plugin/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::env;

use once_cell::sync::Lazy;

use crate::collections::AHashMap;

/// Indexable key to the metadata context for a transform plugin.
Expand Down Expand Up @@ -48,12 +50,16 @@ impl TransformPluginMetadataContext {
env: String,
experimental: Option<AHashMap<String, String>>,
) -> Self {
static CWD: Lazy<Option<String>> = Lazy::new(|| {
env::current_dir()
.map(|cwd| cwd.as_path().to_string_lossy().to_string())
.ok()
});

TransformPluginMetadataContext {
filename,
env,
cwd: env::current_dir()
.map(|cwd| cwd.as_path().to_string_lossy().to_string())
.ok(),
cwd: CWD.clone(),
experimental: experimental.unwrap_or_default(),
}
}
Expand Down
Loading