-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Very bad performance of cargo check
on generic code
#125994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
just confirming my scan of the code here: this is an HList, right? |
It's the same concept, but my own implementation of it. (I didn't know about the frunk crate before this, and the full type in my crate is a little expanded compared to that) |
Yes, that's absolutely fine, I just wanted to confirm my hunch about this being a recursive typechecking case (IIRC we don't necessarily cache certain typechecking results, and I dimly remember something about not being certain such caching would be sound in the current solver). |
I should explain how it works Parsers combined with the When parsers are part of a sequence, they can either output something ( In addition to this, parsers can either be resumable or not. The two problematic trait implementations at the top of the example code are examples of resumable parsers. When a resumable parser succeeds parsing with a resumable status, that parser can be resumed. If a parser later on in a sequence fails, the sequence parser will rewind to the nearest resumable parser and resume parsing from there. Resumable parsers have the |
I reduced compile time by 15 seconds by putting (It still takes 30 seconds with those changes) |
I'm writing a parser crate. Yesterday as I fixed some code I ran into a serious performance issue with type checking in the rust compiler. The code linked below takes 50 seconds to run
cargo check
on my Macbook Pro (M2 Pro).I've tried to make a minimal reproduction by reducing the code a lot and simplifying it a little. It's still a little big at 575 lines (sorry), but the problematic code is at the start. The function at the beginning is a test function from my crate that tests functionality of combining certain parsers. This function is responsible for the slowness. The two trait implementations following that are traits that implement the functionality that is tested by that function, that I wrote yesterday. The rest of the code is dependencies.
I have a function that tests the same thing with simpler kind of parser that lacks the State associated type (not included). That one compiles in a fraction of a second.
I've hosted the example code on the rust playground, but compile fails there (I assume it times out). To reproduce, make a new library crate, copy the code to lib.rs and run
cargo check
to see the problem. (The compiled code doesn't work because everything is stubbed out. The issue is the time to check/compile)Here's the code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1c6bb86548e817430c28ce83d51bc65d
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: