Skip to content
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

Use trait objects internally to avoid generic instantiation #60

Merged
merged 15 commits into from
Dec 7, 2023

Conversation

smklein
Copy link
Collaborator

@smklein smklein commented Dec 6, 2023

Keep the external interface to async transactions mostly unchanged, but delegate to internal functions that (as much as possible) avoid using generic functions.

This is intended to reduce code generation. For a debug build of omicron-nexus, this reduces the (debug build, Linux) binary size from 514 MiB to 497 MiB.

Source for idea: https://matklad.github.io/2021/09/04/fast-rust-builds.html#Keeping-Instantiations-In-Check

A... common case here are closures: by default, prefer &dyn Fn() over impl Fn(). Similarly to paths, an impl-based nice API might be a thin wrapper around dyn-based implementation which does the bulk of the work.

@smklein smklein changed the title Use trait objects internally to avoid generics Use trait objects internally to avoid generic instantiation Dec 6, 2023
Copy link

@steveklabnik steveklabnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to me. wild how much size this cuts off.

i sorta wish the compiler could do this transformation itself but ALSO compile times are long enough without adding more analysis passes, heh

@smklein smklein merged commit 3126feb into master Dec 7, 2023
4 checks passed
@smklein smklein deleted the reduce-generics branch December 7, 2023 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants