# Trig functions very slow

**URL:** <https://discourse.julialang.org/t/trig-functions-very-slow/15335>\
**Category:** Performance\
**Created:** [September 22, 2018, 10:58am UTC](https://discourse.julialang.org/t/trig-functions-very-slow/15335 "2018-09-22T10:58:02Z")\
**Posts on this page:** 1\
**Showing post:** 41

<div class="post-metadata">

**Author:** ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)\
**Post date:** [September 24, 2018, 10:32pm UTC](https://discourse.julialang.org/t/trig-functions-very-slow/15335/41 "2018-09-24T22:32:55Z")

</div>

There are a couple of things we should do:

1. _Write faster scalar functions_. We use translated versions of openlibm (which were based on FreeBSD’s libm, which in turn descend from fdlibm written by Sun in the 90s). These give respectable performance, but there is some room for improvement (e.g. by exploiting `fma` instructions on newer architectures).

2. _Provide hooks to use vectorised kernels_, such as SVML, SLEEF, Yeppp or Apple’s Accelerate library, for operations like `broadcast` and `reduce`. LLVM provides such hooks for its own intrinsics: we don’t currently use these because they are hard coded to call the system math library, not our own scalar functions. Apparently [this is fixable](https://github.com/JuliaLang/julia/issues/21454#issuecomment-295822718), but the best option would be to have a general framework to do this for arbitrary functions, not just the those blessed by LLVM.

3. _A framework to write our own vectorised kernels_. [SIMD.jl](https://github.com/eschnett/SIMD.jl) provides some low-level functionality, but ideally we would have a higher-level way to write SPMD code like [ISPC](https://ispc.github.io/), which would do things like rewrite branches into bitmasks.

Unfortunately the discussion of this issue has become somewhat fragmented, but the main issues are:

- [https://github.com/JuliaLang/julia/issues/8869](https://github.com/JuliaLang/julia/issues/8869)
- [https://github.com/JuliaLang/julia/issues/15265](https://github.com/JuliaLang/julia/issues/15265)
- [https://github.com/JuliaLang/julia/issues/21454](https://github.com/JuliaLang/julia/issues/21454)

---

_[View the full topic](https://discourse.julialang.org/t/trig-functions-very-slow/15335)._
