Compile the inner fct in scan only once per instance.
Merge pull request #1631 from nouiz/scan

Compile the inner fct in scan only once per instance.