# How slow is runtime dispatch, anyway? Benchmark attempts

**URL:** <https://discourse.julialang.org/t/how-slow-is-runtime-dispatch-anyway-benchmark-attempts/124751>\
**Category:** Performance\
**Created:** [January 14, 2025, 3:07am UTC](https://discourse.julialang.org/t/how-slow-is-runtime-dispatch-anyway-benchmark-attempts/124751 "2025-01-14T03:07:12Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [January 14, 2025, 4:52am UTC](https://discourse.julialang.org/t/how-slow-is-runtime-dispatch-anyway-benchmark-attempts/124751/2 "2025-01-14T04:52:12Z")

</div>

While it’s interesting to see how much overhead dynamic method lookup and calling has in Julia, it’s only part of the reason dynamic dispatch is slower. Another important one that’s come up multiple times in practice is the overhead from boxing and unboxing arguments and return values that would otherwise be stack-allocated. [`hash(::Vector{\<abstract type\>}, ::UInt)` allocates quite a bit due to type instability: why can't hash(::Any) infer `UInt` return type? · Issue #44244 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/44244) and [[WIP] dynamic dispatch optimization: avoid boxing stack-allocated inputs by NHDaly · Pull Request #50136 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/50136) talk about this, and there should be related discussion threads on Discourse too.

Edit: this previous thread has similar benchmark and a comparison against Rust: [Curious about the internals of dynamic dispatch - #13 by HashBrown](https://discourse.julialang.org/t/curious-about-the-internals-of-dynamic-dispatch/102888/13)

Suffice it to say that a benchmark that captures the totality of runtime dispatch overhead should consider these other factors, regardless of whether the purpose is to compare against other languages.

---

_[View the full topic](https://discourse.julialang.org/t/how-slow-is-runtime-dispatch-anyway-benchmark-attempts/124751)._
