-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Speedup compile times for joins #3288
Speedup compile times for joins #3288
Conversation
`DefaultSelection` type of joins This commit introduces infrastructure that allows to skip type checking the `DefaultSelection` of joins. diesel-rs#3223 discovered that this is responsible for a substantial amount of compile time for larger joins/codebases. We do not need to check this constraint there as it is always true because each of the tables/sides of the join already have an valid `DefaultSelection`. Therefore the resulting `DefaultSelection` must be valid for the join too (if there is no bug in diesel itself).
it doesn't compile as-is. The reason for this is that with this implem, ```rust let q = schema::some_table_1::table .inner_join(schema::some_table_2::table) .inner_join(schema::some_table_3::table.inner_join(schema::some_table_4::table)); ``` won't compile, because of this bound: ``` impl<Left, Right> QuerySource for Join<Left, Right, Inner> where Left: AppendSelection<Right::DefaultSelection>, ``` and we don't have `Left = Join<LeftLeft, LeftRight, Inner>: AppendSelection<SkipSelectableExpressionWrapper<_>>` because we don't have `SkipSelectableExpressionWrapper<_>: TupleAppend<SkipSelectableExpressionWrapper<_>>`
feb6ea1
to
d5fc92b
Compare
diesel/src/query_source/joins.rs
Outdated
// trait implementations to the inner type | ||
// | ||
// See https://github.com/diesel-rs/diesel/issues/3223 for details | ||
type DefaultSelection = self::private::SkipSelectableExpressionWrapper<Left::Output>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting... How did you trick the compiler into disabling check? For me, this looks like an insoluble task
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The relevant line is here: https://github.com/diesel-rs/diesel/pull/3288/files#diff-d0e8a449e498610baa9a5f3086200726d02bd5e1612f5f1d5587c4418baddf0eR482
This impl does not check that the trait holds true for the inner type, so it effectively skips the recursive trait bound check on large tuples, which is the underlying problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean, that the most important thing there that T
is not bounded, so the compiler does not do expensive recursive checks as it did before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's the main optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from these minor suggestions, LGTM for merge :)
Co-authored-by: Ten0 <9094255+Ten0@users.noreply.github.com>
…BoundCheckWrapper` as suggested in review
60594b4
to
d3dc7e5
Compare
Addresses #3223