# Call FastClosures.jl \`@closure\` in Array Comprehensions?

**URL:** <https://discourse.julialang.org/t/call-fastclosures-jl-closure-in-array-comprehensions/93622>\
**Category:** Internals & Design\
**Tags:** performance, closure, corebox, comprehension\
**Created:** [January 27, 2023, 11:03am UTC](https://discourse.julialang.org/t/call-fastclosures-jl-closure-in-array-comprehensions/93622 "2023-01-27T11:03:34Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [February 3, 2023, 1:44am UTC](https://discourse.julialang.org/t/call-fastclosures-jl-closure-in-array-comprehensions/93622/3 "2023-02-03T01:44:42Z")

</div>

> [@nsajko](#):
>
> You possibly meant to put a comma here, instead of a semicolon (a semicolon is like a newline, which is syntactically significant for `let`). Doing that makes the timing match the other two timings.

No, this is intentional. The intent was to contrive a scenario where neophytes to Julia (and even seasoned veterans) could inadvertently cause boxing and poor performance where they didn’t expect to.

This is a better example, using more common patterns:

```julia
julia> function test1()
           x = if true; collect(1:1000) else collect(1:1000) end
           [x[i] for i in x]
       end;

julia> function test2()
           if true; x=collect(1:1000) else x=collect(1:1000) end
           [x[i] for i in x]
       end;

julia> @btime test1();
  725.197 ns (2 allocations: 15.88 KiB)

julia> @btime test2();
  23.600 μs (985 allocations: 31.27 KiB)

```

Even for people who’ve read [#15276](https://github.com/JuliaLang/julia/issues/15276), it might not be anticipated that a box would be formed here, because the fact that a comprehension creates a lambda is not obvious or necessary.

---

_[View the full topic](https://discourse.julialang.org/t/call-fastclosures-jl-closure-in-array-comprehensions/93622)._
