Apologies for not responding directly to your question, but…
I started refactoring some of the innards of core::fmt…
I’m curious about this, as I have an heavily optimized version of core::fmt that I’ve been meaning to post about at some point.
Briefly: My approach was to move as much information as possible into an ArgumentsSpec structure, including the address of the type-specific fmt function. A generated ArgumentsSpec can’t be specified as a static or const item because its value depends on local types, but the compiler allocates it statically anyway. My other change was to specify formatting parameters using a FormattedArg wrapper, so that fmt::write's run-time work becomes trivial. There are extensive changes in libsyntax. It works and passes tests, although it’s currently limited to 32 parameters. I don’t have precise measurements, but it makes various rustc crates 1-3% smaller or so.
My strawman is that the underlying flags should be expressed as an explicit bitmap, but not exposed to the users, instead a series of getters and setters would exposed on Formatter.
Part of my optimization relies on Formatter being immutable, though. As long as it can’t be changed, then Formatter can use an optional reference to the format parameters, which in the default, typical case, is a single pointer initialized to NULL. I changed Pointer to generate a new Formatter wrapping the previous one.
(Correction: Pointer's new Formatter doesn’t wrap the previous Formatter. Rather, it borrows the existing Formatter's Write trait object and copies the previous formatter parameters, if any exist.)