Calling a closure trait object works the same as calling any method on any trait object, as you can see here. You dereference the vtable pointer (at some offset) to get a pointer to the call function, and then execute an indirect call. This double indirection could be replaced with a single indirection, using an optimization similar to GHC’s “Tables next to code”. You replace the vtable pointer with a pointer directly to the call function, and then store the rest of the vtable (size, align, drop glue) immediately before it in .text.
Has this optimization been considered for Rust? Clearly it’s more important in GHC, where essentially everything you do is a call to a boxed closure. But Rust could benefit too, and it seems like a relatively straightforward change. It could apply to any trait object with a single method (ignoring
One issue is that this involves intermingling code and (read-only) data in .text, which may upset LLVM or some linkers. I think GHC added support to LLVM specifically for this use case.