Commit 32b3ece
authored
Add option to use mimalloc as global allocator (#16024)
* Add option to use mimalloc as global allocator
This commit adds a new feature to the cext and pyext crates to switch the
global allocator to use mimalloc [1] instead of the system allocator.
mimalloc promises better allocation performance and also lower resident
set size over glibc, macOS's libmalloc, or window's allocator [2]. In local
benchmarking using mimalloc improves runtime performance on transpiler
bencmarks in asv about 10% on my x86_64 benchmarking system. The
tradeoff for this is the mimalloc crate [3] internally builds and
statically links the mimalloc c library from source as part of cargo's
build process. This is all encapsulated in the mimalloc-sys's build.rs
using the cc [4] crate so it embeds very cleanly into the build system.
However, this does however require that a C compiler is available when
building from source. For building the Python package and ironically the
C standalone lib this was previously not a requirement.
When the feature is enabled it switches the global allocator to use
mimalloc. Since this is global for a compilation artifact we can only
do it once in qiskit crate, and we'll want to do it either in pyext xor
cext based on whether we're building a python extension or c standalone lib
so that only the outermost crate is opinionated about which allocator to
use. By default this feature is disabled on both crates and we opt-in to
it in the build system. For building pyext the setup.py file updates the
features we pass to setuptools-rust when building the extension to enable
the mimalloc crate and set the global allocator in the pyext code.
Similarly, the makefile is updated to do the same for build cext in
standalone mode. If we don't want to make this enabled by default
(primarily because of the dependency on a C compiler) for building from
source we can update the logic in the build scripts to expose an option
and only enable in CI for testing and for release artifacts. This is
something we'll need to discuss before releasing this option.
[1] https://github.com/microsoft/mimalloc
[2] Leijen, D., Zorn, B., de Moura, L. (2019). Mimalloc: Free List
Sharding in Action. In: Lin, A. (eds) Programming Languages and Systems.
APLAS 2019. Lecture Notes in Computer Science(), vol 11893. Springer,
Cham. https://doi.org/10.1007/978-3-030-34175-6_13
[3] https://crates.io/crates/mimalloc
[4] https://docs.rs/cc/latest/cc/
* Make mimalloc opt-in by default
This commit switches the mimalloc feature to be opt-in by default
everywhere. Since building mimalloc requires a C compiler and this does
significantly change the requirements for building Qiskit from source,
making it opt-in for people that want it is the best course of action
for now. This commit adds a new environment variable
`QISKIT_BUILD_WITH_MIMALLOC=1` which is used to enable building mimalloc
when building Qiskit. The CI jobs are updated to mix mimalloc and not in
Python test jobs and also to always enable mimalloc in wheel builds for
release.
* Improve CONTRIBUTING.md build section formatting
* Improve release notes
* Enable mimalloc for asv
This commti adds the mimalloc environment variable to the asv config too
so that we are enabling the use of mimalloc when running asv numbers.
This will mean the performance numbers we measure with asv are showing
the performance with mimalloc. This is desired as it will better capture
the performance of the packages we ship on release.1 parent 43e9c17 commit 32b3ece
17 files changed
Lines changed: 113 additions & 22 deletions
File tree
- .github/workflows
- crates
- cext
- src
- pyext
- src
- releasenotes/notes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| 131 | + | |
130 | 132 | | |
131 | 133 | | |
132 | 134 | | |
| |||
146 | 148 | | |
147 | 149 | | |
148 | 150 | | |
| 151 | + | |
149 | 152 | | |
150 | 153 | | |
151 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
| |||
61 | 66 | | |
62 | 67 | | |
63 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
64 | 72 | | |
65 | 73 | | |
66 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
17 | | - | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
| |||
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
45 | 52 | | |
46 | 53 | | |
47 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
17 | | - | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
113 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
178 | 189 | | |
179 | 190 | | |
180 | 191 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
| |||
135 | 139 | | |
136 | 140 | | |
137 | 141 | | |
138 | | - | |
| 142 | + | |
139 | 143 | | |
140 | 144 | | |
141 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
0 commit comments