rust-lang / rust-lang/rust-bindgen
Bindgen becomes incredibly slow when using `--enable-function-attribute-detection` with newer-style `[[attribute]]` syntax.
@pvdrz is already working on this.
Since Sep 7, 2022.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
We currently use bindgen 0.59.1 for our very large codebase (~1-2 million lines of C).
The other day, we switched all of our C code from using __attribute__((...)) syntax to using the newer [[...]] syntax. A large majority of our functions have attributes (every fallible function has [[nodiscard]], and the majority of functions are fallible).
This ended up causing bindgen to slow down by a factor of more than 10x. Generating bindings for a given library went from taking between 10 to 20 seconds to taking between 2 and 4 minutes. Disabling --enable-function-attribute-detection resolved the issue.
I took a little look through the code and found the implementation of has_attr:
I wonder if maybe the call to visit() is recursing down too deep. Like if the attributes are on a function definition, could it be visiting all the statements within the function body? Idk, I don't know the structure of the clang AST very well, and the doxygen doesn't make it very easy to learn, so I'm really just shooting in the dark here.
I suppose it's possible that the issue lies in clang, but we aren't seeing any regression in C compilation speed after switching to the new attribute style, so it seems like that's unlikely to be the case.
Anybody have any ideas as to what could be causing this? We'd like to turn function-attribute-detection back on eventually since it's nice to have #[must_use], but the slowdown isn't acceptable for us.
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.
Assessment
This issue has not been assessed yet.