# Why Are Languages Like Python and MATLAB So Much Slower than Julia?

**URL:** <https://discourse.julialang.org/t/why-are-languages-like-python-and-matlab-so-much-slower-than-julia/51381>\
**Category:** Internals & Design\
**Tags:** question, first-steps, performance\
**Created:** [December 7, 2020, 7:33am UTC](https://discourse.julialang.org/t/why-are-languages-like-python-and-matlab-so-much-slower-than-julia/51381 "2020-12-07T07:33:23Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [December 7, 2020, 4:55pm UTC](https://discourse.julialang.org/t/why-are-languages-like-python-and-matlab-so-much-slower-than-julia/51381/9 "2020-12-07T16:55:25Z")

</div>

The simplest answer is that, naively, higher level dynamic languages need to ask meta-questions about _everything_ in order to figure out what to do. That is, given a function like:

```julia
function mysum(array)
    r = zero(eltype(array))
    for elt in array
        r += elt
    end
    return r
end

```

A traditional high-level language _doesn’t know_ what `elt` will be — and it might not always be the same thing. So in every single iteration the language needs to ask:

- what type is `elt`?
- what type is `r`?
- what method of `+` should I call to sum them together?

Those meta questions take real CPU operations and time to answer. It’s time that _you’re not spent doing your algorithm_ and they get in the way of very powerful multiplicative performance gains from SIMD. Now the interesting thing is that since Julia _is_ a dynamic language, you can actually get dynamic-language-like performance quite easily! In the example above, you just need to use `Any[]` arrays. Or `@nospecialize` macros. Or disregarding all the points in the [performance tips chapter](https://docs.julialang.org/en/v1/manual/performance-tips/).

Traditional JITs can work around the problem by tracing the execution, noticing that `elt` is almost always a `Float64`, compiling a specialized version of that code segment, and swapping over to it… but you still need an escape hatch if something crazy changes (like if someone `eval`s something into your local scope).

Julia’s JIT is more akin to a just-barely-ahead-of-time compiler, (almost) always specializing on the arguments it got to try to ensure that the generated machine code can avoid those meta-questions… and from the get-go Julia disabled some dynamic language features (like `eval` in local scope) to ensure that’ll be possible more frequently.

---

_[View the full topic](https://discourse.julialang.org/t/why-are-languages-like-python-and-matlab-so-much-slower-than-julia/51381)._
