The do construction creates an anonymous function which is a closure, and you probably get hit by the infamous issue performance of captured variables in closures · Issue #15276 · JuliaLang/julia · GitHub.
1 Like