# \#lazy-evaluation

**URL:** https://discourse.julialang.org/tag/lazy-evaluation/841.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Sum over LazyArray is slower than over regular array](https://discourse.julialang.org/t/sum-over-lazyarray-is-slower-than-over-regular-array/136989)

<div class="topic-metadata">

**Author:** [@jecs](https://discourse.julialang.org/u/jecs)\
**Replies:** 3\
**Last updated:** [May 5, 2026, 2:32pm UTC](https://discourse.julialang.org/t/sum-over-lazyarray-is-slower-than-over-regular-array/136989 "2026-05-05T14:32:56Z")

</div>

julia\> N = 64; A = randn(N,N); B = randn(N,N); C = similar(A,1,N); Using Lazy Arrays: julia\> @btime sum!($C,LazyArray(@~ $A.\*$B)) 3.047 μs (0 allocations: 0 bytes) Without LazyArrays: julia\> @btime sum!($C,$A.\*$B) …

---

## [Generic API for instantiating lazy values](https://discourse.julialang.org/t/generic-api-for-instantiating-lazy-values/128562)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 11\
**Last updated:** [May 2, 2025, 3:04pm UTC](https://discourse.julialang.org/t/generic-api-for-instantiating-lazy-values/128562 "2025-05-02T15:04:28Z")

</div>

Is there a generic API (ie a function) for requesting a deferred computation of some value? Eg if x is a Base.Generator, I want the array, etc. collect does too much, eg collect(SVector(1, 2, 3)) gives a Vector. Packa…

---

## [Hcat without copy and stack overflow in type inference](https://discourse.julialang.org/t/hcat-without-copy-and-stack-overflow-in-type-inference/101671)

<div class="topic-metadata">

**Author:** [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)\
**Replies:** 3\
**Last updated:** [July 16, 2023, 10:11am UTC](https://discourse.julialang.org/t/hcat-without-copy-and-stack-overflow-in-type-inference/101671 "2023-07-16T10:11:48Z")

</div>

When using packages like ArrayPartition in GitHub - SciML/RecursiveArrayTools.jl: Tools for easily handling objects like arrays of arrays and deeper nestings in scientific machine learning (SciML) and other applications …

---

## [Why are functions that are never called getting compiled?](https://discourse.julialang.org/t/why-are-functions-that-are-never-called-getting-compiled/100072)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 8\
**Last updated:** [June 10, 2023, 10:25pm UTC](https://discourse.julialang.org/t/why-are-functions-that-are-never-called-getting-compiled/100072 "2023-06-10T22:25:28Z")

</div>

Previously I asked about, and solved, a problem with compilation of a function inside generated code - the problem was that multiple instances of a function were getting compiled without being called. I would like to avo…

---

## [How to avoid compilation of an uncalled function](https://discourse.julialang.org/t/how-to-avoid-compilation-of-an-uncalled-function/100058)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 2\
**Last updated:** [June 8, 2023, 8:54pm UTC](https://discourse.julialang.org/t/how-to-avoid-compilation-of-an-uncalled-function/100058 "2023-06-08T20:54:55Z")

</div>

I have some code that generates a lot of function calls within different code branches. Each function call generates a different function instance. All these function instances are getting precompiled when my module is p…

---

## [Lazy broadcasting speed issues](https://discourse.julialang.org/t/lazy-broadcasting-speed-issues/94218)

<div class="topic-metadata">

**Author:** [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Replies:** 13\
**Last updated:** [March 12, 2023, 4:52pm UTC](https://discourse.julialang.org/t/lazy-broadcasting-speed-issues/94218 "2023-03-12T16:52:22Z")

</div>

I am working on a new package called SeparableFunctions.jl with the aim to boost the performance for functions which are expensive to calculate on multidimensional grids, but can profit a lot from broadcasting. To this…

---

## [How do I get readdlm to return a Matrix of strings?](https://discourse.julialang.org/t/how-do-i-get-readdlm-to-return-a-matrix-of-strings/85186)

<div class="topic-metadata">

**Author:** [@eyeHawk](https://discourse.julialang.org/u/eyeHawk)\
**Replies:** 12\
**Last updated:** [August 2, 2022, 10:43pm UTC](https://discourse.julialang.org/t/how-do-i-get-readdlm-to-return-a-matrix-of-strings/85186 "2022-08-02T22:43:12Z")

</div>

I am reading in a list of english words into my program. I then want to make sure the words are lowercase so I am processing the list with lowercase() one word at a time and pushing them into another list. It seems that …

---

## [Why do some functions not output the result directly?](https://discourse.julialang.org/t/why-do-some-functions-not-output-the-result-directly/80449)

<div class="topic-metadata">

**Author:** [@N-Accumbens](https://discourse.julialang.org/u/N-Accumbens)\
**Replies:** 23\
**Last updated:** [May 4, 2022, 9:24pm UTC](https://discourse.julialang.org/t/why-do-some-functions-not-output-the-result-directly/80449 "2022-05-04T21:24:25Z")

</div>

Hello, so for context I’m a R user. I’ve been trying to use this function using IterTools IterTools.product(collect(1:5), collect(1:5)) But I get this output. Base.Iterators.ProductIterator{Tuple{Vector{Int64}, Vecto…

---

## [Use of Lazy arrays](https://discourse.julialang.org/t/use-of-lazy-arrays/79779)

<div class="topic-metadata">

**Author:** [@Siempie](https://discourse.julialang.org/u/Siempie)\
**Replies:** 3\
**Last updated:** [April 21, 2022, 4:36pm UTC](https://discourse.julialang.org/t/use-of-lazy-arrays/79779 "2022-04-21T16:36:49Z")

</div>

Hi, I am looking into the use of lazy evaluation and lazy arrays in Julia. For example the package LazyArrays.jl. However i am not quite sure if i understand the benefits of lazy evaluation correctly. In my understandi…

---

## [Lazy.jl list overhead](https://discourse.julialang.org/t/lazy-jl-list-overhead/73958)

<div class="topic-metadata">

**Author:** [@jekyllstein](https://discourse.julialang.org/u/jekyllstein)\
**Replies:** 0\
**Last updated:** [January 3, 2022, 11:39am UTC](https://discourse.julialang.org/t/lazy-jl-list-overhead/73958 "2022-01-03T11:39:19Z")

</div>

I was experimenting with Lazy.jl and was wondering why there was significant overhead for accessing the first item of a list with a sufficiently complicated comprehension. function testlist(n) l = @lazy \[x^2 for x …

---

## [Transducer Filtering with Regex?](https://discourse.julialang.org/t/transducer-filtering-with-regex/52441)

<div class="topic-metadata">

**Author:** [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Replies:** 0\
**Last updated:** [December 27, 2020, 4:26am UTC](https://discourse.julialang.org/t/transducer-filtering-with-regex/52441 "2020-12-27T04:26:39Z")

</div>

Hi, I have several cases where I need just the first few elements that match a condition. With transducers, I can do something like big\_array |\> Filter(expensive\_filter) |\> Map(expensive\_transformation) |\> Take(5) |\> c…

---

## [Lazy or efficient representation of \`repeat\` function on Arrays?](https://discourse.julialang.org/t/lazy-or-efficient-representation-of-repeat-function-on-arrays/73356)

<div class="topic-metadata">

**Author:** [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Replies:** 0\
**Last updated:** [December 20, 2021, 4:32am UTC](https://discourse.julialang.org/t/lazy-or-efficient-representation-of-repeat-function-on-arrays/73356 "2021-12-20T04:32:56Z")

</div>

what is the best( lazy ? ) way to represent repeat function (other than doing following) the following julia\> @btime A = repeat(\[1 2\],3,1) 116.760 ns (2 allocations: 192 bytes) 3×2 Matrix{Int64}: 1 2 1 2 1 2 i…

---

## [Lazy logspace object](https://discourse.julialang.org/t/lazy-logspace-object/70091)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 3\
**Last updated:** [October 20, 2021, 7:40pm UTC](https://discourse.julialang.org/t/lazy-logspace-object/70091 "2021-10-20T19:40:03Z")

</div>

We still miss a lazy version as a range. The broadcast solution above is greedy and breaks code that expects range objects.

---

## [Datastructure for lazy evalulation](https://discourse.julialang.org/t/datastructure-for-lazy-evalulation/48972)

<div class="topic-metadata">

**Author:** [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Replies:** 0\
**Last updated:** [October 25, 2020, 10:11am UTC](https://discourse.julialang.org/t/datastructure-for-lazy-evalulation/48972 "2020-10-25T10:11:28Z")

</div>

I’m working on some visualization things and i think i need a datastructure to capture relations between ‘objects’ or ‘data’ so that i can track down the minimum set of updates. So like A depends on B and C and if C or …

---

## [How lazy is too lazy? An exercise in pseudoinverses](https://discourse.julialang.org/t/how-lazy-is-too-lazy-an-exercise-in-pseudoinverses/67020)

<div class="topic-metadata">

**Author:** [@artkuo](https://discourse.julialang.org/u/artkuo)\
**Replies:** 4\
**Last updated:** [August 27, 2021, 11:16pm UTC](https://discourse.julialang.org/t/how-lazy-is-too-lazy-an-exercise-in-pseudoinverses/67020 "2021-08-27T23:16:07Z")

</div>

Inspired by this discussion, I worked up a self-education project to let a naive user type inv(A'A)A'b expecting to do a pseudoinverse by hand. But the package lazily avoids doing any inversion or matrix multiplication, …

---

## [Transforming arbitrary Julia code to lazy evaluation](https://discourse.julialang.org/t/transforming-arbitrary-julia-code-to-lazy-evaluation/66239)

<div class="topic-metadata">

**Author:** [@tbenst](https://discourse.julialang.org/u/tbenst)\
**Replies:** 4\
**Last updated:** [August 12, 2021, 3:51am UTC](https://discourse.julialang.org/t/transforming-arbitrary-julia-code-to-lazy-evaluation/66239 "2021-08-12T03:51:01Z")

</div>

I’ve been experimenting with methods for transforming arbitrary Julia code for lazy evaluation (repo at https://github.com/tbenst/Thunks.jl). Here’s an example of what I’d like to be able to do in a fraction of a second: …

---

## [Package for lazy concatenation along arbitrary higher dimensions?](https://discourse.julialang.org/t/package-for-lazy-concatenation-along-arbitrary-higher-dimensions/55413)

<div class="topic-metadata">

**Author:** [@tlnagy](https://discourse.julialang.org/u/tlnagy)\
**Replies:** 4\
**Last updated:** [February 17, 2021, 7:17am UTC](https://discourse.julialang.org/t/package-for-lazy-concatenation-along-arbitrary-higher-dimensions/55413 "2021-02-17T07:17:57Z")

</div>

Are there any packages that let you concatenate lazily along arbitrary dimensions like the eager cat does? julia\> mats = \[rand(5,6,7,8), rand(5,6,7,8)\]; julia\> combo = cat(mats..., dims=3); # this, but lazy julia\> siz…

---

## [Question on lazy map function](https://discourse.julialang.org/t/question-on-lazy-map-function/53450)

<div class="topic-metadata">

**Author:** [@asyrov](https://discourse.julialang.org/u/asyrov)\
**Replies:** 10\
**Last updated:** [January 17, 2021, 1:50am UTC](https://discourse.julialang.org/t/question-on-lazy-map-function/53450 "2021-01-17T01:50:50Z")

</div>

Can anyone please point me to overview of using (maybe different kinds) of map/reduce/filter functions in Julia (and it’s standard packages)? Here is is what I’m missing now: I want any(map(x -\> x \> 0, big\_rand\_array)) …

---

## [How to read files from a compressed file (zip/gz) lazily?](https://discourse.julialang.org/t/how-to-read-files-from-a-compressed-file-zip-gz-lazily/53314)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 3\
**Last updated:** [January 14, 2021, 6:09pm UTC](https://discourse.julialang.org/t/how-to-read-files-from-a-compressed-file-zip-gz-lazily/53314 "2021-01-14T18:09:53Z")

</div>

I know how to use TranscodingStreams to read one file without fully decompress it first, what if the target.tar.gz contains multiple directories/files?

---

## [Not understanding iterators and lazy evaluation](https://discourse.julialang.org/t/not-understanding-iterators-and-lazy-evaluation/48322)

<div class="topic-metadata">

**Author:** [@lewis](https://discourse.julialang.org/u/lewis)\
**Replies:** 11\
**Last updated:** [October 14, 2020, 6:23pm UTC](https://discourse.julialang.org/t/not-understanding-iterators-and-lazy-evaluation/48322 "2020-10-14T18:23:13Z")

</div>

Let’s say I have a big array: big = rand(1:4, 8\_000\_000) I have a loop that will run 180 times and filter big and do something with the results. Each time I filter big, the result vector will be a different size (trivi…

---

## [Should \`inv\` be lazy?](https://discourse.julialang.org/t/should-inv-be-lazy/42786)

<div class="topic-metadata">

**Author:** [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Replies:** 24\
**Last updated:** [July 23, 2020, 6:55am UTC](https://discourse.julialang.org/t/should-inv-be-lazy/42786 "2020-07-23T06:55:12Z")

</div>

I was thinking about how inv is almost always the wrong thing to use in code, and how this primarily trips up people without significant linear algebra experience, and I realized that I think the following will be almos…

---

## [Lazy countmap](https://discourse.julialang.org/t/lazy-countmap/35220)

<div class="topic-metadata">

**Author:** [@harven](https://discourse.julialang.org/u/harven)\
**Replies:** 3\
**Last updated:** [February 27, 2020, 3:27pm UTC](https://discourse.julialang.org/t/lazy-countmap/35220 "2020-02-27T15:27:27Z")

</div>

I am triaging elements in a list according to their values by some function f and compute the number of elements for each possible value as follows. countmap(map(f, list)) This returns a dict whose keys are unique va…

---

## [Lazy and eager API design](https://discourse.julialang.org/t/lazy-and-eager-api-design/22398)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 6\
**Last updated:** [October 10, 2019, 5:27am UTC](https://discourse.julialang.org/t/lazy-and-eager-api-design/22398 "2019-10-10T05:27:45Z")

</div>

This is a somewhat general API interface design question and I am still wondering about the idiomatic “Julian” way of formulating it, so I thought I would ask here. Suppose I have a vocabulary of verbs f, g, h, which op…

---

## [Is there a lazy sparse matrix constructor?](https://discourse.julialang.org/t/is-there-a-lazy-sparse-matrix-constructor/21422)

<div class="topic-metadata">

**Author:** [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Replies:** 3\
**Last updated:** [March 3, 2019, 9:54pm UTC](https://discourse.julialang.org/t/is-there-a-lazy-sparse-matrix-constructor/21422 "2019-03-03T21:54:48Z")

</div>

Constructing a sparse matrix via the following is slow: n = 200 m = 250 A = spzeros(n,m) for i in 1:n for j in 1:m A\[i,j\] = rand() end end The way to speed this up is to use the following syntax: cur\_I = Int…

---

## [How to lazily \`collect(zip(fn(a), b))\` for some function \`fn\`?](https://discourse.julialang.org/t/how-to-lazily-collect-zip-fn-a-b-for-some-function-fn/9244)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 2\
**Last updated:** [February 22, 2018, 10:51am UTC](https://discourse.julialang.org/t/how-to-lazily-collect-zip-fn-a-b-for-some-function-fn/9244 "2018-02-22T10:51:36Z")

</div>

I want to lazily collect a zip iterator. See MWE below where I applied pointer. to a before using a zip and collect, but pointer.(a) allocated a new vector, so I don’t want that. Is there a way to lazily do pointer.(a) s…

---

## [Lazy evaluation on a large scale, is it the right thing to do?](https://discourse.julialang.org/t/lazy-evaluation-on-a-large-scale-is-it-the-right-thing-to-do/4815)

<div class="topic-metadata">

**Author:** [@louisponet](https://discourse.julialang.org/u/louisponet)\
**Replies:** 2\
**Last updated:** [July 13, 2017, 11:46am UTC](https://discourse.julialang.org/t/lazy-evaluation-on-a-large-scale-is-it-the-right-thing-to-do/4815 "2017-07-13T11:46:59Z")

</div>

First a quick description of my usecase: I have an array of 81x81x81 complex values which represent a wavefunction in real space. I have 200 values of vector k, for which I need to calculate various things using these 8…
