# Performance

**URL:** https://discourse.julialang.org/c/usage/perf/37.md?page=36

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

**Page:** 37

---

## [How to best parallelize matrix operations?](https://discourse.julialang.org/t/how-to-best-parallelize-matrix-operations/103895)

<div class="topic-metadata">

**Author:** [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)\
**Replies:** 1\
**Last updated:** [September 20, 2023, 3:57pm UTC](https://discourse.julialang.org/t/how-to-best-parallelize-matrix-operations/103895 "2023-09-20T15:57:28Z")

</div>

I need to do some operations on 3-dimensional matrices and would like to explore getting some speed ups with parallelization. I have a version working using map and @spawn as suggestetd here, and I get the right values, …

---

## [Very different performance on M1 mac, native vs rosetta](https://discourse.julialang.org/t/very-different-performance-on-m1-mac-native-vs-rosetta/66845)

<div class="topic-metadata">

**Author:** [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)\
**Replies:** 14\
**Last updated:** [September 20, 2023, 12:29pm UTC](https://discourse.julialang.org/t/very-different-performance-on-m1-mac-native-vs-rosetta/66845 "2023-09-20T12:29:00Z")

</div>

I was trying the argmin vs minimum benchark that was being discussed and found that the native arm julia is almost 5x slower than running in rosetta. Is the arm codegen that much worse or is that a bug with the M1 specif…

---

## [Avoiding intermediate vector allocations in matrix to scalar computations](https://discourse.julialang.org/t/avoiding-intermediate-vector-allocations-in-matrix-to-scalar-computations/104021)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 6\
**Last updated:** [September 20, 2023, 9:48am UTC](https://discourse.julialang.org/t/avoiding-intermediate-vector-allocations-in-matrix-to-scalar-computations/104021 "2023-09-20T09:48:16Z")

</div>

I recently noticed that the computation of a scalar from vector' \* matrix \* vector is allocating memory. This isn’t hugely surprising - the output of the first multiplication is a vector. However, the allocation can easi…

---

## [@debug has massive performance impact on Windows](https://discourse.julialang.org/t/debug-has-massive-performance-impact-on-windows/103974)

<div class="topic-metadata">

**Author:** [@ThummeTo](https://discourse.julialang.org/u/ThummeTo)\
**Replies:** 25\
**Last updated:** [September 19, 2023, 2:44pm UTC](https://discourse.julialang.org/t/debug-has-massive-performance-impact-on-windows/103974 "2023-09-19T14:44:33Z")

</div>

Hey guys, I found that the @debug macro has a massive performance impact on my code. I use the macro very often, because the documentation says: \[The macro\] will produce no output by default. Furthermore, it’s very ch…

---

## [Strange allocation in closure](https://discourse.julialang.org/t/strange-allocation-in-closure/104017)

<div class="topic-metadata">

**Author:** [@trahflow](https://discourse.julialang.org/u/trahflow)\
**Replies:** 3\
**Last updated:** [September 19, 2023, 2:41pm UTC](https://discourse.julialang.org/t/strange-allocation-in-closure/104017 "2023-09-19T14:41:18Z")

</div>

Hi, I observe an allocation involving a closure that I do not understand. Consider the following minimal working example: julia\> function outer(a) inner(b, c) = b, c a, inner end outer (ge…

---

## [Prevent huge number of allocations mutating columns of arrays](https://discourse.julialang.org/t/prevent-huge-number-of-allocations-mutating-columns-of-arrays/103848)

<div class="topic-metadata">

**Author:** [@Kieran\_Marray](https://discourse.julialang.org/u/Kieran_Marray)\
**Replies:** 15\
**Last updated:** [September 19, 2023, 1:48pm UTC](https://discourse.julialang.org/t/prevent-huge-number-of-allocations-mutating-columns-of-arrays/103848 "2023-09-19T13:48:24Z")

</div>

Hi, I am writing some code to update the columns in an array by repeatedly solving a linear system. I am trying to allocate arrays for the solutions, left-hand-side, and right-hand-side at the beginning of the code and t…

---

## [Pinv not Type Stable?](https://discourse.julialang.org/t/pinv-not-type-stable/103885)

<div class="topic-metadata">

**Author:** [@AlexanderNenninger](https://discourse.julialang.org/u/AlexanderNenninger)\
**Replies:** 15\
**Last updated:** [September 18, 2023, 2:01pm UTC](https://discourse.julialang.org/t/pinv-not-type-stable/103885 "2023-09-18T14:01:13Z")

</div>

Why is LinearAlgebra.pinv not type stable? Can it be implemented in a type stable way? Example (thanks to @albheim) using LinearAlgebra using JET function test(M) A = rand(M, M + 2) pinv(A) end test(10) repor…

---

## [Use 2d marker in Makie \`meshscatter\`](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978)

<div class="topic-metadata">

**Author:** [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Replies:** 16\
**Last updated:** [September 18, 2023, 1:59pm UTC](https://discourse.julialang.org/t/use-2d-marker-in-makie-meshscatter/103978 "2023-09-18T13:59:22Z")

</div>

Hello ! I’m trying to display a large set of 3D points (about 80k) with GLMakie. Initially, I used meshscatter, unfortunately my PC doesn’t have a discrete GPU so I’m trying to reduce the stress on the iGPU by using sc…

---

## [Performant reading of .tar.xz files](https://discourse.julialang.org/t/performant-reading-of-tar-xz-files/103912)

<div class="topic-metadata">

**Author:** [@trace\_forms](https://discourse.julialang.org/u/trace_forms)\
**Replies:** 15\
**Last updated:** [September 18, 2023, 1:55pm UTC](https://discourse.julialang.org/t/performant-reading-of-tar-xz-files/103912 "2023-09-18T13:55:45Z")

</div>

Hi there, I am trying to rapidly load data that is stored within .tar.xz files. Specifically, I am working with the genomic sequences and associated metadata for SARS-CoV-2 from GISAID. These come as separate .tar.xz fi…

---

## [Julia just... vanished in the middle of the night during a large task. Help troubleshooting/optimising would be appreciated](https://discourse.julialang.org/t/julia-just-vanished-in-the-middle-of-the-night-during-a-large-task-help-troubleshooting-optimising-would-be-appreciated/103834)

<div class="topic-metadata">

**Author:** [@MaxM](https://discourse.julialang.org/u/MaxM)\
**Replies:** 15\
**Last updated:** [September 14, 2023, 1:07pm UTC](https://discourse.julialang.org/t/julia-just-vanished-in-the-middle-of-the-night-during-a-large-task-help-troubleshooting-optimising-would-be-appreciated/103834 "2023-09-14T13:07:21Z")

</div>

I have quite a large task to run and in doing so I’ve encountered unfortunate issues. Below there are two blocks of code, one with a bunch of for loops (attempt 1), the other using functions (attempt 2). I’m running thes…

---

## [How to Make Tuple of Tuple generation Type Stable](https://discourse.julialang.org/t/how-to-make-tuple-of-tuple-generation-type-stable/103842)

<div class="topic-metadata">

**Author:** [@AlexanderNenninger](https://discourse.julialang.org/u/AlexanderNenninger)\
**Replies:** 1\
**Last updated:** [September 14, 2023, 10:33am UTC](https://discourse.julialang.org/t/how-to-make-tuple-of-tuple-generation-type-stable/103842 "2023-09-14T10:33:24Z")

</div>

I have code that needs to generate lists of indices. Cutting away all the fuzz, it boils down to using JET function foobar(K::Int, t::NTuple{N,T}) where {N,T} return \[t\[1:K\]\] end function foo(::Val{N}, k::Int) whe…

---

## [Reduce GC time](https://discourse.julialang.org/t/reduce-gc-time/103736)

<div class="topic-metadata">

**Author:** [@fdekerme](https://discourse.julialang.org/u/fdekerme)\
**Replies:** 7\
**Last updated:** [September 14, 2023, 10:28am UTC](https://discourse.julialang.org/t/reduce-gc-time/103736 "2023-09-14T10:28:23Z")

</div>

Hello :grin:, I tried to optimize my code to reduce GC time. Among other things, I tried to implement “in place” operations, in particular with a long GC function “is\_intersect!”, which checks whether a given interval i…

---

## [In-place assignment, without allocation](https://discourse.julialang.org/t/in-place-assignment-without-allocation/103811)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 8\
**Last updated:** [September 13, 2023, 1:17pm UTC](https://discourse.julialang.org/t/in-place-assignment-without-allocation/103811 "2023-09-13T13:17:45Z")

</div>

I’m trying to do y = x\[ind\] in-place, where y, x, ind are all vectors. By in-place, I mean no memory is allocated. I’m able to achieve this using a hand-written for loop (assign2! below). I suspect there is a way to achi…

---

## [Most performant way of updating vector values?](https://discourse.julialang.org/t/most-performant-way-of-updating-vector-values/103753)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 9\
**Last updated:** [September 13, 2023, 5:39am UTC](https://discourse.julialang.org/t/most-performant-way-of-updating-vector-values/103753 "2023-09-13T05:39:56Z")

</div>

Several times in my code, I will update the values of a vector. I want to avoid allocations and other stuff, and make it as performant as possible. At the beginning the vector is preallocated with n dummy values, and the…

---

## [Type instability for broadcast with abstract type](https://discourse.julialang.org/t/type-instability-for-broadcast-with-abstract-type/103727)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 4\
**Last updated:** [September 11, 2023, 7:20pm UTC](https://discourse.julialang.org/t/type-instability-for-broadcast-with-abstract-type/103727 "2023-09-11T19:20:04Z")

</div>

I have encountered a type instability when defining broadcasting for an abstract type. Consider the following (silly) example: import Base.Broadcast: Broadcasted, BroadcastStyle, broadcastable, broadcasted, instantiate …

---

## [Unrolling loops over tuples - why so hard?](https://discourse.julialang.org/t/unrolling-loops-over-tuples-why-so-hard/103428)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 14\
**Last updated:** [September 10, 2023, 10:58pm UTC](https://discourse.julialang.org/t/unrolling-loops-over-tuples-why-so-hard/103428 "2023-09-10T22:58:11Z")

</div>

Unrolling loops over tuple elements can bring easy performance gains. Here’s a trivial example of a 250x speed-up, just by adding an @unroll macro to the code: import Unroll.@unroll using BenchmarkTools function nounro…

---

## [Is splitting the Julia code into smaller scripts impacting performance?](https://discourse.julialang.org/t/is-splitting-the-julia-code-into-smaller-scripts-impacting-performance/103613)

<div class="topic-metadata">

**Author:** [@CrisCool](https://discourse.julialang.org/u/CrisCool)\
**Replies:** 5\
**Last updated:** [September 10, 2023, 9:13am UTC](https://discourse.julialang.org/t/is-splitting-the-julia-code-into-smaller-scripts-impacting-performance/103613 "2023-09-10T09:13:44Z")

</div>

Hei there julians! Let’s say I’m working on a Julia App and I organize my code in a MAIN.jl script and mayn other scripts, which I call from the MAIN.jl with include(). The structure can be nested, so the scripts include…

---

## [How to initialize an array of structs](https://discourse.julialang.org/t/how-to-initialize-an-array-of-structs/83674)

<div class="topic-metadata">

**Author:** [@fft](https://discourse.julialang.org/u/fft)\
**Replies:** 9\
**Last updated:** [September 9, 2023, 12:47pm UTC](https://discourse.julialang.org/t/how-to-initialize-an-array-of-structs/83674 "2023-09-09T12:47:01Z")

</div>

I want to create an array of structs like shown below mutable struct mystruct a::Float32 b::Float32 c::UInt32 end mystruct() = mystruct(0,0,0) size = 3 a = Array{mystruct, 3}(undef, size, size, size) fo…

---

## [Calculation of Hessian of a loss function w.r.t. dense layer weight matrices](https://discourse.julialang.org/t/calculation-of-hessian-of-a-loss-function-w-r-t-dense-layer-weight-matrices/103697)

<div class="topic-metadata">

**Author:** [@Harsh\_Choudhary](https://discourse.julialang.org/u/Harsh_Choudhary)\
**Replies:** 0\
**Last updated:** [September 9, 2023, 7:23am UTC](https://discourse.julialang.org/t/calculation-of-hessian-of-a-loss-function-w-r-t-dense-layer-weight-matrices/103697 "2023-09-09T07:23:51Z")

</div>

Hi, I am trying to train a dummy Neural Net which is given as: y = transpose(W1)sigmoid(W2x) where W1 and W2 are 10x1 and x is a scalar input. I am using second-order optimization and for that purpose, I need to calculat…

---

## [Type Instability when composing functor and function](https://discourse.julialang.org/t/type-instability-when-composing-functor-and-function/103680)

<div class="topic-metadata">

**Author:** [@elenev](https://discourse.julialang.org/u/elenev)\
**Replies:** 3\
**Last updated:** [September 8, 2023, 9:46pm UTC](https://discourse.julialang.org/t/type-instability-when-composing-functor-and-function/103680 "2023-09-08T21:46:33Z")

</div>

I am training a neural net using Flux.jl. I have a custom function that normalizes inputs before evaluating the model: function normalize(state) state\_min = \[-1.2f0, -0.07f0\] state\_max = \[0.6f0, 0.07f0\] norm…

---

## [When does concrete type inference not matter for performance?](https://discourse.julialang.org/t/when-does-concrete-type-inference-not-matter-for-performance/103603)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 6\
**Last updated:** [September 8, 2023, 12:05am UTC](https://discourse.julialang.org/t/when-does-concrete-type-inference-not-matter-for-performance/103603 "2023-09-08T00:05:44Z")

</div>

The docstring for code\_warntype states that Not all non-leaf types are particularly problematic for performance, and the performance characteristics of a particular type is an implementation detail of the compiler. cod…

---

## [Slow makie animations?](https://discourse.julialang.org/t/slow-makie-animations/103626)

<div class="topic-metadata">

**Author:** [@rkube](https://discourse.julialang.org/u/rkube)\
**Replies:** 9\
**Last updated:** [September 7, 2023, 7:27pm UTC](https://discourse.julialang.org/t/slow-makie-animations/103626 "2023-09-07T19:27:00Z")

</div>

Hi, I’m trying to animate some makie plots and performance seems to be a bit lacking. Animating this plot takes about 47 seconds on my machine 47.157643 seconds (30.39 M allocations: 3.480 GiB, 1.38% gc time, 3.92% co…

---

## [Alternative permutation/reducing for loops](https://discourse.julialang.org/t/alternative-permutation-reducing-for-loops/103554)

<div class="topic-metadata">

**Author:** [@Leticia-maria](https://discourse.julialang.org/u/Leticia-maria)\
**Replies:** 7\
**Last updated:** [September 7, 2023, 3:50pm UTC](https://discourse.julialang.org/t/alternative-permutation-reducing-for-loops/103554 "2023-09-07T15:50:07Z")

</div>

Hello, I am writing this function where I need to combine all terms in this structure (called Basis): struct GaussianBasisSet \<: AbstractBasisSet R α::Matrix{Float64} d::Matrix{Float64} ℓ::Int m::Int…

---

## [Understanding output of @time and @btime under cgroup CPUQuota constrains](https://discourse.julialang.org/t/understanding-output-of-time-and-btime-under-cgroup-cpuquota-constrains/103571)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 6\
**Last updated:** [September 7, 2023, 9:38am UTC](https://discourse.julialang.org/t/understanding-output-of-time-and-btime-under-cgroup-cpuquota-constrains/103571 "2023-09-07T09:38:09Z")

</div>

Hello, I was testing cgroup CPU/ Memory quota in a Ubuntu 22.04 system and realised that while @time reacts to changes I do in terms of CPUQuota (and indeed the whole system does slow down, meaning the limit is enforced)…

---

## [Fixing red bars at top of flame profile](https://discourse.julialang.org/t/fixing-red-bars-at-top-of-flame-profile/103316)

<div class="topic-metadata">

**Author:** [@ilanggear](https://discourse.julialang.org/u/ilanggear)\
**Replies:** 12\
**Last updated:** [September 6, 2023, 4:14pm UTC](https://discourse.julialang.org/t/fixing-red-bars-at-top-of-flame-profile/103316 "2023-09-06T16:14:41Z")

</div>

I’ve attached a screenshot of my flame profile. I’ve read that red bars near the top signal a problem with type instability. But I have specified the type of every struct member and the vast majority of my code relies …

---

## [Question about "in place" operations](https://discourse.julialang.org/t/question-about-in-place-operations/103573)

<div class="topic-metadata">

**Author:** [@fdekerme](https://discourse.julialang.org/u/fdekerme)\
**Replies:** 1\
**Last updated:** [September 6, 2023, 3:50pm UTC](https://discourse.julialang.org/t/question-about-in-place-operations/103573 "2023-09-06T15:50:16Z")

</div>

Hello, At the moment I’m studying a little bit of code optimisation. I don’t understand why in case with sample() we have 16 bytes allocated and in the second case 0 (with the in place operation “sample!()”). Isn’t it p…

---

## [Sparse matrix vector faster than dense matrix vector?](https://discourse.julialang.org/t/sparse-matrix-vector-faster-than-dense-matrix-vector/103446)

<div class="topic-metadata">

**Author:** [@dgleich](https://discourse.julialang.org/u/dgleich)\
**Replies:** 9\
**Last updated:** [September 5, 2023, 2:15pm UTC](https://discourse.julialang.org/t/sparse-matrix-vector-faster-than-dense-matrix-vector/103446 "2023-09-05T14:15:44Z")

</div>

As I was teaching sparse matrices in class, I was humbled by a theory-practice gap. The idea in theory: don’t use sparse matrices when you really have dense matrix. The idea in practice: here, let me show you in Julia! …

---

## [How to compute Hessian sub-blocks with autodiff?](https://discourse.julialang.org/t/how-to-compute-hessian-sub-blocks-with-autodiff/103494)

<div class="topic-metadata">

**Author:** [@biona001](https://discourse.julialang.org/u/biona001)\
**Replies:** 7\
**Last updated:** [September 4, 2023, 10:23pm UTC](https://discourse.julialang.org/t/how-to-compute-hessian-sub-blocks-with-autodiff/103494 "2023-09-04T22:23:51Z")

</div>

Hi community, I’m trying to use ForwardDiff.jl to compute a Hessian for a log likelihood function. Computing the full Hessian takes a long time, and I’m only interested in a sub-block of the Hessian anyway. Is there any…

---

## ["Compiling" DSL code to Reduce Indirection](https://discourse.julialang.org/t/compiling-dsl-code-to-reduce-indirection/103516)

<div class="topic-metadata">

**Author:** [@Ian\_L](https://discourse.julialang.org/u/Ian_L)\
**Replies:** 0\
**Last updated:** [September 4, 2023, 5:43pm UTC](https://discourse.julialang.org/t/compiling-dsl-code-to-reduce-indirection/103516 "2023-09-04T17:43:56Z")

</div>

Hello, In my quest to learn more about how to write DSLs in Julia, I’ve reach a point in the design and would like feedback and suggestions. For reference, the DSL is based of the SPPL language for symbolic exact infere…

---

## [Extreme memory usage in nested loop](https://discourse.julialang.org/t/extreme-memory-usage-in-nested-loop/103471)

<div class="topic-metadata">

**Author:** [@daviyan5](https://discourse.julialang.org/u/daviyan5)\
**Replies:** 8\
**Last updated:** [September 3, 2023, 1:05pm UTC](https://discourse.julialang.org/t/extreme-memory-usage-in-nested-loop/103471 "2023-09-03T13:05:41Z")

</div>

I need to conduct extensive memory and performance testing on a memory-intensive function that creates mutable structs, temporary arrays, and more, even though most of the variables are type-defined. Running a single ins…

[Previous page](https://discourse.julialang.org/c/usage/perf/37.md?page=35)

[Next page](https://discourse.julialang.org/c/usage/perf/37.md?page=37)
