mirror of
https://github.com/swc-project/swc.git
synced 2024-10-04 12:18:08 +03:00
refactor(*): Remove fastmem
(#4211)
This commit is contained in:
parent
30742ae6e7
commit
3b1da220e2
2
.github/workflows/cargo.yml
vendored
2
.github/workflows/cargo.yml
vendored
@ -102,8 +102,6 @@ jobs:
|
||||
os: ubuntu-latest
|
||||
- crate: enum_kind
|
||||
os: ubuntu-latest
|
||||
- crate: fastmem
|
||||
os: ubuntu-latest
|
||||
- crate: from_variant
|
||||
os: ubuntu-latest
|
||||
- crate: jsdoc
|
||||
|
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -815,13 +815,6 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
|
||||
|
||||
[[package]]
|
||||
name = "fastmem"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rayon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fixedbitset"
|
||||
version = "0.4.1"
|
||||
@ -3721,11 +3714,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_node_base"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
dependencies = [
|
||||
"fastmem",
|
||||
"mimalloc-rust",
|
||||
"swc_common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1,14 +0,0 @@
|
||||
[package]
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
description = "Configurable utilities for fast memory operations"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
name = "fastmem"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.1.0"
|
||||
|
||||
[features]
|
||||
enable = ["rayon"]
|
||||
|
||||
[dependencies]
|
||||
rayon = { version = "1", optional = true }
|
@ -1,97 +0,0 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
pub fn drop_fast<T>(v: T)
|
||||
where
|
||||
T: Send + 'static,
|
||||
{
|
||||
FastDrop::new(v);
|
||||
}
|
||||
|
||||
/// Utility type to deallocate memory in another thread.
|
||||
///
|
||||
///
|
||||
///
|
||||
/// If ths feature `enable` is turned on, the value will be deallocated in other
|
||||
/// thread.
|
||||
///
|
||||
/// This type uses [rayon::spawn]
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct FastDrop<T>
|
||||
where
|
||||
T: Send + 'static,
|
||||
{
|
||||
value: Option<T>,
|
||||
}
|
||||
|
||||
impl<T> Default for FastDrop<T>
|
||||
where
|
||||
T: Send + 'static,
|
||||
T: Default,
|
||||
{
|
||||
#[inline(always)]
|
||||
fn default() -> Self {
|
||||
Self::new(T::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> FastDrop<T>
|
||||
where
|
||||
T: Send,
|
||||
{
|
||||
#[inline(always)]
|
||||
pub fn new(value: T) -> Self {
|
||||
let value = Some(value);
|
||||
Self { value }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<T> for FastDrop<T>
|
||||
where
|
||||
T: Send,
|
||||
{
|
||||
#[inline(always)]
|
||||
fn from(value: T) -> Self {
|
||||
Self::new(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for FastDrop<T>
|
||||
where
|
||||
T: Send,
|
||||
{
|
||||
type Target = T;
|
||||
|
||||
#[inline(always)]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
debug_assert!(self.value.is_some());
|
||||
// Safety: self.value can be None only if drop is called.
|
||||
unsafe { self.value.as_ref().unwrap_unchecked() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DerefMut for FastDrop<T>
|
||||
where
|
||||
T: Send,
|
||||
{
|
||||
#[inline(always)]
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
debug_assert!(self.value.is_some());
|
||||
// Safety: self.value can be None only if drop is called.
|
||||
unsafe { self.value.as_mut().unwrap_unchecked() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Drop for FastDrop<T>
|
||||
where
|
||||
T: Send,
|
||||
{
|
||||
fn drop(&mut self) {
|
||||
#[cfg(feature = "enable")]
|
||||
if let Some(value) = self.value.take() {
|
||||
rayon::spawn(move || {
|
||||
std::mem::drop(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
//! Utilities to unblock main thread.
|
||||
//!
|
||||
//! # Cargo Features
|
||||
//!
|
||||
//! ## `enable`
|
||||
//!
|
||||
//! This enables fast-mode of this crate.
|
||||
|
||||
#![deny(clippy::all)]
|
||||
#![deny(unused)]
|
||||
|
||||
pub use self::fast_drop::*;
|
||||
|
||||
mod fast_drop;
|
@ -23,38 +23,38 @@ swc_v1 = ["swc_node_bundler/swc_v1"]
|
||||
swc_v2 = ["swc_node_bundler/swc_v2"]
|
||||
|
||||
[build-dependencies]
|
||||
napi-build = { version = "1" }
|
||||
napi-build = {version = "1"}
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
backtrace = "0.3"
|
||||
napi = { version = "2", default-features = false, features = [
|
||||
napi = {version = "2", default-features = false, features = [
|
||||
"napi3",
|
||||
"serde-json",
|
||||
] }
|
||||
napi-derive = { version = "2", default-features = false, features = [
|
||||
]}
|
||||
napi-derive = {version = "2", default-features = false, features = [
|
||||
"type-def",
|
||||
] }
|
||||
node_macro_deps = { path = "../node_macro_deps" }
|
||||
]}
|
||||
node_macro_deps = {path = "../node_macro_deps"}
|
||||
path-clean = "0.1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { version = "1", features = ["unbounded_depth"] }
|
||||
swc = { path = "../swc", features = ["concurrent", "node"] }
|
||||
swc_atoms = { version = "0.2.4", path = "../swc_atoms" }
|
||||
swc_bundler = { path = "../swc_bundler" }
|
||||
swc_common = { path = "../swc_common", features = ["sourcemap"] }
|
||||
swc_ecma_ast = { path = "../swc_ecma_ast" }
|
||||
swc_ecma_lints = { path = "../swc_ecma_lints", features = [
|
||||
serde = {version = "1", features = ["derive"]}
|
||||
serde_json = {version = "1", features = ["unbounded_depth"]}
|
||||
swc = {path = "../swc", features = ["concurrent", "node"]}
|
||||
swc_atoms = {version = "0.2.4", path = "../swc_atoms"}
|
||||
swc_bundler = {path = "../swc_bundler"}
|
||||
swc_common = {path = "../swc_common", features = ["sourcemap", "perf"]}
|
||||
swc_ecma_ast = {path = "../swc_ecma_ast"}
|
||||
swc_ecma_lints = {path = "../swc_ecma_lints", features = [
|
||||
"non_critical_lints",
|
||||
] }
|
||||
swc_ecma_loader = { path = "../swc_ecma_loader" }
|
||||
swc_ecma_parser = { path = "../swc_ecma_parser" }
|
||||
swc_node_base = { path = "../swc_node_base" }
|
||||
swc_node_bundler = { path = "../swc_node_bundler" }
|
||||
swc_plugin_runner = { path = "../swc_plugin_runner", optional = true, default-features = false }
|
||||
tracing = { version = "0.1.32", features = ["release_max_level_info"] }
|
||||
]}
|
||||
swc_ecma_loader = {path = "../swc_ecma_loader"}
|
||||
swc_ecma_parser = {path = "../swc_ecma_parser"}
|
||||
swc_node_base = {path = "../swc_node_base"}
|
||||
swc_node_bundler = {path = "../swc_node_bundler"}
|
||||
swc_plugin_runner = {path = "../swc_plugin_runner", optional = true, default-features = false}
|
||||
tracing = {version = "0.1.32", features = ["release_max_level_info"]}
|
||||
tracing-chrome = "0.5.0"
|
||||
tracing-futures = "0.2.5"
|
||||
tracing-subscriber = { version = "0.3.9", features = ["env-filter"] }
|
||||
wasmer = { version = "2.2.1", optional = true, default-features = false }
|
||||
wasmer-wasi = { version = "2.2.1", optional = true, default-features = false }
|
||||
tracing-subscriber = {version = "0.3.9", features = ["env-filter"]}
|
||||
wasmer = {version = "2.2.1", optional = true, default-features = false}
|
||||
wasmer-wasi = {version = "2.2.1", optional = true, default-features = false}
|
||||
|
@ -6,15 +6,11 @@ edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
name = "swc_node_base"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
fastmem = { version = "0.1.0", path = "../fastmem", features = ["enable"] }
|
||||
swc_common = { version = "0.17.14", path = "../swc_common", features = [
|
||||
"perf",
|
||||
] }
|
||||
|
||||
[target.'cfg(not(all(target_os = "linux", target_arch = "aarch64", target_env = "musl")))'.dependencies]
|
||||
mimalloc-rust = "=0.1.5"
|
||||
|
@ -29,20 +29,20 @@ plugin = [
|
||||
[dependencies]
|
||||
anyhow = "1.0.42"
|
||||
console_error_panic_hook = "0.1.6"
|
||||
js-sys = { version = "0.3.56", optional = true }
|
||||
js-sys = {version = "0.3.56", optional = true}
|
||||
once_cell = "1.10.0"
|
||||
parking_lot_core = "0.9.1"
|
||||
path-clean = "0.1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde = {version = "1", features = ["derive"]}
|
||||
serde_json = "1"
|
||||
swc = { path = "../swc" }
|
||||
swc_common = { path = "../swc_common" }
|
||||
swc_ecma_lints = { path = "../swc_ecma_lints", features = [
|
||||
swc = {path = "../swc"}
|
||||
swc_common = {path = "../swc_common", features = ["perf"]}
|
||||
swc_ecma_lints = {path = "../swc_ecma_lints", features = [
|
||||
"non_critical_lints",
|
||||
] }
|
||||
swc_ecmascript = { path = "../swc_ecmascript" }
|
||||
swc_plugin_runner = { path = "../swc_plugin_runner", default-features = false, optional = true }
|
||||
tracing = { version = "0.1.32", features = ["release_max_level_off"] }
|
||||
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
|
||||
wasmer = { version = "2.2.1", optional = true, default-features = false }
|
||||
wasmer-wasi = { version = "2.2.1", optional = true, default-features = false }
|
||||
]}
|
||||
swc_ecmascript = {path = "../swc_ecmascript"}
|
||||
swc_plugin_runner = {path = "../swc_plugin_runner", default-features = false, optional = true}
|
||||
tracing = {version = "0.1.32", features = ["release_max_level_off"]}
|
||||
wasm-bindgen = {version = "0.2", features = ["serde-serialize"]}
|
||||
wasmer = {version = "2.2.1", optional = true, default-features = false}
|
||||
wasmer-wasi = {version = "2.2.1", optional = true, default-features = false}
|
||||
|
Loading…
Reference in New Issue
Block a user