3

The manual says:

Generated functions can achieve high efficiency at run time, but come with a compile time cost: a new function body must be generated for every combination of concrete argument types. Typically, Julia is able to compile "generic" versions of functions that will work for any arguments, but with generated functions this is impossible. This means that programs making heavy use of generated functions might be impossible to statically compile.
...
In this style of definition, the code generation feature is essentially an optional optimization. The compiler will use it if convenient, but otherwise may choose to use the normal implementation instead. This style is preferred, since it allows the compiler to make more decisions and compile programs in more ways, and since normal code is more readable than code-generating code

In practice I find that allowing it to use the non-generated version is trashing my performance. 50x slow down, and going from 0 allocations to nonzero.

Frames Catherine White
  • 27,368
  • 21
  • 87
  • 137
  • This seems like a performance bug report? – mbauman Jan 06 '20 at 18:39
  • @MattB. I thought I was just doing something wrong. the docs don't say when to use it and when not to. here is issue https://github.com/JuliaLang/julia/issues/34283 – Frames Catherine White Jan 06 '20 at 19:30
  • The goal is to have the compiler make that tradeoff choice "smartly" for you — and here it seems to be choosing wrongly, no? – mbauman Jan 06 '20 at 19:31
  • 1
    Right, the docs stop short of saying the compiler would be smart. It says the compiler will _"use it if convenient"_, and I personally at least do many dumn things if they are _convenient_ – Frames Catherine White Jan 06 '20 at 19:45

0 Answers0