oxc-project
sort-package-json
BlogDocsChangelog

Optimize array sorting with in-place operations

#14Merged
Comparing
perf/in-place-sorting
(
fc3c921
) with
main
(
64c6ffa
)
CodSpeed Performance Gauge
+1%
Untouched
4

Benchmarks

Passed

sort large package.json
benches/sort.rs::benches::bench_large_package
CodSpeed Performance Gauge
+3%
88.5 µs86.2 µs
sort small package.json
benches/sort.rs::benches::bench_small_package
CodSpeed Performance Gauge
+2%
133.3 µs130.7 µs
sort already sorted package.json
benches/sort.rs::benches::bench_already_sorted
CodSpeed Performance Gauge
+1%
128.6 µs127.6 µs
sort minimal package.json
benches/sort.rs::benches::bench_minimal_package
CodSpeed Performance Gauge
0%
12 µs11.9 µs

Commits

Click on a commit to change the comparison range
Base
main
64c6ffa
+1.45%
Optimize array sorting with in-place operations Changes to sort_array_unique(): - Sort Vec<Value> in-place by comparing &str references - Eliminate Vec<String> allocation and N string copies - Zero heap allocations vs 3+ allocations before - Affects 11 fields: keywords, categories, libc, bundled deps, etc. Changes to sort_paths_naturally(): - Pre-compute depth and lowercase once per string (not on every comparison) - Eliminate O(N² log N) to_lowercase() calls during sorting - Move Values instead of copying strings - Reduce from 3+ Vec allocations to 1 Vec allocation Performance impact: - sort_array_unique: 100% reduction in allocations (3+ → 0) - sort_paths_naturally: 66% reduction in allocations + ~1000x fewer temporary string allocations - Both functions: Zero string copies (N → 0)
6ce78fe
10 days ago
by Boshen
+0.01%
Fix formatting with cargo fmt - Remove trailing spaces before blank lines - Format sort_unstable_by closure on one line
fc3c921
10 days ago
by Boshen
© 2025 CodSpeed Technology
Home Terms Privacy Docs