I am unsure whether this makes sense to report as a bug, but I have a multi-crate project where I am passing a function pointer from one crate to another. I want to allow that function to mutate data that the crate I am passing the function to, does not know about. I also want to be able to change the crate passing out the function pointer without recompiling the crate that is receiving it.
I had a working version using
static mut, which was definitely not thread-safe, and for all I know was unsafe in other ways as well. So as part of figuring out the best way to improve that situation, I tried using a
move closure instead. This obviously required changing the type from
fn() to some form of
FnMut. This change increased the compile time of the project from around 4 seconds to around 15 seconds, even though the receiving crate was not reported as being recompiled. I have a vague understandly that
FnMut involves an additional layer of indirection if it cannot be inlined, (I’m thinking it’s a struct containing a pointer to the function and all it’s closed over state,) but I still found this surprising.
There are many of the relevant details in this SO question I asked about avoid using static mut but I’m wondering, since my project is open source, if it would be useful to make a git branch and tag some commits or something so others can replicate this.