From 953d2936844ca09a800088996c0c09417c6aa1f9 Mon Sep 17 00:00:00 2001 From: Eekle <96976531+Eekle@users.noreply.github.com> Date: Sat, 27 Jan 2024 17:31:24 +0100 Subject: [PATCH] Mention generics in "optimizing dependencies" Mention generics in "optimizing dependencies" --- src/unsorted/speed-vs-size.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/unsorted/speed-vs-size.md b/src/unsorted/speed-vs-size.md index 6538d94b..4721c068 100644 --- a/src/unsorted/speed-vs-size.md +++ b/src/unsorted/speed-vs-size.md @@ -42,6 +42,12 @@ override the optimization level of dependencies. You can use that feature to optimize all dependencies for size while keeping the top crate unoptimized and debugger friendly. +Beware that generic code can sometimes be optimized alongside the crate where it +is instantiated, rather than the crate where it is defined. If you create an +instance of a generic struct in your application and find that it pulls in code +with a large footprint, it may be that increasing the optimisation level of the +relevant dependencies has no effect. + [`profile-overrides`]: https://doc.rust-lang.org/cargo/reference/profiles.html#overrides Here's an example: