Lambda functions don’t have pretty names. That’s merely an annoyance when debugging a crash. But when profiling, it’s a serious handicap. And when profiling futures-driven code, it’s crippling. I’m trying to profile a Tokio-based application, but almost every single frame of every single stack has a generic name like
_<futures::future::and_then::AndThen<A, B, F> as futures::future::Future>::poll::h8e23f80c3f62ba61. The flame graph is completely incomprehensible. Using
RUSTFLAGS="-C debuginfo=2 -C inline-threshold=0 doesn’t help.
AFAICT, the root cause seems to be that methods like
Future::and_then<F, B>(self, f: F) are generic in the
f argument. And since the
f argument is usually a lambda function, that means that
Future::and_then gets monomorphized every place that it’s called. And since
f has only one caller, it gets inlined. And since
f's caller is technically in the
futures crate, its stack frames get those useless names.
Has anybody found a solution to this problem? I feel like it’s the real Achilles’ heel of futures programming.