Commit 5750690
authored
[mypyc] Make type objects immortal if using free threading (#19538)
If they are not immortal, concurrent construction of objects by multiple
threads can cause serious contention due to reference count updates.
Making them immortal is similar to how both user-defined normal Python
classes and built-in types in free-threaded builds are immortal.
Fix the issue for both native and non-native classes. Dataclasses still
have contention, and they may be harder to fix (this may require a fix
in CPython).
This speeds up a few micro-benchmarks that construct instances of
classes in multiple threads by a big factor (5x+).1 parent 0f78f9c commit 5750690
File tree
7 files changed
+56
-2
lines changed- mypyc
- irbuild
- lib-rt
- primitives
7 files changed
+56
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
424 | 424 | | |
425 | 425 | | |
426 | 426 | | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
427 | 431 | | |
428 | 432 | | |
429 | 433 | | |
| |||
433 | 437 | | |
434 | 438 | | |
435 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
436 | 444 | | |
437 | 445 | | |
438 | 446 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
265 | 268 | | |
266 | 269 | | |
267 | 270 | | |
| |||
449 | 452 | | |
450 | 453 | | |
451 | 454 | | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
452 | 460 | | |
453 | 461 | | |
454 | 462 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
164 | 166 | | |
165 | 167 | | |
166 | 168 | | |
| 169 | + | |
167 | 170 | | |
168 | 171 | | |
169 | 172 | | |
| |||
2322 | 2325 | | |
2323 | 2326 | | |
2324 | 2327 | | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
2325 | 2333 | | |
2326 | 2334 | | |
2327 | 2335 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
931 | 931 | | |
932 | 932 | | |
933 | 933 | | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
934 | 938 | | |
935 | 939 | | |
936 | 940 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1058 | 1058 | | |
1059 | 1059 | | |
1060 | 1060 | | |
1061 | | - | |
| 1061 | + | |
1062 | 1062 | | |
1063 | 1063 | | |
1064 | 1064 | | |
| |||
1088 | 1088 | | |
1089 | 1089 | | |
1090 | 1090 | | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
| 142 | + | |
143 | 143 | | |
| 144 | + | |
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
0 commit comments