mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
edc70eae97
#13622 and #13624 altered what happens when the `fixed_size` Cargo feature is enabled. Previously, enabling that feature altered behavior of `AllocatorPool`. Now the feature is additive - it does nothing on it's own, but only adds additional APIs, and *those APIs* can be used to alter behavior. The purpose of the `disable_fixed_size` Cargo feature was to prevent the `fixed_size` feature being activated when tests are run with `--all-features`. Now that enabling `fixed_size` feature doesn't alter behavior, we don't need to worry about it being enabled in tests. Therefore `disable_fixed_size` feature can be removed. This removes a bunch of `#[cfg]` boilerplate, and ugly hacks which were previously required to workaround feature unification.
1.9 KiB
1.9 KiB
Oxc Allocator
A high-performance memory allocator using bump-based arena allocation for fast AST node creation.
Overview
Oxc uses a bump-based memory arena for faster AST allocations. This crate provides an [Allocator] that manages memory efficiently by allocating objects in a single contiguous memory region, avoiding the overhead of individual heap allocations.
Key Features
- Bump allocation: Fast allocation by simply incrementing a pointer
- Arena-based memory management: All allocations live for the same lifetime
- Zero-copy data structures: Efficient
Box,Vec,String, andHashMapimplementations - Optimal for AST operations: Perfect for parse-transform-emit workflows
Architecture
The allocator is designed specifically for AST processing workflows where:
- A large number of nodes are allocated during parsing
- All nodes have the same lifetime (tied to the AST)
- Memory is released all at once when the AST is dropped
This approach is significantly faster than using the system allocator for AST operations.
Features
serialize- Enables serialization support forBoxandVecwithserdeandoxc_estree.pool- EnablesAllocatorPool.bitset- EnablesBitSet.from_raw_parts- Adds unsafefrom_raw_partsmethod (not recommended for general use).fixed_size- MakesAllocatorPoolcreate large fixed-size allocators, instead of flexibly-sized ones. Only supported on 64-bit little-endian platforms at present. Usage of this feature is not advisable, and it will be removed as soon as we're able to.track_allocations- Count allocations and reallocations. For internal use only. The APIs provided by this feature are sketchy at best, and possibly undefined behavior. Do not enable this feature under any circumstances in production code.disable_track_allocations- Disablestrack_allocationsfeature. Purpose is to prevent--all-featuresenabling allocation tracking.