# Performance

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

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

**Page:** 29

---

## [Storing comparisons](https://discourse.julialang.org/t/storing-comparisons/110513)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 1\
**Last updated:** [February 21, 2024, 1:58pm UTC](https://discourse.julialang.org/t/storing-comparisons/110513 "2024-02-21T13:58:54Z")

</div>

I have a program which computes a number, stores it and uses it for many times. Then it proceeds to the next iteration (it’s a loop), generates another number, stores it and uses it as well for many times. Considering …

---

## [How come a struct is type unstable, if too many different field types?](https://discourse.julialang.org/t/how-come-a-struct-is-type-unstable-if-too-many-different-field-types/110447)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 2\
**Last updated:** [February 21, 2024, 12:38am UTC](https://discourse.julialang.org/t/how-come-a-struct-is-type-unstable-if-too-many-different-field-types/110447 "2024-02-21T00:38:27Z")

</div>

Hello! The real code is a bit of a mess, so just giving an example and looking for a hint. I have defined a struct as: @with\_kw struct CLL{I,T,D} Points::Vector{SVector{D,T}} MaxValidIndex::Base.RefValue{Int} =…

---

## [List of matrices](https://discourse.julialang.org/t/list-of-matrices/110456)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 6\
**Last updated:** [February 21, 2024, 7:33am UTC](https://discourse.julialang.org/t/list-of-matrices/110456 "2024-02-21T07:33:14Z")

</div>

Is there something better than this, to hold matrices? (not that i complain, just curious) C = Vector{AbstractMatrix{Float64}}(undef, 2) for i = 1:2 A = rand(Float64, i\*2, i\*2) display(A) C\[i\] = A end displa…

---

## [Mul! vs \* benchmarks](https://discourse.julialang.org/t/mul-vs-benchmarks/110448)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 2\
**Last updated:** [February 20, 2024, 4:41pm UTC](https://discourse.julialang.org/t/mul-vs-benchmarks/110448 "2024-02-20T16:41:23Z")

</div>

I have these 4 examles I’m benchmarking: using SparseArrays using LinearAlgebra using BenchmarkTools using Random function myfun1(m::Integer, n::Integer) Random.seed!(1) A = rand(Float64, n, n) B = sparse(r…

---

## [The speed of inter-process communication via RemoteChannels](https://discourse.julialang.org/t/the-speed-of-inter-process-communication-via-remotechannels/110424)

<div class="topic-metadata">

**Author:** [@sumiya11](https://discourse.julialang.org/u/sumiya11)\
**Replies:** 4\
**Last updated:** [February 20, 2024, 7:18pm UTC](https://discourse.julialang.org/t/the-speed-of-inter-process-communication-via-remotechannels/110424 "2024-02-20T19:18:30Z")

</div>

I wish to roughly measure the latency and throughput of process communication in Julia, to decide how to use multi-processing in my implementation. In the following script, I compare main and main\_with\_channels: using …

---

## [GLMakie - Polar heatmap/ millions of Polygons(?)](https://discourse.julialang.org/t/glmakie-polar-heatmap-millions-of-polygons/98470)

<div class="topic-metadata">

**Author:** [@Ertyk](https://discourse.julialang.org/u/Ertyk)\
**Replies:** 1\
**Last updated:** [February 20, 2024, 10:37am UTC](https://discourse.julialang.org/t/glmakie-polar-heatmap-millions-of-polygons/98470 "2024-02-20T10:37:20Z")

</div>

Hello, I am trying to plot (a lot of) data in a live “polar heatmap”. A triangular visualization like below is ok. For now I have used polygons by modifying this example: https://docs.makie.org/stable/examples/plott…

---

## [Why does indexing into CartesianIndices lead to excessive runtime dispatch?](https://discourse.julialang.org/t/why-does-indexing-into-cartesianindices-lead-to-excessive-runtime-dispatch/110438)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 9\
**Last updated:** [February 20, 2024, 8:17am UTC](https://discourse.julialang.org/t/why-does-indexing-into-cartesianindices-lead-to-excessive-runtime-dispatch/110438 "2024-02-20T08:17:31Z")

</div>

This just looks so weird to me. The code is really simply: function neighbors(d::Int) n\_ = CartesianIndices((fill(-1:1, d)...,)) n = n\_\[begin:end//2\] #This line runtime errors end using JET @report\_opt neigh…

---

## [Constructing Q matrix from QR decomposition](https://discourse.julialang.org/t/constructing-q-matrix-from-qr-decomposition/110383)

<div class="topic-metadata">

**Author:** [@Endeavour](https://discourse.julialang.org/u/Endeavour)\
**Replies:** 3\
**Last updated:** [February 19, 2024, 10:20am UTC](https://discourse.julialang.org/t/constructing-q-matrix-from-qr-decomposition/110383 "2024-02-19T10:20:23Z")

</div>

Hi! I am working with some large complex float matrices ( that may go up to 16000x16000). I need to do a QR decomposition of a rectangular matrix. I require the Q matrix to be square. It seems like that extracting the Q…

---

## [Static Array times scalar](https://discourse.julialang.org/t/static-array-times-scalar/110401)

<div class="topic-metadata">

**Author:** [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Replies:** 2\
**Last updated:** [February 19, 2024, 2:11pm UTC](https://discourse.julialang.org/t/static-array-times-scalar/110401 "2024-02-19T14:11:33Z")

</div>

How to multiply a static array with a scalar with allocating memory ? I tried Aloc = SVector{36}(SVector(Bloc)./Scalar(area) and variants without succes. Thx!

---

## [How to write a multi-threaded reduction using Bumper.jl?](https://discourse.julialang.org/t/how-to-write-a-multi-threaded-reduction-using-bumper-jl/110314)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 10\
**Last updated:** [February 18, 2024, 12:52pm UTC](https://discourse.julialang.org/t/how-to-write-a-multi-threaded-reduction-using-bumper-jl/110314 "2024-02-18T12:52:10Z")

</div>

Hello! I am trying to see if I can get a multithreaded reduction to work using Bumper.jl but my results are a bit embaressing… I can’t seem to get it to work and I don’t think it is using all my threads… The code snippe…

---

## [Checking if a list of vectors are all identical](https://discourse.julialang.org/t/checking-if-a-list-of-vectors-are-all-identical/110215)

<div class="topic-metadata">

**Author:** [@Gus\_Hart](https://discourse.julialang.org/u/Gus_Hart)\
**Replies:** 23\
**Last updated:** [February 15, 2024, 10:35pm UTC](https://discourse.julialang.org/t/checking-if-a-list-of-vectors-are-all-identical/110215 "2024-02-15T22:35:06Z")

</div>

(Looking for the most idiomatic way to solve this problem. It’s inside several nested loops.) I have a situation where I have two lists of 3-vectors. Often these two lists are identical except for displacement. (One set…

---

## [Best practices for single script files](https://discourse.julialang.org/t/best-practices-for-single-script-files/110258)

<div class="topic-metadata">

**Author:** [@Ved\_Mahajan](https://discourse.julialang.org/u/Ved_Mahajan)\
**Replies:** 9\
**Last updated:** [February 17, 2024, 4:38pm UTC](https://discourse.julialang.org/t/best-practices-for-single-script-files/110258 "2024-02-17T16:38:49Z")

</div>

Hey all :wave: In the future I see myself writing a lot of single script files. They will be, almost exclusively, for analysing my molecular dynamics simulations. I imagine a rough skeleton of the script to be: define …

---

## [Performance of \`Meta.parse\` and \`eval\`](https://discourse.julialang.org/t/performance-of-meta-parse-and-eval/52061)

<div class="topic-metadata">

**Author:** [@brucala](https://discourse.julialang.org/u/brucala)\
**Replies:** 11\
**Last updated:** [December 30, 2020, 6:39pm UTC](https://discourse.julialang.org/t/performance-of-meta-parse-and-eval/52061 "2020-12-30T18:39:10Z")

</div>

Hi all, I’m a relatively new and now enthusiastic Julia user. While exploring the metaprogramming capabilities I came to the question of this topic. Probably I am missing something or misinterpreting the use intention f…

---

## [How to correctly unroll loop in LoopVectorization?](https://discourse.julialang.org/t/how-to-correctly-unroll-loop-in-loopvectorization/110229)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 12\
**Last updated:** [February 15, 2024, 8:47pm UTC](https://discourse.julialang.org/t/how-to-correctly-unroll-loop-in-loopvectorization/110229 "2024-02-15T20:47:01Z")

</div>

Hello! I have made a toy script here, SummaryToy script example using StaticArrays using LoopVectorization using StructArrays using BenchmarkTools struct DimensionalData{D, T} vectors::Tuple{Vararg{Vector{T}, D}}…

---

## [Function definition inside let-block impacting performance?](https://discourse.julialang.org/t/function-definition-inside-let-block-impacting-performance/110007)

<div class="topic-metadata">

**Author:** [@JuhaHeiskala](https://discourse.julialang.org/u/JuhaHeiskala)\
**Replies:** 42\
**Last updated:** [February 14, 2024, 10:18pm UTC](https://discourse.julialang.org/t/function-definition-inside-let-block-impacting-performance/110007 "2024-02-14T22:18:36Z")

</div>

Is there some reason why a function defined inside a let-block is slower compared to defining the same function in global scope? e.g. below recursive Fibonacci (from the old Julia microbenchmarks) is 10 times slower if …

---

## [Multi-threaded code requiring scratch space](https://discourse.julialang.org/t/multi-threaded-code-requiring-scratch-space/109997)

<div class="topic-metadata">

**Author:** [@PGS62](https://discourse.julialang.org/u/PGS62)\
**Replies:** 17\
**Last updated:** [February 14, 2024, 12:40pm UTC](https://discourse.julialang.org/t/multi-threaded-code-requiring-scratch-space/109997 "2024-02-14T12:40:37Z")

</div>

I think it’s true that to get decent performance from multi-threaded code, it’s a good idea to minimise the amount of allocation done by each task. One way to do this can be calling functions that accept a “scratch” argu…

---

## [Struct with field types defined by parametric type](https://discourse.julialang.org/t/struct-with-field-types-defined-by-parametric-type/110117)

<div class="topic-metadata">

**Author:** [@mattsignorelli](https://discourse.julialang.org/u/mattsignorelli)\
**Replies:** 5\
**Last updated:** [February 13, 2024, 8:48am UTC](https://discourse.julialang.org/t/struct-with-field-types-defined-by-parametric-type/110117 "2024-02-13T08:48:53Z")

</div>

Say I have a struct MyStruct such that struct A ... end struct B ... end struct MyStruct{T \<: Union{A, B}} t::T v::Vector end I want v to be of type Vector{Float64} if T == A, else if T == B then v should be of t…

---

## [Make functions in the present model available to workers](https://discourse.julialang.org/t/make-functions-in-the-present-model-available-to-workers/110034)

<div class="topic-metadata">

**Author:** [@kingoslo](https://discourse.julialang.org/u/kingoslo)\
**Replies:** 6\
**Last updated:** [February 12, 2024, 6:37pm UTC](https://discourse.julialang.org/t/make-functions-in-the-present-model-available-to-workers/110034 "2024-02-12T18:37:56Z")

</div>

Hello. I am trying to use pmap to call a function that is defined inside the present module, but I can’t make it work. I’ve searched for a few hours for the solution. Therefore I decided to write here. This is a minimal…

---

## [How to use WriteVTK properly when saving continous simulation results?](https://discourse.julialang.org/t/how-to-use-writevtk-properly-when-saving-continous-simulation-results/109506)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 7\
**Last updated:** [February 12, 2024, 6:16pm UTC](https://discourse.julialang.org/t/how-to-use-writevtk-properly-when-saving-continous-simulation-results/109506 "2024-02-12T18:16:21Z")

</div>

Hello! I would just like to check that I am doing this right. I use WriteVTK a lot and really love it. I run a simulation in which every N time steps I output a .vtp file. The ‘pseudo’ code I use looks like this: # Th…

---

## [Access a tuple of structs using the values of an integer array](https://discourse.julialang.org/t/access-a-tuple-of-structs-using-the-values-of-an-integer-array/109980)

<div class="topic-metadata">

**Author:** [@fedoroff](https://discourse.julialang.org/u/fedoroff)\
**Replies:** 16\
**Last updated:** [February 12, 2024, 4:30pm UTC](https://discourse.julialang.org/t/access-a-tuple-of-structs-using-the-values-of-an-integer-array/109980 "2024-02-12T16:30:30Z")

</div>

I have a tuple of heterogeneous structures: struct Foo{T} a :: T b :: T end foos = (Foo(1,2), Foo(3.0,4.0)) and I have a 3D grid which is separated into different regions such that in a given region I want to …

---

## [Generate and evaluate functions programmatically](https://discourse.julialang.org/t/generate-and-evaluate-functions-programmatically/110083)

<div class="topic-metadata">

**Author:** [@VPBML](https://discourse.julialang.org/u/VPBML)\
**Replies:** 2\
**Last updated:** [February 12, 2024, 12:27pm UTC](https://discourse.julialang.org/t/generate-and-evaluate-functions-programmatically/110083 "2024-02-12T12:27:55Z")

</div>

Hi, I wonder what is the best way (performance-wise) to generate and evaluate functions programmatically. The functions I need are generated dynamically via a Genetic Programming algorithm (i.e., they are based on previ…

---

## [Cuda (Julia vs C++)](https://discourse.julialang.org/t/cuda-julia-vs-c/109865)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 4\
**Last updated:** [February 12, 2024, 12:03pm UTC](https://discourse.julialang.org/t/cuda-julia-vs-c/109865 "2024-02-12T12:03:44Z")

</div>

Are there any benchmarks between C++ cuda and Cuda.jl?

---

## [How to implement hybrid parallelized programs](https://discourse.julialang.org/t/how-to-implement-hybrid-parallelized-programs/109604)

<div class="topic-metadata">

**Author:** [@mdyuki](https://discourse.julialang.org/u/mdyuki)\
**Replies:** 29\
**Last updated:** [February 12, 2024, 8:31am UTC](https://discourse.julialang.org/t/how-to-implement-hybrid-parallelized-programs/109604 "2024-02-12T08:31:30Z")

</div>

Hello. I have scientific computing codes that contain nested loops. I have parallelized them so far with multithreading one of the loops. This improved performance, but I need to reduce more computational time. To increa…

---

## [Optimize code which uses KernelAbstractions.jl](https://discourse.julialang.org/t/optimize-code-which-uses-kernelabstractions-jl/110068)

<div class="topic-metadata">

**Author:** [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Replies:** 1\
**Last updated:** [February 11, 2024, 5:29pm UTC](https://discourse.julialang.org/t/optimize-code-which-uses-kernelabstractions-jl/110068 "2024-02-11T17:29:57Z")

</div>

Hi, in RadonKA.jl I just launch the kernel with the following code: \[....\] kernel! = radon\_kernel!(backend) kernel!(sinogram::AbstractArray{T}, img, weights, in\_height, out\_height, angles, mid, rad…

---

## [Julia crashes for larger PINNs?](https://discourse.julialang.org/t/julia-crashes-for-larger-pinns/109714)

<div class="topic-metadata">

**Author:** [@georgegito](https://discourse.julialang.org/u/georgegito)\
**Replies:** 6\
**Last updated:** [February 11, 2024, 3:49pm UTC](https://discourse.julialang.org/t/julia-crashes-for-larger-pinns/109714 "2024-02-11T15:49:27Z")

</div>

Hello, I am trying to train a PINN using NeuralPDE. I use the example of the documentation (Introduction to NeuralPDE for PDEs · NeuralPDE.jl) and when I try to increase the network size, the performance struggles and Ju…

---

## [Help me optimize my special solution to save VTP (VTK) file?](https://discourse.julialang.org/t/help-me-optimize-my-special-solution-to-save-vtp-vtk-file/110064)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 1\
**Last updated:** [February 11, 2024, 2:39pm UTC](https://discourse.julialang.org/t/help-me-optimize-my-special-solution-to-save-vtp-vtk-file/110064 "2024-02-11T14:39:52Z")

</div>

Hello! Lately I’ve learned a lot from all of you guys on the forum on how to write performant code and reduce allocs/type instabilities, which has been really nice. I have a case where I want to save a lot of simulation…

---

## [Why is the bounds-checking not elided in isassigned for \`SlowSubArray\`s despite an inbounds annotation?](https://discourse.julialang.org/t/why-is-the-bounds-checking-not-elided-in-isassigned-for-slowsubarray-s-despite-an-inbounds-annotation/110019)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 0\
**Last updated:** [February 10, 2024, 7:12am UTC](https://discourse.julialang.org/t/why-is-the-bounds-checking-not-elided-in-isassigned-for-slowsubarray-s-despite-an-inbounds-annotation/110019 "2024-02-10T07:12:03Z")

</div>

Function definition julia\> function mycopyto!(dest::AbstractArray, src::AbstractArray) iterdest, itersrc = eachindex(dest), eachindex(src) @inbounds for I in iterdest if isassigned(s…

---

## [Performance tips for Union Types](https://discourse.julialang.org/t/performance-tips-for-union-types/13928)

<div class="topic-metadata">

**Author:** [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Replies:** 6\
**Last updated:** [February 9, 2024, 10:57pm UTC](https://discourse.julialang.org/t/performance-tips-for-union-types/13928 "2024-02-09T22:57:35Z")

</div>

As I’ve summed up from the scattered discourse posts, the Julia compiler has been optimised for the small Union Types. Yet, it seems, there is no information about it in the Julia docs (I’ve searched in the Performance …

---

## [Can this be written even faster? (CPU)](https://discourse.julialang.org/t/can-this-be-written-even-faster-cpu/109924)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 34\
**Last updated:** [February 9, 2024, 2:24pm UTC](https://discourse.julialang.org/t/can-this-be-written-even-faster-cpu/109924 "2024-02-09T14:24:35Z")

</div>

Hello! My usual experience has been that when I think something is as fast as I think it can be, then someone shows me how to do it even faster :slight\_smile: I’ve made a script attached below with a serial version and…

---

## [M. learning with regularization using Flux is too slow?](https://discourse.julialang.org/t/m-learning-with-regularization-using-flux-is-too-slow/105683)

<div class="topic-metadata">

**Author:** [@taka255](https://discourse.julialang.org/u/taka255)\
**Replies:** 5\
**Last updated:** [February 9, 2024, 12:32pm UTC](https://discourse.julialang.org/t/m-learning-with-regularization-using-flux-is-too-slow/105683 "2024-02-09T12:32:49Z")

</div>

I am trying to do supervised learning with Flux, as a way to add a regularization term to the loss function referring to the official documentation. I have tried two ways to add a regularization term to the loss functio…

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

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