4 ms·
The author is right about inlining but has picked the wrong example to show this since the compiler cannot inline across await. If this function is in the hot
by stevenhuang 7mo ago
The author is right about inlining but has picked the wrong example to show this since the compiler cannot inline across await.
If this function is in the hot path the last thing you'll want to do is to needlessly call await. You'll enter a suspension point and your task can get migrated to another thread. It is in no way comparable to the dead simple inlining example given later.
This is why you should always benchmark before making guesses, and to double check you're even benchmarking the right thing. In this case they used the findings from a nonasync benchmark and applied it to async. This will lead you to a very wrong conclusion, and performance issues.
- modulared 7mo ago> since the compiler cannot inline across await. Is this stated somewhere? A simple search online yields nothing, and just testing it out on godbolt the compiler does inline at least simple async functions as mentioned in the article.
- stevenhuang 7mo agoYeah I suppose it may be inlined if it's a trivial async function (no suspension points).