oxc-project
oxc
BlogDocsChangelog

perf(allocator/vec2): optimize reserving memory

#9792Merged
Comparing
03-15-pref_allocator_vec2_optimize_reserving_memory
(
17a9320
) with
main
(
e924c2b
)
CodSpeed Performance Gauge
0%
Untouched
33

Benchmarks

Passed

parser[cal.com.tsx]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
+2%
30.2 ms29.7 ms
parser[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
+2%
91.4 µs90.1 µs
parser[antd.js]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
+1%
113.7 ms112.2 ms
parser[checker.ts]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
+1%
57 ms56.4 ms
lexer[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
+1%
20.9 µs20.7 µs
parser[pdf.mjs]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
+1%
18.3 ms18.1 ms
mangler[antd.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_mangler
CodSpeed Performance Gauge
+1%
15.9 ms15.8 ms
semantic[checker.ts]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
+1%
64.7 ms64.3 ms
semantic[cal.com.tsx]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
+1%
26.2 ms26 ms
semantic[antd.js]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
0%
105.4 ms104.9 ms
transformer[antd.js]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
0%
51.8 ms51.6 ms
semantic[pdf.mjs]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
0%
17.2 ms17.1 ms
mangler[react.development.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_mangler
CodSpeed Performance Gauge
0%
293.9 µs292.7 µs
minifier[react.development.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_minifier
CodSpeed Performance Gauge
0%
1.8 ms1.8 ms
minifier[antd.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_minifier
CodSpeed Performance Gauge
0%
163.9 ms163.3 ms
minifier[typescript.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_minifier
CodSpeed Performance Gauge
0%
289.2 ms288.4 ms
transformer[checker.ts]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
0%
23.2 ms23.1 ms
transformer[pdf.mjs]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
0%
10.3 ms10.3 ms
semantic[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
0%
74.4 µs74.3 µs
codegen_sourcemap[checker.ts]
tasks/benchmark/benches/codegen.rs::codegen::bench_codegen
CodSpeed Performance Gauge
0%
65.7 ms65.7 ms
mangler[typescript.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_mangler
CodSpeed Performance Gauge
0%
39.4 ms39.4 ms
linter[cal.com.tsx]
tasks/benchmark/benches/linter.rs::linter::bench_linter
CodSpeed Performance Gauge
0%
1.2 s1.2 s
lexer[antd.js]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
0%
24.1 ms24.1 ms
codegen[checker.ts]
tasks/benchmark/benches/codegen.rs::codegen::bench_codegen
CodSpeed Performance Gauge
0%
22.6 ms22.6 ms
lexer[checker.ts]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
0%
14.5 ms14.5 ms
linter[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/linter.rs::linter::bench_linter
CodSpeed Performance Gauge
0%
2.7 ms2.7 ms
estree[checker.ts]
tasks/benchmark/benches/parser.rs::parser::bench_estree
CodSpeed Performance Gauge
0%
87.4 ms87.4 ms
lexer[cal.com.tsx]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
0%
5.7 ms5.7 ms
lexer[pdf.mjs]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
0%
3.8 ms3.8 ms
linter[checker.ts]
tasks/benchmark/benches/linter.rs::linter::bench_linter
CodSpeed Performance Gauge
0%
3 s3 s
isolated-declarations[vue-id.ts]
tasks/benchmark/benches/isolated_declarations.rs::transformer::bench_isolated_declarations
CodSpeed Performance Gauge
0%
57.6 ms57.8 ms
transformer[cal.com.tsx]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
0%
34.2 ms34.3 ms
transformer[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
-1%
144.9 µs146 µs

Commits

Click on a commit to change the comparison range
Base
main
e924c2b
+0.33%
perf(allocator/vec2): optimize reserving memory (#9792) resolve: https://github.com/oxc-project/oxc/pull/9656#issuecomment-2723678880 #9656 brought a small performance improvement for the transformer but also led the parser to 1% performance hits. This PR returns performance by splitting `reserve_internal` to `reserve_exact_internal` and `reserve_amortized_internal` respectively the internal implementation of `reserve_exact` and `reserve`. Why the change can improve performance? The original `reserve_internal` implementation has a check for reserve strategy, https://github.com/oxc-project/oxc/blob/fef680a4775559805e99622fb5aa6155cdf47034/crates/oxc_allocator/src/vec2/raw_vec.rs#L664-L668 which is can be avoided because the caller of `reserve_internal` already knows the reserve strategy. After the change, the `reserve_exact` and `reserve` can call the corresponding internal implementation directly, which can avoid unnecessary checks. Likewise, the `Fallibility` check can also be avoided, https://github.com/oxc-project/oxc/blob/fef680a4775559805e99622fb5aa6155cdf47034/crates/oxc_allocator/src/vec2/raw_vec.rs#L681-L683 because we know where the errors should be handled. ~~Due to this change, I also replaced Bumpalo's `CollecitonAllocErr` with allocator-api2's `TryReserveError` because `CollecitonAllocErr::AllocErr` cannot pass in a `Layout`.~~ I ended up reverting https://github.com/oxc-project/oxc/pull/9792/commits/937c61a65815f84d6998764e77b1aabac4a8dc71 as it caused transformer performance 1%-2% regression (See [codspeed](https://codspeed.io/oxc-project/oxc/branches/03-15-pref_allocator_vec2_optimize_reserving_memory) and switch to "replace CollectionAllocErr with TryReserveError" commit), and replaced by https://github.com/oxc-project/oxc/pull/9792/commits/84edacdcc131e1891a02e9f5862cbf52da71a355 I've tried various way to save the performance but it not work. I suspect the cause is that `TryReserveError` is 16 bytes whereas `CollecitonAllocErr` is only 1 byte. So, after both checks are removed, the performance returns to the original. The whole change is according to standard `RawVec`'s implementation. See https://doc.rust-lang.org/src/alloc/raw_vec.rs.html <img width="608" alt="image" src="https://github.com/user-attachments/assets/53066d8e-26f0-4eb1-8f33-4ca9e517e75b" />
17a9320
9 months ago
by Dunqing
© 2025 CodSpeed Technology
Home Terms Privacy Docs