Repository navigation
Description
Warning
This issue is not yet ready for a PR. If you are interested in contributing to scikit-learn, please have a look at our contributing guidelines, and in particular the sections for new contributors and the "Needs triage" label.
Modern CPUs such as Intel Core Ultra Series 3 processors and Apple M1/M2/... series have different core speeds (P-cores, E-cores, LP-cores...).
joblib and native libraries such as OpenMP or BLAS libraries will often start one thread per core. However, thread scheduling overhead can cause performance degradation compared to using fewer threads on those architectures, especially when iterating on many small data problems, for instance when bagging or grid searching models on small data.
The purpose of this issue is to assess how frequent and how bad is this problem in practice and track coordinate remediation efforts.
Concrete cases of this problem
- HistGradientBoostingClassifier/Regressor 15x slowdown on small data problems compared to disabled OpenMP threading #30662
- KMeans(init='k-means++') performance issue with OpenBLAS #17334 (comment)
- ... (comment or edit to add more)
Possible remediation strategies
- Refactor parallel sections to group more work per parallel task (possibly dynamically based on the data size)
- Dynamically adjust the number of threads based on a cost model informed by CPU architecture, data shape or benchmark: this sounds complex
- Limit the number of threads on hybrid GPUs (e.g. either 1 thread per performance core, or 1 thread per performance core and 1 additional thread per two efficiency core for instance):
Activity
itamarst commentedon Jun 5, 2026
Here is an idea, expanding on mention of benchmarking above:
The smaller amount with single thread is to reduce the slowdown if N threads are significantly faster, especially important when you have large amounts of data; the higher amount with N threads is to amortize overhead of starting thread pool.
Variations:
itamarst commentedon Jun 5, 2026
For macOS specifically it appears there is an additional problem. macOS has a QoS setting for threads, and OpenMP not doing this (or using the wrong setting) may be part of the problem; long-running threads might be auto-migrated to efficiency cores.
https://www.reddit.com/r/HPC/comments/1t0aaf3/openmp_coding_on_mac_os_x_and_efficiency_e_cores/ talks about this and some solutions.
More discussion, where they actually used a lower QoS level to get faster results: https://jmmv.dev/2019/03/macos-threads-qos-and-bazel.html (the linked patch provides a solution for process pools, but not threads.)
itamarst commentedon Nov 5, 2026
A relevant piece of information that might explain some of this: I'm pretty sure OpenBLAS specifically works by breaking a chunk of work into a number of chunks equal to the number of cores, and then has to wait until all jobs are done. So if you have mixture of fast and slow cores, actual speed is that of slow cores. (Compare to OpenMP, which can use smaller chunks and so can break up work in way that adapts better to different workloads on different cores.)
So for OpenBLAS specifically setting the limit to number of performance cores only should be a win, so long as they are the majority (or if equal in number, if performance cores are at least twice as fast as slow cores).