mirror of
https://github.com/swc-project/swc.git
synced 2024-11-22 06:46:41 +03:00
perf(es): Cache current_dir()
system calls (#9683)
Some checks are pending
CI / Cargo fmt (push) Waiting to run
CI / Cargo clippy (push) Waiting to run
CI / Check license of dependencies (push) Waiting to run
CI / Check (macos-latest) (push) Waiting to run
CI / Check (ubuntu-latest) (push) Waiting to run
CI / Check (windows-latest) (push) Waiting to run
CI / Test wasm (binding_core_wasm) (push) Waiting to run
CI / Test wasm (binding_minifier_wasm) (push) Waiting to run
CI / Test wasm (binding_typescript_wasm) (push) Waiting to run
CI / List crates (push) Waiting to run
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Blocked by required conditions
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Waiting to run
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Waiting to run
CI / Test with @swc/cli (push) Waiting to run
CI / Miri (better_scoped_tls) (push) Waiting to run
CI / Miri (string_enum) (push) Waiting to run
CI / Miri (swc) (push) Waiting to run
CI / Miri (swc_bundler) (push) Waiting to run
CI / Done (push) Blocked by required conditions
Benchmark / Bench everything (push) Waiting to run
Publish crates (auto) / Publish cargo crates (push) Waiting to run
Some checks are pending
CI / Cargo fmt (push) Waiting to run
CI / Cargo clippy (push) Waiting to run
CI / Check license of dependencies (push) Waiting to run
CI / Check (macos-latest) (push) Waiting to run
CI / Check (ubuntu-latest) (push) Waiting to run
CI / Check (windows-latest) (push) Waiting to run
CI / Test wasm (binding_core_wasm) (push) Waiting to run
CI / Test wasm (binding_minifier_wasm) (push) Waiting to run
CI / Test wasm (binding_typescript_wasm) (push) Waiting to run
CI / List crates (push) Waiting to run
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Blocked by required conditions
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Waiting to run
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Waiting to run
CI / Test with @swc/cli (push) Waiting to run
CI / Miri (better_scoped_tls) (push) Waiting to run
CI / Miri (string_enum) (push) Waiting to run
CI / Miri (swc) (push) Waiting to run
CI / Miri (swc_bundler) (push) Waiting to run
CI / Done (push) Blocked by required conditions
Benchmark / Bench everything (push) Waiting to run
Publish crates (auto) / Publish cargo crates (push) Waiting to run
**Description:** Cache `current_dir()` system calls. Those are needless because we already cache `current_dir` in some places so it will break if the user changes cwd anyway. **Related issue:** - https://github.com/swc-project/swc/issues/9601
This commit is contained in:
parent
09de6f4065
commit
7aab945a21
7
.changeset/silent-cows-brake.md
Normal file
7
.changeset/silent-cows-brake.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
swc: patch
|
||||||
|
swc_common: patch
|
||||||
|
swc_core: patch
|
||||||
|
---
|
||||||
|
|
||||||
|
perf(es): Cache `current_dir()` system calls
|
@ -842,7 +842,9 @@ pub struct CallerOptions {
|
|||||||
|
|
||||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
|
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
|
||||||
fn default_cwd() -> PathBuf {
|
fn default_cwd() -> PathBuf {
|
||||||
::std::env::current_dir().unwrap()
|
static CWD: Lazy<PathBuf> = Lazy::new(|| ::std::env::current_dir().unwrap());
|
||||||
|
|
||||||
|
CWD.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `.swcrc` file
|
/// `.swcrc` file
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use crate::collections::AHashMap;
|
use crate::collections::AHashMap;
|
||||||
|
|
||||||
/// Indexable key to the metadata context for a transform plugin.
|
/// Indexable key to the metadata context for a transform plugin.
|
||||||
@ -48,12 +50,16 @@ impl TransformPluginMetadataContext {
|
|||||||
env: String,
|
env: String,
|
||||||
experimental: Option<AHashMap<String, String>>,
|
experimental: Option<AHashMap<String, String>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
static CWD: Lazy<Option<String>> = Lazy::new(|| {
|
||||||
|
env::current_dir()
|
||||||
|
.map(|cwd| cwd.as_path().to_string_lossy().to_string())
|
||||||
|
.ok()
|
||||||
|
});
|
||||||
|
|
||||||
TransformPluginMetadataContext {
|
TransformPluginMetadataContext {
|
||||||
filename,
|
filename,
|
||||||
env,
|
env,
|
||||||
cwd: env::current_dir()
|
cwd: CWD.clone(),
|
||||||
.map(|cwd| cwd.as_path().to_string_lossy().to_string())
|
|
||||||
.ok(),
|
|
||||||
experimental: experimental.unwrap_or_default(),
|
experimental: experimental.unwrap_or_default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user