Skip to content

Commit

Permalink
refactor(transformer): pre-allocate more stack space (#6095)
Browse files Browse the repository at this point in the history
Pre-allocate 16 bytes for stacks in transforms that use them. Allocators usually support minimum of 16 bytes for allocations anyway. Now that we're using `SparseStack`, allocating decent capacity is now cheap.
  • Loading branch information
overlookmotel committed Sep 27, 2024
1 parent 6a68db0 commit 8146517
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/oxc_transformer/src/helpers/stack/capacity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ pub trait StackCapacity<T> {

/// Default capacity of stack.
///
/// Same defaults as [`std::vec::Vec`] uses.
/// Same defaults as [`std::vec::Vec`] uses, except 16 bytes for types with size 1 (instead of 8).
/// Allocators will usually allocate minimum 16 bytes anyway.
const DEFAULT_CAPACITY: usize = {
// It's impossible for this to exceed `MAX_CAPACITY` because `size_of::<T>() >= align_of::<T>()`
match size_of::<T>() {
1 => 8,
1 => 16,
size if size <= 1024 => 4,
_ => 1,
}
Expand Down

0 comments on commit 8146517

Please sign in to comment.