Skip to content

perf: add a mimalloc allocation fast path - #15658

Draft
LingyuCoder wants to merge 5 commits into
mainfrom
seal/try-mimalloc-fastpath
Draft

LingyuCoder wants to merge 5 commits into
mainfrom
seal/try-mimalloc-fastpath

Conversation

@LingyuCoder

@LingyuCoder LingyuCoder commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Motivation

Avoid the overhead of mimalloc's aligned allocation API for allocations with ordinary alignment requirements, and make the cached-source hash benchmarks measure actual lookups.

Changes

Implement the shared mimalloc adapter in rspack_allocator. Route requests with alignment up to align_of::<usize>() and no larger than the allocation size through mi_malloc / mi_zalloc, retaining the aligned fallback and existing deallocation and reallocation behavior. Register the binding's global allocator in rspack_binding_api, preserving its allocator selection, while benchmarks register their own wrapper around the shared implementation.

Separate cached-source lookups from single and batched HashMap lifecycles. Execute both lookups and include allocation and destruction in the lifecycle measurements, using new benchmark names for the changed workloads.

@LingyuCoder LingyuCoder changed the title refactor: add a mimalloc allocation fast path perf: add a mimalloc allocation fast path Sep 13, 2026
@github-actions

github-actions Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 91bc1f3 to fix: revert "feat(core): expose NormalModule beforeLoaders hook to JS" (#15660) by AsyncIter

🎉 Size decreased by 31.95KB from 68.85MB to 68.82MB (⬇️0.05%)

@github-actions

github-actions Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
popular-libs 1.7 MB 523.6 KB 0 0
react-10k 5.3 MB 1.3 MB 0 0
react-1k 799.2 KB 217.5 KB 0 0
react-5k 2.6 MB 662.0 KB 0 0
ui-components 4.9 MB 1.4 MB 0 0

Generated by Rsdoctor GitHub Action

@codspeed

codspeed Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 3.47%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 27 improved benchmarks
✅ 22 untouched benchmarks
🆕 3 new benchmarks
⏩ 48 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
rust@create_module_hashes 7.6 ms 7.1 ms +7.82%
rust@mangle_exports 3.1 ms 3 ms +5.68%
rust@create_concatenate_module_unsupported_syntax 17.6 ms 16.7 ms +4.85%
rust@concatenate_module_code_generation 43.7 ms 41.7 ms +4.76%
rust@create_concatenate_module 13.7 ms 13.1 ms +4.44%
rust@build_chunk_graph 26.1 ms 25 ms +4.37%
rust@build_module_graph 448 ms 429.3 ms +4.34%
rust@create_concatenate_module_bailouts 97.7 ms 93.7 ms +4.28%
rust@create_concatenate_module_shared_roots 17.4 ms 16.8 ms +4.04%
rust@flag_dependency_exports 5.1 ms 4.9 ms +3.54%
rust@create_chunk_assets 1.1 ms 1.1 ms +3.5%
sources@concat_source_add_few 583.9 ns 564.2 ns +3.5%
rust@create_named_module_ids 3.2 ms 3.1 ms +3.45%
bundle@css-modules-development 1.9 s 1.8 s +3.32%
rust@create_module_assets 169.6 µs 164.5 µs +3.12%
bundle@misc-development 2.8 s 2.7 s +3.1%
rust@build_swc-loader 1,003.5 ms 974.7 ms +2.96%
rust@flag_dependency_usage 10 ms 9.7 ms +2.93%
bundle@basic-react-development 151 ms 146.7 ms +2.87%
rust@create_full_hash 2.3 ms 2.3 ms +2.49%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing seal/try-mimalloc-fastpath (91bc1f3) with main (22f1dd8)

Open in CodSpeed

Footnotes

  1. 48 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@web-infra-dev web-infra-dev deleted a comment from codspeed Bot Sep 15, 2026
@web-infra-dev web-infra-dev deleted a comment from github-actions Bot Sep 15, 2026
@web-infra-dev web-infra-dev deleted a comment from github-actions Bot Sep 15, 2026
@web-infra-dev web-infra-dev deleted a comment from github-actions Bot Sep 15, 2026
LingyuCoder added a commit that referenced this pull request Sep 20, 2026
PR #15658's fast path calls libmimalloc_sys::mi_malloc directly for word-aligned layouts, relying on mimalloc's ordinary entry point to satisfy the requested alignment. mimalloc does not guarantee that contract across versions or build configurations, so the fast path cannot be relied upon for stability or accuracy. Restore the upstream mimalloc::MiMalloc global allocator.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant