[BUG]: slow compile if very long std::array being used with clang-18
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
3.0.0
Problem description
I've found that pybind11 compile time very slow if very long std::array being used
clang-18 spends 90 seconds to finish, clang-20 11 seconds, g++-13 13 seconds.
tried 2.16.3/3.0.0 both compile slow with clang-18. clang ftime-trace shows that most of time spent in codegen
for function
std::array<int, 102400ul> pybind11::detail::vector_to_array_impl<std::array<int, 102400ul>, std::vector<int, std::allocator<int>>, 0ul, 1ul, 2ul, 3ul, 4ul, 5ul, 6ul, 7ul, 8ul, 9ul, 10ul, 11ul, ....
I've created a repo to show this issue https://github.com/comicfans/pybind11_slow_clang/tree/main
clang-18 compile trace (which can be loaded into chrome://tracing)
basic.cpp.json
Reproducible example code
#include <array>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
namespace py = pybind11;
struct SlowType {
std::array<int, 102400> member{};
};
PYBIND11_MODULE(basic, module) {
py::class_<SlowType>(module, "SlowType")
.def(py::init<>())
.def_readwrite("member", &SlowType::member);
}
Is this a regression? Put the last known working version here if it is.
Not a regression
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal basic.cpp reproducer and the vector_to_array_impl instantiation reached through pybind11/stl.h; compare clang-18 with clang-20 and g++-13 while inspecting the supplied ftime trace. Done means the cause of the long std::array compile time is identified and a validated fix or documented limitation is agreed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend-api-design, performance
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100