-
-
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
DebugBinds/Query: Reduce monomorphization overhead #4417
Conversation
// This is not using the `?` operator to reduce the code size of this | ||
// function, which is getting copies a lot due to monomorphization. | ||
let query = match self.query() { | ||
Ok(query) => query, | ||
Err(err) => return Err(err), | ||
}; |
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.
I tried to use a tri!()
macro instead (see https://github.com/serde-rs/serde/blob/v1.0.217/serde/src/lib.rs#L290-L301), but that slightly bumped the numbers upwards again, so I'm not sure whether it's worth it for the readability benefit.
The output of `cargo llvm-lines --package diesel_tests --test integration_tests --profile test --features postgres` showed this struct as one of the main code size reasons, slowing down the compilation of applications. This commit brings the LLVM IR lines of the `Debug` implementation from 104763 down to 46809 (-55.3%).
The output of `cargo llvm-lines --package diesel_tests --test integration_tests --profile test --features postgres` showed this struct as one of the main code size reasons, slowing down the compilation of applications. This commit brings the LLVM IR lines of the `Debug` and `Display` implementations from 150633 down to 139574 (-7.3%).
Thanks for opening this PR. Such optimizations are really appreciated. I wonder whether it might be meaningful to use a similar strategy here to what we already do for the statement cache: diesel/diesel/src/connection/statement_cache/mod.rs Lines 252 to 287 in 3f69aa4
That would mean that instead of storing a reference to the generic query type we would rather just store a reference to a trait object in |
yeah, I thought about that as well, but I wasn't sure whether the performance overhead of the |
This commit replaces the generic `&'a T` field in `DebugBinds` with `&'a dyn QueryFragment<DB>`. This causes the number of LLVM copies of this struct to plummet from 743 to 1, since it is now only compiled once per backend implementation.
hmm, in general this seems to work, but https://github.com/diesel-rs/diesel/blob/3f69aa4570c505a94889e3c3de4e83e13bc6a37d/diesel/src/query_builder/insert_statement/insert_with_default_for_sqlite.rs isn't particularly happy about the removal of the generic |
Thanks for the update. I think removing the generic For a future diesel 3.0 version we might want to remove the |
5c7c508
to
e24912a
Compare
that didn't work since the code in https://github.com/diesel-rs/diesel/blob/3f69aa4570c505a94889e3c3de4e83e13bc6a37d/diesel/src/query_builder/insert_statement/insert_with_default_for_sqlite.rs is accessing |
total LLVM IR lines as reported by the above command:
|
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.
Thanks for working on this and thanks for providing these numbers ❤️
that seems unrelated to my changes 😅 |
Yes, seems like the CI image got updated and something is now missing. I need to fix that 😞 |
The output of
cargo llvm-lines --package diesel_tests --test integration_tests --profile test --features postgres
showed theDebug
andDisplay
implementations of theDebugBinds
andDebugQuery
structs as two of the main code size reasons, slowing down the compilation of applications. This commit significantly reduces the LLVM IR lines of the two structs, which should hopefully improve compile times a little bit (see commit messages for detailed numbers)./cc @weiznich
Related: