At work we care about code size as well as run-time performance, and the most obvious knob for that is opt_level = "s". Cargo profile overrides allow us to get more fine-grained by compiling some specific packages one way or the other in a workspace, but that’s not very dependable when a particular crate might be broken out into several implementation dependencies—if not now, then maybe in their next release.
What I’d really like to say is “default to ‘size’ (s), but go back to ‘speed’ (3) for anything in (e.g.) aes’s dependency subtree”. It’s not going to be perfect, but it’s close enough for defining a library where only some parts are performance-sensitive.
Of course this scheme can have conflicts: one package can be under two explicitly-specified subtrees. One way to resolve this is for Cargo to require that subtree to then itself be specified explicitly to break the stalemate; this does mean some notion of domination would affect the resolved opt-level (or other profile setting I guess). Another would be to only allow one value for the override—e.g. I can override the opt-level for the dependencies of both aes and sha2, but I must override them to the same value (whether or not they overlap in practice).
Non-dependency-based overrides would take precedent over dependency-based ones, which would take precedence over the * override and build-override.
(I do remember that generics add another layer on top of all this, since the codegen will happen in the client crate rather than the library defining the generic API—as written up in the Overrides documentation in the Cargo book. I don’t think Cargo can do anything about that though.)
Thoughts? Would anybody else use this?