exponential build times when returning impl T
#100886
Labels
C-bug
Category: This is a bug.
I-compiletime
Issue: Problems and improvements with respect to compile times.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I work on the
s2n-quic
project. We haveClient
andServer
builders that allow applications to configure the behavior of the library through several "providers":We noticed that as the number of configured providers increased, the time that
rustc
spends type checking exponentially increases. I've created a standalone example of this behavior in a gist. Note that it doesn't even need to call different providers; the example callswith_a
over and over again with the same type.The issue seems to be with the use of
impl T
in each of thewith_*
functions:If the return type is changed to
Builder<U>
, the compile time is unchanged in relation to the number of calls.Here's a summary from the self-profile:
My expectation is that
impl T
would be equivalent toU
in the amount of type checking needed. My preference would be to useimpl T
, as it keeps the display size of the type in the UI minimal.Let me know if you need any additional details 😃.
Meta
rustc --version --verbose
:nightly (for the self-profile):
I also tested this behavior on an old version of
rustc
(1.35) and compile times were actually worse so there has been some improvement since then.The text was updated successfully, but these errors were encountered: