# Performance

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

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

**Page:** 68

---

## [Best way to save/read bytes in struct](https://discourse.julialang.org/t/best-way-to-save-read-bytes-in-struct/79842)

<div class="topic-metadata">

**Author:** [@nandoconde](https://discourse.julialang.org/u/nandoconde)\
**Replies:** 6\
**Last updated:** [April 23, 2022, 2:51pm UTC](https://discourse.julialang.org/t/best-way-to-save-read-bytes-in-struct/79842 "2022-04-23T14:51:52Z")

</div>

Hello! Main question I am developing a library to manipulate protocol messages in Julia. It must be able to store an incoming message, and then return its fields when asked for it. Here is a MWE for it: # incoming mes…

---

## [Is Julia integral calculation not as fast as MATLAB?](https://discourse.julialang.org/t/is-julia-integral-calculation-not-as-fast-as-matlab/79824)

<div class="topic-metadata">

**Author:** [@F-YF](https://discourse.julialang.org/u/F-YF)\
**Replies:** 20\
**Last updated:** [April 22, 2022, 2:08pm UTC](https://discourse.julialang.org/t/is-julia-integral-calculation-not-as-fast-as-matlab/79824 "2022-04-22T14:08:34Z")

</div>

I found it was slow when I used QuadGK.jl to do integral calculation. Then I used MATLAB to make a comparison and found that Julia integral was slower than MATLAB. Here are my comparisons: julia\> using QuadGK julia\> f(…

---

## [Speed up for-loop with multithreading](https://discourse.julialang.org/t/speed-up-for-loop-with-multithreading/79823)

<div class="topic-metadata">

**Author:** [@Himbeersternchen](https://discourse.julialang.org/u/Himbeersternchen)\
**Replies:** 10\
**Last updated:** [April 22, 2022, 1:32pm UTC](https://discourse.julialang.org/t/speed-up-for-loop-with-multithreading/79823 "2022-04-22T13:32:50Z")

</div>

Hi Guys, I’m trying to speed up my for-loop with multithreading like following (test3.jl code): time0 = @elapsed begin n = 250 a1 = Array{Array{Float64, 1}, 1}(undef, n) Threads.@threads for i in 1:n …

---

## [Fastest way to fill a Sparse Matrix?](https://discourse.julialang.org/t/fastest-way-to-fill-a-sparse-matrix/79795)

<div class="topic-metadata">

**Author:** [@Alejandro\_Quiaro\_San](https://discourse.julialang.org/u/Alejandro_Quiaro_San)\
**Replies:** 3\
**Last updated:** [April 21, 2022, 9:29pm UTC](https://discourse.julialang.org/t/fastest-way-to-fill-a-sparse-matrix/79795 "2022-04-21T21:29:05Z")

</div>

Hello guys, I am wondering which should be the right strategy to fill values in a big sparse matrix. I have a variable L, which is an n x m matrix, and is sparse. An outer loop runs on the row index, and just a few valu…

---

## [Zygote dozens\* of times slower than manually written function](https://discourse.julialang.org/t/zygote-dozens-of-times-slower-than-manually-written-function/79748)

<div class="topic-metadata">

**Author:** [@Gabrielmlando](https://discourse.julialang.org/u/Gabrielmlando)\
**Replies:** 17\
**Last updated:** [April 21, 2022, 9:25pm UTC](https://discourse.julialang.org/t/zygote-dozens-of-times-slower-than-manually-written-function/79748 "2022-04-21T21:25:48Z")

</div>

I am trying to use Zygote in order to avoid the need of manually passing gradients/Hessians. I started by the simplest possible example for my applications, namely a hydrogen atom. The Hamiltonian and initial point are d…

---

## [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…

---

## [Fast offset matrix subtraction](https://discourse.julialang.org/t/fast-offset-matrix-subtraction/79731)

<div class="topic-metadata">

**Author:** [@this\_josh](https://discourse.julialang.org/u/this_josh)\
**Replies:** 5\
**Last updated:** [April 21, 2022, 7:34am UTC](https://discourse.julialang.org/t/fast-offset-matrix-subtraction/79731 "2022-04-21T07:34:54Z")

</div>

I have a matrix h \\in \\mathbb{R}^{n\_n \\times n\_t} where n\_n is the number of sensors and n\_t is the number of hours in a day. I want to understand the variation between each timestamp for each sensor (note times roll ove…

---

## [Is it suggested to write functions for ::IO?](https://discourse.julialang.org/t/is-it-suggested-to-write-functions-for-io/79718)

<div class="topic-metadata">

**Author:** [@Rratic](https://discourse.julialang.org/u/Rratic)\
**Replies:** 6\
**Last updated:** [April 20, 2022, 9:38am UTC](https://discourse.julialang.org/t/is-it-suggested-to-write-functions-for-io/79718 "2022-04-20T09:38:55Z")

</div>

I found that some of the functions in Base are written like (::IO,::Any), and then uses sprint to wrap it so that it can return a string. For the following code: function A(io::IO) print(io,"foo") end A()=sprint(A) B()…

---

## [Extract an \`AbstractVector{T}\` from an \`AbstractVector{T, Missing}\`](https://discourse.julialang.org/t/extract-an-abstractvector-t-from-an-abstractvector-t-missing/79698)

<div class="topic-metadata">

**Author:** [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Replies:** 3\
**Last updated:** [April 19, 2022, 6:00pm UTC](https://discourse.julialang.org/t/extract-an-abstractvector-t-from-an-abstractvector-t-missing/79698 "2022-04-19T18:00:46Z")

</div>

I know that a certain subset of the indices of an AbstractVector{T, Missing} are not missing. I want to efficiently manipulate that subset. How can I extract x::AbstractVector{T} from y::AbstractVector{T, Missing} such …

---

## [Alternate ways to deal with arrays of subtypes of abstract type](https://discourse.julialang.org/t/alternate-ways-to-deal-with-arrays-of-subtypes-of-abstract-type/79689)

<div class="topic-metadata">

**Author:** [@NatMath](https://discourse.julialang.org/u/NatMath)\
**Replies:** 11\
**Last updated:** [April 19, 2022, 4:15pm UTC](https://discourse.julialang.org/t/alternate-ways-to-deal-with-arrays-of-subtypes-of-abstract-type/79689 "2022-04-19T16:15:20Z")

</div>

New to Julia here. I am currently working on a raymarching program which supports different types of primitives. I thus have a Primitive abstract type which has subtypes, for example Sphere and Box. For each primitive su…

---

## [GMT.jl and VSCode](https://discourse.julialang.org/t/gmt-jl-and-vscode/76155)

<div class="topic-metadata">

**Author:** [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Replies:** 5\
**Last updated:** [April 18, 2022, 11:56pm UTC](https://discourse.julialang.org/t/gmt-jl-and-vscode/76155 "2022-04-18T23:56:50Z")

</div>

I’m having some issues between GMT and VSCode. (macOS Big Sur). Running the following in terminal works fine. I get the image in a new window. using GMT plot(1:10, rand(10), lw=1, lc=:blue, marker=:square, markere…

---

## [Performance when dispatching on type](https://discourse.julialang.org/t/performance-when-dispatching-on-type/79617)

<div class="topic-metadata">

**Author:** [@ArjunNarayanan](https://discourse.julialang.org/u/ArjunNarayanan)\
**Replies:** 4\
**Last updated:** [April 18, 2022, 5:13pm UTC](https://discourse.julialang.org/t/performance-when-dispatching-on-type/79617 "2022-04-18T17:13:14Z")

</div>

A colleague recently showed me this example, and I’m curious as to the underlying reason for the performance hit. using BenchmarkTools, StaticArrays f(u, v) = u\*v' struct ConcType end ctyp = ConcType cvar = ConcType(…

---

## [Why does JET give these "runtime dispatch detected" lines for some LDLFactorizations calls in Tulip](https://discourse.julialang.org/t/why-does-jet-give-these-runtime-dispatch-detected-lines-for-some-ldlfactorizations-calls-in-tulip/79583)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 4\
**Last updated:** [April 18, 2022, 12:57pm UTC](https://discourse.julialang.org/t/why-does-jet-give-these-runtime-dispatch-detected-lines-for-some-ldlfactorizations-calls-in-tulip/79583 "2022-04-18T12:57:07Z")

</div>

I’m playing around with linear programming using Tulip.jl and BigFloat, and I wanted to decrease the time necessary for finding each LP solution, so it seemed like JET.jl might be helpful to investigate possible performa…

---

## [Is it possible to reduce the allocation in replace missing value?](https://discourse.julialang.org/t/is-it-possible-to-reduce-the-allocation-in-replace-missing-value/79524)

<div class="topic-metadata">

**Author:** [@tiZ](https://discourse.julialang.org/u/tiZ)\
**Replies:** 5\
**Last updated:** [April 18, 2022, 8:25am UTC](https://discourse.julialang.org/t/is-it-possible-to-reduce-the-allocation-in-replace-missing-value/79524 "2022-04-18T08:25:49Z")

</div>

Hi , I wanna replace the missing value to 0 in a large vector, but I got a hugh memory allocation for example: A = rand(10\_000\_000); @time replace!(A, -Inf =\> 0, Inf =\> 0, NaN =\> 0); this takes only 0.065884 seconds…

---

## [Why passing a distributed matrix to functions hurts performance?](https://discourse.julialang.org/t/why-passing-a-distributed-matrix-to-functions-hurts-performance/79353)

<div class="topic-metadata">

**Author:** [@Neo](https://discourse.julialang.org/u/Neo)\
**Replies:** 7\
**Last updated:** [April 14, 2022, 8:19pm UTC](https://discourse.julialang.org/t/why-passing-a-distributed-matrix-to-functions-hurts-performance/79353 "2022-04-14T20:19:00Z")

</div>

Hi folks, I observed something strange recently. Passing a distributed matrix to a function will hurt its performance? Let’s say here is task to apply a distributed matrix to some vectors like below: using Distributed…

---

## [Minimizing allocations for custom powerset iterator](https://discourse.julialang.org/t/minimizing-allocations-for-custom-powerset-iterator/79361)

<div class="topic-metadata">

**Author:** [@RobertGregg](https://discourse.julialang.org/u/RobertGregg)\
**Replies:** 7\
**Last updated:** [April 14, 2022, 7:28pm UTC](https://discourse.julialang.org/t/minimizing-allocations-for-custom-powerset-iterator/79361 "2022-04-14T19:28:22Z")

</div>

Just to preface: I realize both Combinatorics.jl and IterTools.jl implement an iterator for powersets. This question is mostly for improving my own Julia skills. I’m trying to iterate through a powerset as efficiently a…

---

## [Performance of \`zero\`, \`oneunit\` etc. in constructing unsigned ranges](https://discourse.julialang.org/t/performance-of-zero-oneunit-etc-in-constructing-unsigned-ranges/79470)

<div class="topic-metadata">

**Author:** [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Replies:** 5\
**Last updated:** [April 14, 2022, 7:26am UTC](https://discourse.julialang.org/t/performance-of-zero-oneunit-etc-in-constructing-unsigned-ranges/79470 "2022-04-14T07:26:32Z")

</div>

In my code, I often need to iterate over the range 0:m or 1:m where the type of each range element is a primitive type T, usually UInt8 or UInt16. m itself is already of type T. This leaves me with many options for spe…

---

## [How to speed up the for-loop with dataframe access](https://discourse.julialang.org/t/how-to-speed-up-the-for-loop-with-dataframe-access/79447)

<div class="topic-metadata">

**Author:** [@tiZ](https://discourse.julialang.org/u/tiZ)\
**Replies:** 25\
**Last updated:** [April 14, 2022, 6:44am UTC](https://discourse.julialang.org/t/how-to-speed-up-the-for-loop-with-dataframe-access/79447 "2022-04-14T06:44:18Z")

</div>

Hi, I am new to Julia from R, and I have a little trouble in learning how to speed up my code. for a simple demo example, I have a DataFrame with 3 column X 8679568 row, each row is a record of protein pair. The row 1 …

---

## [What is the fastest, vector or array?](https://discourse.julialang.org/t/what-is-the-fastest-vector-or-array/79399)

<div class="topic-metadata">

**Author:** [@Leticia-maria](https://discourse.julialang.org/u/Leticia-maria)\
**Replies:** 4\
**Last updated:** [April 13, 2022, 8:42pm UTC](https://discourse.julialang.org/t/what-is-the-fastest-vector-or-array/79399 "2022-04-13T20:42:18Z")

</div>

Hi there, I would like to know what do you think about the performance of different types: vector and array. Whic one is the fastest?

---

## [Should broadcasting be avoided for type unstable code?](https://discourse.julialang.org/t/should-broadcasting-be-avoided-for-type-unstable-code/79438)

<div class="topic-metadata">

**Author:** [@jules](https://discourse.julialang.org/u/jules)\
**Replies:** 3\
**Last updated:** [April 13, 2022, 3:55pm UTC](https://discourse.julialang.org/t/should-broadcasting-be-avoided-for-type-unstable-code/79438 "2022-04-13T15:55:35Z")

</div>

This simple expression incurs an overhead of 0.13 seconds in a fresh REPL (Julia 1.7.1). julia\> @time (x -\> x .+ 1)(Any\[2\]) 0.128635 seconds (458.42 k allocations: 25.632 MiB, 11.29% gc time, 99.23% compilation time) …

---

## [Convert hash digest to UInt256](https://discourse.julialang.org/t/convert-hash-digest-to-uint256/79307)

<div class="topic-metadata">

**Author:** [@jj-404](https://discourse.julialang.org/u/jj-404)\
**Replies:** 11\
**Last updated:** [April 13, 2022, 8:37am UTC](https://discourse.julialang.org/t/convert-hash-digest-to-uint256/79307 "2022-04-13T08:37:45Z")

</div>

Hello guys, I need to convert the output of sha256 to a UInt256. What is the optimal way to do that performance-wise? using SHA, BitIntegers x=sha256("okok") # convert(UInt256, x) for context, sha256 returns a Vector{…

---

## [Iterating on Tuple allocates memory if values don't have identical types](https://discourse.julialang.org/t/iterating-on-tuple-allocates-memory-if-values-dont-have-identical-types/79410)

<div class="topic-metadata">

**Author:** [@jdebecdelievre](https://discourse.julialang.org/u/jdebecdelievre)\
**Replies:** 4\
**Last updated:** [April 13, 2022, 6:56am UTC](https://discourse.julialang.org/t/iterating-on-tuple-allocates-memory-if-values-dont-have-identical-types/79410 "2022-04-13T06:56:39Z")

</div>

Hi, Could someone help me understand why iterating on a tuple seems much slower if the values have non-unique types? Here is a very simple example: a = 1. b = \[1.\] c = \[1.\] A = (a, b) B = (b, c) @btime for d=$A; d; en…

---

## [Best practice for array allocation in self-consistent calculations](https://discourse.julialang.org/t/best-practice-for-array-allocation-in-self-consistent-calculations/79371)

<div class="topic-metadata">

**Author:** [@jsjie](https://discourse.julialang.org/u/jsjie)\
**Replies:** 10\
**Last updated:** [April 13, 2022, 1:48am UTC](https://discourse.julialang.org/t/best-practice-for-array-allocation-in-self-consistent-calculations/79371 "2022-04-13T01:48:30Z")

</div>

In computational physics, self-consistent calculations are frequently met. In such calchlations, a function might be called repeatedly, and there might be some auxiliary arrays that are used in the function, which will k…

---

## [Recursive call vs while loop](https://discourse.julialang.org/t/recursive-call-vs-while-loop/7723)

<div class="topic-metadata">

**Author:** [@anon61610682](https://discourse.julialang.org/u/anon61610682)\
**Replies:** 21\
**Last updated:** [April 12, 2022, 9:40pm UTC](https://discourse.julialang.org/t/recursive-call-vs-while-loop/7723 "2022-04-12T21:40:12Z")

</div>

I have been playing with parametric methods to imitate the template programming of, say, C++. I seem to have some performance overhead when I prefer using method recursion to using a loop. Compare, for instance, the bel…

---

## [Row and column major order for arrays of different shape](https://discourse.julialang.org/t/row-and-column-major-order-for-arrays-of-different-shape/79297)

<div class="topic-metadata">

**Author:** [@fedoroff](https://discourse.julialang.org/u/fedoroff)\
**Replies:** 23\
**Last updated:** [April 12, 2022, 1:05pm UTC](https://discourse.julialang.org/t/row-and-column-major-order-for-arrays-of-different-shape/79297 "2022-04-12T13:05:12Z")

</div>

In the following code the functions r\_major and c\_major iterate over array a in the row and column major order: using BenchmarkTools function r\_major!(a) N1, N2 = size(a) for i=1:N1 for j=1:N2 a\[i,j…

---

## [Julia versus MATLAB](https://discourse.julialang.org/t/julia-versus-matlab/79360)

<div class="topic-metadata">

**Author:** [@kumarbalachandran](https://discourse.julialang.org/u/kumarbalachandran)\
**Replies:** 5\
**Last updated:** [April 12, 2022, 2:12am UTC](https://discourse.julialang.org/t/julia-versus-matlab/79360 "2022-04-12T02:12:56Z")

</div>

I am trying Julia 1.7.2 on an M1 MacBook Air for bench marking Eigen against MATLAB 2022a a=randn(100,100) tic, for x=1:100; eig(a); end; toc Elapsed time is 0.295766 seconds. whereas Julia v1.7.2 a=randn(Float64, (10…

---

## [Julia is very slow compared to python/numpy. What am I doing wrong here?](https://discourse.julialang.org/t/julia-is-very-slow-compared-to-python-numpy-what-am-i-doing-wrong-here/78598)

<div class="topic-metadata">

**Author:** [@Vahid\_Hosseinzadeh](https://discourse.julialang.org/u/Vahid_Hosseinzadeh)\
**Replies:** 25\
**Last updated:** [April 11, 2022, 6:41pm UTC](https://discourse.julialang.org/t/julia-is-very-slow-compared-to-python-numpy-what-am-i-doing-wrong-here/78598 "2022-04-11T18:41:34Z")

</div>

Hi guys, I wrote a recursive function which construct a matrix in python using Qutip module: (I just used the tensor function and Pauli matrices definitions from Qutip) import numpy as np from qutip import \* def psit…

---

## [Iterators.flatmap optimization attempt](https://discourse.julialang.org/t/iterators-flatmap-optimization-attempt/79265)

<div class="topic-metadata">

**Author:** [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Replies:** 2\
**Last updated:** [April 11, 2022, 11:38am UTC](https://discourse.julialang.org/t/iterators-flatmap-optimization-attempt/79265 "2022-04-11T11:38:47Z")

</div>

Following the nice conversation at #44792 I’m trying to investigate the question of whether flatmap functions might offer performance benefits. I suspect that in general flatten(x) cannot do better than a flatmap(identit…

---

## [Tullio seems two times slower than basic LoopVectorization](https://discourse.julialang.org/t/tullio-seems-two-times-slower-than-basic-loopvectorization/79298)

<div class="topic-metadata">

**Author:** [@ForceBru](https://discourse.julialang.org/u/ForceBru)\
**Replies:** 3\
**Last updated:** [April 10, 2022, 5:44pm UTC](https://discourse.julialang.org/t/tullio-seems-two-times-slower-than-basic-loopvectorization/79298 "2022-04-10T17:44:01Z")

</div>

I wanted to use Tullio to get rid of lots of nested loops in my code and write Einstein notation instead. Code I’m trying to compute a simple sum: elbo\_tullio(G::AbstractMatrix, p::AbstractVector, mu::AbstractVector, v…

---

## [Sundials: High memory usage](https://discourse.julialang.org/t/sundials-high-memory-usage/79270)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 1\
**Last updated:** [April 9, 2022, 9:57pm UTC](https://discourse.julialang.org/t/sundials-high-memory-usage/79270 "2022-04-09T21:57:52Z")

</div>

I am using the package Sundials, which belongs to DifferentialEquations. I have a residual function with zero memory allocations, but the IDA solver of Sundials has a quite high memory usage. I have the following code fo…

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

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