I would like to evaluate a scalar-function f: R \xrightarrow{} R as well as its derivative and hessian at around 200 values using ForwardDiff.jl
To speed-up the computations, is it possible to precompute an object like the graph of the function and apply it to the different values? From my understanding, it would be a waste of time to recompute the same thing multiple times.
An equivalent to what you’re talking about already happens automagically. ForwardDiff works by calling your code with a type (dual) that causes your code to also compute derivatives. As such your code will run with a new type, so compilation occurs to optimize your code.
The problem is that DiffResults.jl computes simultaneously f(x), \nabla f(x), H(f(x)) but solely for the same vector, not for repeated use of the same function f for different values.
Calculating at a different point requires everything to be recalculated. As @Oscar_Smith said, once you call ForwardDiff once, the code should have been compiled for your particular function, and the compiled version will be used for all the evaluations.