# Performance

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

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

**Page:** 118

---

## [Multithreading cause segmentation error of deprecation warning](https://discourse.julialang.org/t/multithreading-cause-segmentation-error-of-deprecation-warning/38806)

<div class="topic-metadata">

**Author:** [@JiangXL](https://discourse.julialang.org/u/JiangXL)\
**Replies:** 1\
**Last updated:** [May 5, 2020, 1:24pm UTC](https://discourse.julialang.org/t/multithreading-cause-segmentation-error-of-deprecation-warning/38806 "2020-05-05T13:24:29Z")

</div>

Running following codes without --depwarn=no using Images img = rand(512,512); Threads.@threads for i in 1:200 edge,count=imhist(img) end causes Julia crash with different output, most useful should be: ┌ Err…

---

## [How to speed up creating a sparse matrix?](https://discourse.julialang.org/t/how-to-speed-up-creating-a-sparse-matrix/38800)

<div class="topic-metadata">

**Author:** [@lesshaste](https://discourse.julialang.org/u/lesshaste)\
**Replies:** 2\
**Last updated:** [May 5, 2020, 11:43am UTC](https://discourse.julialang.org/t/how-to-speed-up-creating-a-sparse-matrix/38800 "2020-05-05T11:43:23Z")

</div>

I am attempting to create a sparse matrix from an array of arrays called S . My code is this: function make\_matrix(nostates, S) M = spzeros(Int32, nostates, nostates) convert(SparseMatrixCSC{UInt32, UInt32}, M) …

---

## [Need help on improving performance of a small subfunction](https://discourse.julialang.org/t/need-help-on-improving-performance-of-a-small-subfunction/38675)

<div class="topic-metadata">

**Author:** [@O\_Julia](https://discourse.julialang.org/u/O_Julia)\
**Replies:** 21\
**Last updated:** [May 4, 2020, 11:58am UTC](https://discourse.julialang.org/t/need-help-on-improving-performance-of-a-small-subfunction/38675 "2020-05-04T11:58:07Z")

</div>

There is a function in my main program and I have realised that this function consumes most of time in my program. Is it possible to speed up this mentioned function given below function fun1(r::Matrix,od::Int64,γ::Floa…

---

## [Could someone demystify arrays for me?](https://discourse.julialang.org/t/could-someone-demystify-arrays-for-me/38643)

<div class="topic-metadata">

**Author:** [@krstoff](https://discourse.julialang.org/u/krstoff)\
**Replies:** 1\
**Last updated:** [May 3, 2020, 5:36am UTC](https://discourse.julialang.org/t/could-someone-demystify-arrays-for-me/38643 "2020-05-03T05:36:48Z")

</div>

I was having trouble finding performance characteristics for push! and pushfirst! on Vector{T} so I wrote a quick test comparing the two and was surprised to find that they were the same speed - even when intermixed. I d…

---

## [Avoiding type instability when slicing a tuple](https://discourse.julialang.org/t/avoiding-type-instability-when-slicing-a-tuple/38567)

<div class="topic-metadata">

**Author:** [@Mason](https://discourse.julialang.org/u/Mason)\
**Replies:** 10\
**Last updated:** [May 2, 2020, 12:37am UTC](https://discourse.julialang.org/t/avoiding-type-instability-when-slicing-a-tuple/38567 "2020-05-02T00:37:58Z")

</div>

This question is an adapted version of what appeared here in the JuliaLang Zulip helpdesk. Suppose I have a function that takes in a heterogeneously typed Tuple and will return a slice of that tuple where the slice ind…

---

## [Vector addition in Julia slower than numpy in Linux](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520)

<div class="topic-metadata">

**Author:** [@aminsadeghi](https://discourse.julialang.org/u/aminsadeghi)\
**Replies:** 21\
**Last updated:** [May 1, 2020, 9:02pm UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520 "2020-05-01T21:02:51Z")

</div>

I tried this on Julia 1.4 on Ubuntu 19.10: import numpy as np a = np.random.rand(500\_000) b = np.random.rand(500\_000) %timeit a + b 115 µs ± 1.03 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each) using Benchma…

---

## [Huge difference between passing a type, or using a hardcoded-type (in benchmarks)?](https://discourse.julialang.org/t/huge-difference-between-passing-a-type-or-using-a-hardcoded-type-in-benchmarks/38561)

<div class="topic-metadata">

**Author:** [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Replies:** 6\
**Last updated:** [May 1, 2020, 6:49pm UTC](https://discourse.julialang.org/t/huge-difference-between-passing-a-type-or-using-a-hardcoded-type-in-benchmarks/38561 "2020-05-01T18:49:27Z")

</div>

I do not understand why there is a 30x difference between these two implementations. I guess I am doing some dumb (benchmarking) mistake because the produced LLVM code seems to be equal. Note that I am using a large buf…

---

## [How to call constructor of parametric family of types efficiently](https://discourse.julialang.org/t/how-to-call-constructor-of-parametric-family-of-types-efficiently/38503)

<div class="topic-metadata">

**Author:** [@SEA](https://discourse.julialang.org/u/SEA)\
**Replies:** 6\
**Last updated:** [April 30, 2020, 8:38pm UTC](https://discourse.julialang.org/t/how-to-call-constructor-of-parametric-family-of-types-efficiently/38503 "2020-04-30T20:38:23Z")

</div>

I would like to call the constructor of several parametric families of types efficiently, while only having access to a concrete instance of a type. Also, I am trying to avoid having to write a separate method for each f…

---

## [Strange memory allocation with DistributedArrays](https://discourse.julialang.org/t/strange-memory-allocation-with-distributedarrays/38325)

<div class="topic-metadata">

**Author:** [@mipiro](https://discourse.julialang.org/u/mipiro)\
**Replies:** 11\
**Last updated:** [April 29, 2020, 3:51am UTC](https://discourse.julialang.org/t/strange-memory-allocation-with-distributedarrays/38325 "2020-04-29T03:51:37Z")

</div>

Hello! I noticed a strange thing while I was playing with distributed arrays. Here is an example of the code: using Distributed; addprocs(2) @everywhere using DistributedArrays function create\_big\_darray(n) darr =…

---

## [Improving performance of mapping algorithm](https://discourse.julialang.org/t/improving-performance-of-mapping-algorithm/38161)

<div class="topic-metadata">

**Author:** [@Mabo87](https://discourse.julialang.org/u/Mabo87)\
**Replies:** 17\
**Last updated:** [April 28, 2020, 5:30pm UTC](https://discourse.julialang.org/t/improving-performance-of-mapping-algorithm/38161 "2020-04-28T17:30:29Z")

</div>

Hi all, I ported a code from MATLAB to Julia, because it takes too long right now: using Random using Printf start = time() Lk = 4 Lp = 1500 # create test data: coordinates of relative points and points to be mapped p…

---

## [Julia on old desktop vs Matlab on old desktop vs Julia on Raspberry Pi-4](https://discourse.julialang.org/t/julia-on-old-desktop-vs-matlab-on-old-desktop-vs-julia-on-raspberry-pi-4/38162)

<div class="topic-metadata">

**Author:** [@kw\_martin](https://discourse.julialang.org/u/kw_martin)\
**Replies:** 5\
**Last updated:** [April 28, 2020, 2:30pm UTC](https://discourse.julialang.org/t/julia-on-old-desktop-vs-matlab-on-old-desktop-vs-julia-on-raspberry-pi-4/38162 "2020-04-28T14:30:20Z")

</div>

I have an early but complete and working (fairly well) version of a set of routines for analyzing ECG signals for the heart rate. It is mostly based on a popular technique called Pan/Tompkins (published in 1985 that oper…

---

## [Performance of collecting a zip where one argument to zip has eltype == Union{Nothing, Int}](https://discourse.julialang.org/t/performance-of-collecting-a-zip-where-one-argument-to-zip-has-eltype-union-nothing-int/38310)

<div class="topic-metadata">

**Author:** [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Replies:** 4\
**Last updated:** [April 28, 2020, 4:33am UTC](https://discourse.julialang.org/t/performance-of-collecting-a-zip-where-one-argument-to-zip-has-eltype-union-nothing-int/38310 "2020-04-28T04:33:47Z")

</div>

I ran into an interesting performance issue when collecting a zip. Before you say “don’t collect!”, the next step is to feed the collected array into sort, which throws a method error if you feed it a zip iterator. The i…

---

## [Can \`load\` work faster?](https://discourse.julialang.org/t/can-load-work-faster/38291)

<div class="topic-metadata">

**Author:** [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Replies:** 3\
**Last updated:** [April 27, 2020, 1:00pm UTC](https://discourse.julialang.org/t/can-load-work-faster/38291 "2020-04-27T13:00:39Z")

</div>

I have to load many files in a loop (to be more specific, I’m working with OBJ files to be used with MeshIO). I guess that including a line like load(filename) in the loop, with filename being a string with the file path…

---

## [Improving an algorithm that compute gps distances](https://discourse.julialang.org/t/improving-an-algorithm-that-compute-gps-distances/38213)

<div class="topic-metadata">

**Author:** [@David\_Cardozo](https://discourse.julialang.org/u/David_Cardozo)\
**Replies:** 41\
**Last updated:** [April 27, 2020, 10:20am UTC](https://discourse.julialang.org/t/improving-an-algorithm-that-compute-gps-distances/38213 "2020-04-27T10:20:34Z")

</div>

Hi everyone! Is it possible to parallelize vectorized functions / operations? I have this code I ported from python but it running a little bit slower than numpy and not surprisingly 10x slower than jax (cpu only). u…

---

## [Show off Julia performance on your PC!](https://discourse.julialang.org/t/show-off-julia-performance-on-your-pc/33606)

<div class="topic-metadata">

**Author:** [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Replies:** 53\
**Last updated:** [April 26, 2020, 9:21pm UTC](https://discourse.julialang.org/t/show-off-julia-performance-on-your-pc/33606 "2020-04-26T21:21:39Z")

</div>

I just built a new PC and, after asking some questions here about performance and getting some interesting answers, I thought it would be fun to start a thread where people can show off their builds and, more importantly…

---

## [Manually specialized function is faster than the generic version](https://discourse.julialang.org/t/manually-specialized-function-is-faster-than-the-generic-version/38223)

<div class="topic-metadata">

**Author:** [@fjarri](https://discourse.julialang.org/u/fjarri)\
**Replies:** 2\
**Last updated:** [April 26, 2020, 6:58am UTC](https://discourse.julialang.org/t/manually-specialized-function-is-faster-than-the-generic-version/38223 "2020-04-26T06:58:36Z")

</div>

The code: using BenchmarkTools function adc(a::T, b::T, carry::T) where T T2 = widen(T) ret = (a % T2) + (b % T2) + (carry % T2) ret % T, (ret \>\> 64) % T end function mac(a::T, b::T, c::T, carry::T) wher…

---

## [Avoid repeated memory allocation by defining an Array{Float64} outside of optimize() using Optim.jl, ForwardDiff.jl](https://discourse.julialang.org/t/avoid-repeated-memory-allocation-by-defining-an-array-float64-outside-of-optimize-using-optim-jl-forwarddiff-jl/37357)

<div class="topic-metadata">

**Author:** [@Maximilian](https://discourse.julialang.org/u/Maximilian)\
**Replies:** 7\
**Last updated:** [April 24, 2020, 6:58pm UTC](https://discourse.julialang.org/t/avoid-repeated-memory-allocation-by-defining-an-array-float64-outside-of-optimize-using-optim-jl-forwarddiff-jl/37357 "2020-04-24T18:58:01Z")

</div>

I am using Optim.jl with an objective that is computed by multipliying, transposing and inverting some matrices (maximum size of about 500x500). However, I have only a few parameters (maximum 200), each one having a fixe…

---

## [Using IOStreams with Distributed parallelism](https://discourse.julialang.org/t/using-iostreams-with-distributed-parallelism/37966)

<div class="topic-metadata">

**Author:** [@Ward9250](https://discourse.julialang.org/u/Ward9250)\
**Replies:** 2\
**Last updated:** [April 24, 2020, 1:38pm UTC](https://discourse.julialang.org/t/using-iostreams-with-distributed-parallelism/37966 "2020-04-24T13:38:57Z")

</div>

I’ve got a serial function: function serial\_mem(::Type{M}, input::DatastoreBuffer{\<:ReadDatastore}, count\_mode::CountMode, range::AbstractRange = 1:length(input)) where {M\<:AbstractMer} @info "\[Process: $(myid())\] C…

---

## [Generate faa di bruno matrix](https://discourse.julialang.org/t/generate-faa-di-bruno-matrix/38059)

<div class="topic-metadata">

**Author:** [@Veenty](https://discourse.julialang.org/u/Veenty)\
**Replies:** 9\
**Last updated:** [April 24, 2020, 2:25am UTC](https://discourse.julialang.org/t/generate-faa-di-bruno-matrix/38059 "2020-04-24T02:25:31Z")

</div>

I am trying to implement the funcion A(x1, x2, x3, ..xn) Such that \[A\]\_{m,j} = B\_{m,j} , where B\_{m,j} corresponds to the incomplete bell polynomial. The thing is, that I don’t want to have to construct that matrix ev…

---

## [Unexpected Core.Box from functions within a function](https://discourse.julialang.org/t/unexpected-core-box-from-functions-within-a-function/38022)

<div class="topic-metadata">

**Author:** [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Replies:** 4\
**Last updated:** [April 23, 2020, 6:34am UTC](https://discourse.julialang.org/t/unexpected-core-box-from-functions-within-a-function/38022 "2020-04-23T06:34:14Z")

</div>

I was surprised that something like the following is slow, and not type-stable: function g(A) function make(A) B = similar(A) act!(B, A, axes(A, 1)) B end function act!(B, A, ax) …

---

## [Efficiently Store and Access Large 3-Dimensional Arrays](https://discourse.julialang.org/t/efficiently-store-and-access-large-3-dimensional-arrays/37656)

<div class="topic-metadata">

**Author:** [@Dr.Merkwuedigliebe](https://discourse.julialang.org/u/Dr.Merkwuedigliebe)\
**Replies:** 12\
**Last updated:** [April 22, 2020, 5:19pm UTC](https://discourse.julialang.org/t/efficiently-store-and-access-large-3-dimensional-arrays/37656 "2020-04-22T17:19:19Z")

</div>

I am working on a simulation that stores and remove values (some form of float) at various points in a 3-dimensional space, represented by an array with a size of ~(2e4 x 4e4 x 1e2). Specifically, it records the property…

---

## [Fastest way to compute \`A^n \* x\` for large matrices \`A\` and vector \`x\`](https://discourse.julialang.org/t/fastest-way-to-compute-a-n-x-for-large-matrices-a-and-vector-x/37900)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 13\
**Last updated:** [April 22, 2020, 3:54pm UTC](https://discourse.julialang.org/t/fastest-way-to-compute-a-n-x-for-large-matrices-a-and-vector-x/37900 "2020-04-22T15:54:25Z")

</div>

I have the following two (functionally equivalent) functions function mul1(A, xin) x1 = copy(xin) x2 = A\*x1 for i in 1:20 x2 = A\*x1 x1, x2 = x2, x1 end return x1 end and function mu…

---

## [Is is just me or](https://discourse.julialang.org/t/is-is-just-me-or/38003)

<div class="topic-metadata">

**Author:** [@lewis](https://discourse.julialang.org/u/lewis)\
**Replies:** 0\
**Last updated:** [April 22, 2020, 2:41am UTC](https://discourse.julialang.org/t/is-is-just-me-or/38003 "2020-04-22T02:41:36Z")

</div>

…is 1.4 a lot snappier in a lot of ways. I am eyeballing and I time runs of something new I’m working on. Those timings are about 10% or more faster. I’ve improved the code a little, but I’ve also added some tricky fea…

---

## [Construction Overhead for MvNormal](https://discourse.julialang.org/t/construction-overhead-for-mvnormal/37732)

<div class="topic-metadata">

**Author:** [@bmit](https://discourse.julialang.org/u/bmit)\
**Replies:** 4\
**Last updated:** [April 19, 2020, 3:32pm UTC](https://discourse.julialang.org/t/construction-overhead-for-mvnormal/37732 "2020-04-19T15:32:19Z")

</div>

MvNormal distributions in the Distributions package have a large construction overhead because the underlaying PDMats package performs a full Cholesky decomposition of the covariance matrix. In theory, I think this can b…

---

## [Type inference fails for broadcasted addition of tuples containing multiple types](https://discourse.julialang.org/t/type-inference-fails-for-broadcasted-addition-of-tuples-containing-multiple-types/37725)

<div class="topic-metadata">

**Author:** [@tomohiro\_soejima](https://discourse.julialang.org/u/tomohiro_soejima)\
**Replies:** 3\
**Last updated:** [April 17, 2020, 6:19am UTC](https://discourse.julialang.org/t/type-inference-fails-for-broadcasted-addition-of-tuples-containing-multiple-types/37725 "2020-04-17T06:19:34Z")

</div>

Hi, I want to write addition function for tuples with unknown length and unknown type e.g. something like Tuple{a, b, c, d...} where the length and type is determined at runtime, and a, b, c, and d are custom types with…

---

## [Efficient way to apply monotonous rank transformation to an array](https://discourse.julialang.org/t/efficient-way-to-apply-monotonous-rank-transformation-to-an-array/37689)

<div class="topic-metadata">

**Author:** [@francesco.alemanno](https://discourse.julialang.org/u/francesco.alemanno)\
**Replies:** 4\
**Last updated:** [April 16, 2020, 1:51pm UTC](https://discourse.julialang.org/t/efficient-way-to-apply-monotonous-rank-transformation-to-an-array/37689 "2020-04-16T13:51:02Z")

</div>

hi guys, i wonder if any of you know of a more efficient way to rank an array currently i am using A=\[45, 4, 7, 10, 25, 36, 36, 22, 31, 16\] # input vector S=invperm(sort(1:length(A),by=i-\>A\[i\])) f(x)=x^2 B=1:length(…

---

## [Weird behaviour with packages and multiple processes](https://discourse.julialang.org/t/weird-behaviour-with-packages-and-multiple-processes/37651)

<div class="topic-metadata">

**Author:** [@Ward9250](https://discourse.julialang.org/u/Ward9250)\
**Replies:** 2\
**Last updated:** [April 15, 2020, 6:25pm UTC](https://discourse.julialang.org/t/weird-behaviour-with-packages-and-multiple-processes/37651 "2020-04-15T18:25:57Z")

</div>

Hi, I’m trying to develop a package which has some functionality that uses Distributed, I created a project to test and run my function but I’m getting some weirdness: So I created a project with the package I wanted to…

---

## [Memory issues](https://discourse.julialang.org/t/memory-issues/37594)

<div class="topic-metadata">

**Author:** [@natgeo-wong](https://discourse.julialang.org/u/natgeo-wong)\
**Replies:** 3\
**Last updated:** [April 15, 2020, 6:47am UTC](https://discourse.julialang.org/t/memory-issues/37594 "2020-04-15T06:47:57Z")

</div>

Hi! Got a question on memory handling: For the following script nlon = 360; nlat = 181; nhr = 744; np = 37; for loop = 1 : 5 @info "$(Dates.now()) - Preallocating arrays ..." Ta = zeros(nlon,nlat,nhr,np); sH…

---

## [Initializing Dictionary and where syntax](https://discourse.julialang.org/t/initializing-dictionary-and-where-syntax/37467)

<div class="topic-metadata">

**Author:** [@Holdmycoffee](https://discourse.julialang.org/u/Holdmycoffee)\
**Replies:** 1\
**Last updated:** [April 12, 2020, 9:47pm UTC](https://discourse.julialang.org/t/initializing-dictionary-and-where-syntax/37467 "2020-04-12T21:47:51Z")

</div>

Is there any difference between Dict{T where T\<: Real, Int64}() and Dict{Real, Int64}() ?

---

## [Running task on background thread slows performance and increases jitter](https://discourse.julialang.org/t/running-task-on-background-thread-slows-performance-and-increases-jitter/37320)

<div class="topic-metadata">

**Author:** [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Replies:** 2\
**Last updated:** [April 11, 2020, 12:34am UTC](https://discourse.julialang.org/t/running-task-on-background-thread-slows-performance-and-increases-jitter/37320 "2020-04-11T00:34:15Z")

</div>

I’ve been testing to see if Julia is appropriate for recording high volumes of market data arriving over the network with precise timestamps. I ran the simple loop below to simulate parsing strings and to create a littl…

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

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