1. 16
    1. 1

      This was really interesting. Thank you for doing it. :D

      Do Elixir typespecs get filtered down to Erlang as guards? I assumed they were documentation and useful to Dialyzer, but don’t create actual guards.

      I mention this because using is_float in Erlang can speed float operation up a lot since they can be kept in registers. Wings3D uses this extensively (example). However, graphmath doesn’t use guards at all, rather it uses typespecs.

      1. 1

        Wait, Wings3D is erlang? Wow :O

        1. 1

          Do Elixir typespecs get filtered down to Erlang as guards?

          I don’t think so, as far as I know typespecs are identical in both Erlang and Elixir and are both purely cosmetic to inform Dialyzer what is going on. I do know that people are continuing to optimize with guards, so it might be interesting to add type guards to graphmath and see how it goes. I’m reminded of someone talking about pldev saying something along the lines of “when you’re inside of a pattern match, types have already been checked”.

          Something else I wanted to try was enabling and disabling JIT to see how big a difference it makes, but it appears it’s only a build-time option, and I didn’t feel like jumping through the hoops to get this working with a version of Erlang that doesn’t include JIT at all, so.

          1. 1

            Do Elixir typespecs get filtered down to Erlang as guards? I assumed they were documentation and useful to Dialyzer, but don’t create actual guards.

            No they do not create guards. If you want guard you need to write it on your own. And yes, with OTP 25 and later if JIT compiler can guarantee that the type is always within given boundary it can generate more optimised code.

          2. 1

            Nx examples aren’t truly representative as from what I know it will transfer data between native code and binaries repeatedly. In most cases you build complex execution tree using defn and stuff, so the goal is to keep native representation of tensors as long as possible and not go back and forth between Elixir and execution engine (in case of EXLA or Torchx). So take these benchmarks with grain of salt.

          🇬🇧 The UK geoblock is lifted, hopefully permanently.