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(allocator): Drop scoped_tls #9240

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Also, SWC tries to ensure that

for rust users.

MSRV of crates is currently `1.71`.
MSRV of crates is currently `1.73`.

To update all SWC crates you use, you can run `curl https://raw.githubusercontent.com/swc-project/swc/main/scripts/update-all-swc-crates.sh | bash -s`. This script will update all dependencies to the latest version and run `cargo build` to ensure that everything works.
Note that you need
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ ignore-interior-mutability = [
"swc_atoms::JsWord",
"swc_ecma_ast::Id",
]
msrv = "1.71"
msrv = "1.73"
type-complexity-threshold = 25000
1 change: 0 additions & 1 deletion crates/swc_allocator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ bumpalo = { workspace = true, features = [
] }
ptr_meta = { workspace = true }
rkyv = { workspace = true, optional = true }
scoped-tls = { workspace = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
triomphe = "0.1.13"
Expand Down
18 changes: 11 additions & 7 deletions crates/swc_allocator/src/alloc.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::{alloc::Layout, mem::transmute, ptr::NonNull};
use std::{alloc::Layout, cell::Cell, mem::transmute, ptr::NonNull};

use allocator_api2::alloc::Global;
use scoped_tls::scoped_thread_local;

use crate::{FastAlloc, MemorySpace};

scoped_thread_local!(pub(crate) static ALLOC: &'static SwcAllocator);
thread_local! {
static ALLOC: Cell<Option<&'static SwcAllocator>> = const { Cell::new(None) };
}

#[derive(Default)]
pub struct SwcAllocator(MemorySpace);
Expand All @@ -22,15 +23,18 @@ impl SwcAllocator {
transmute::<&'a SwcAllocator, &'static SwcAllocator>(self)
};

ALLOC.set(&s, f)
ALLOC.set(Some(s));
let ret = f();
ALLOC.set(None);
ret
}
}

impl Default for FastAlloc {
fn default() -> Self {
Self {
alloc: if ALLOC.is_set() {
Some(ALLOC.with(|v| *v))
alloc: if let Some(v) = ALLOC.get() {
Some(v)
} else {
None
},
Expand Down Expand Up @@ -87,7 +91,7 @@ unsafe impl allocator_api2::alloc::Allocator for FastAlloc {
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
if self.alloc.is_some() {
debug_assert!(
ALLOC.is_set(),
ALLOC.get().is_some(),
"Deallocating a pointer allocated with arena mode with a non-arena mode allocator"
);

Expand Down
Loading