# Improving speed of runtime dispatch detector

**URL:** <https://discourse.julialang.org/t/improving-speed-of-runtime-dispatch-detector/114697>\
**Category:** Performance\
**Tags:** question\
**Created:** [May 24, 2024, 6:45pm UTC](https://discourse.julialang.org/t/improving-speed-of-runtime-dispatch-detector/114697 "2024-05-24T18:45:59Z")\
**Posts on this page:** 1\
**Showing post:** 22

<div class="post-metadata">

**Author:** ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Post date:** [May 25, 2024, 5:45pm UTC](https://discourse.julialang.org/t/improving-speed-of-runtime-dispatch-detector/114697/22 "2024-05-25T17:45:34Z")

</div>

Okay all is good, I fixed it [here](https://github.com/MilesCranmer/DispatchDoctor.jl/pull/3) by moving back to the closure approach:

```julia
function _stable(fex::Expr)
    func = splitdef(fex)

    ...
    @gensym closure T
    func[:body] = quote
        let $closure() = $(func[:body]), $T = $(Base).promote_op($closure)
            if !$(Base).isconcretetype($T)
                ...
            end

            return $closure()::$T
        end
    end

    return combinedef(func)
end

```

It seems like `promote_op` gets the same results if you put all the function body in a closure. And, as before, the check looks to compile away if everything is type-stable.

---

_[View the full topic](https://discourse.julialang.org/t/improving-speed-of-runtime-dispatch-detector/114697)._
