# Performance

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

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

**Page:** 115

---

## [Safe loop with push! multi-threading](https://discourse.julialang.org/t/safe-loop-with-push-multi-threading/41892)

<div class="topic-metadata">

**Author:** [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Replies:** 7\
**Last updated:** [June 23, 2020, 2:36am UTC](https://discourse.julialang.org/t/safe-loop-with-push-multi-threading/41892 "2020-06-23T02:36:01Z")

</div>

Hello, I would like to use multi-threading to speed-up a for loop. For each instance, an expensive computation is done and then the result is pushed at the end of an array. Here is toy example: x = collect(1:10) f(x)…

---

## [Performance of value type construction](https://discourse.julialang.org/t/performance-of-value-type-construction/41603)

<div class="topic-metadata">

**Author:** [@mtfishman](https://discourse.julialang.org/u/mtfishman)\
**Replies:** 1\
**Last updated:** [June 22, 2020, 8:11pm UTC](https://discourse.julialang.org/t/performance-of-value-type-construction/41603 "2020-06-22T20:11:35Z")

</div>

I noticed the following performance discrepancy between making a value type and making the instance of a value type using a runtime value: julia\> using BenchmarkTools julia\> x = "x" "x" julia\> f(x::String) = Val{Symbo…

---

## [Complex vector math performance: StructArray of CuArrays vs CuArrays](https://discourse.julialang.org/t/complex-vector-math-performance-structarray-of-cuarrays-vs-cuarrays/40576)

<div class="topic-metadata">

**Author:** [@ozmaden](https://discourse.julialang.org/u/ozmaden)\
**Replies:** 2\
**Last updated:** [June 22, 2020, 4:40pm UTC](https://discourse.julialang.org/t/complex-vector-math-performance-structarray-of-cuarrays-vs-cuarrays/40576 "2020-06-22T16:40:45Z")

</div>

Hi there! I’m benchmarking a GPU implementation of a function performing downconversion of a signal given a carrier signal replica. The original form of the function in the library looks like this: julia\> function downc…

---

## [Tensor Contractions for N-dimensional tensors](https://discourse.julialang.org/t/tensor-contractions-for-n-dimensional-tensors/41810)

<div class="topic-metadata">

**Author:** [@morkip](https://discourse.julialang.org/u/morkip)\
**Replies:** 5\
**Last updated:** [June 22, 2020, 1:29pm UTC](https://discourse.julialang.org/t/tensor-contractions-for-n-dimensional-tensors/41810 "2020-06-22T13:29:10Z")

</div>

I am working with exponentially sized tensors (exponential in a given variable N, for my case to the basis 4). Up to now, I stored the tensors linearly indexed, that is in a vector from 1:4^N. Contractions where therefor…

---

## [When to return an explicit \`nothing\` from a function?](https://discourse.julialang.org/t/when-to-return-an-explicit-nothing-from-a-function/41846)

<div class="topic-metadata">

**Author:** [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Replies:** 9\
**Last updated:** [June 22, 2020, 1:15pm UTC](https://discourse.julialang.org/t/when-to-return-an-explicit-nothing-from-a-function/41846 "2020-06-22T13:15:28Z")

</div>

After making a few minor modifications to a function, I was surprised that my program went from a few hundred allocations to millions. It turns out that even though I never used the return value of the function (the las…

---

## [Asynchronous Makie](https://discourse.julialang.org/t/asynchronous-makie/27127)

<div class="topic-metadata">

**Author:** [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Replies:** 17\
**Last updated:** [June 21, 2020, 11:54am UTC](https://discourse.julialang.org/t/asynchronous-makie/27127 "2020-06-21T11:54:11Z")

</div>

Hi, I wrote a toy CFD solver computing pressure and velocity fields for successive timesteps and I use Makie for plotting the result and store a movie. Although I only plot new frames every 200 timesteps, the plotting …

---

## [Matrix to array of tuples: Avoiding many small allocations](https://discourse.julialang.org/t/matrix-to-array-of-tuples-avoiding-many-small-allocations/41796)

<div class="topic-metadata">

**Author:** [@decardinb](https://discourse.julialang.org/u/decardinb)\
**Replies:** 2\
**Last updated:** [June 20, 2020, 11:35pm UTC](https://discourse.julialang.org/t/matrix-to-array-of-tuples-avoiding-many-small-allocations/41796 "2020-06-20T23:35:25Z")

</div>

How do I convert a matrix to an array of tuples while avoiding many small allocations in a loop? My current code is function matrixtotuple(x::AbstractMatrix{T}) where T r,c = size(x) pts = Vector{Tuple}(undef,r) @ti…

---

## [Compiler optimization challenge: Bayer pattern image unpacking](https://discourse.julialang.org/t/compiler-optimization-challenge-bayer-pattern-image-unpacking/41779)

<div class="topic-metadata">

**Author:** [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Replies:** 0\
**Last updated:** [June 20, 2020, 3:16pm UTC](https://discourse.julialang.org/t/compiler-optimization-challenge-bayer-pattern-image-unpacking/41779 "2020-06-20T15:16:17Z")

</div>

I’ve found an interesting example of a slightly convoluted for-loop that might be a good showcase of Julia’s ability to generate efficient code. I need help optimizing this code, though, because I’m not sure I have eithe…

---

## [Test code with multi-threading](https://discourse.julialang.org/t/test-code-with-multi-threading/41754)

<div class="topic-metadata">

**Author:** [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Replies:** 3\
**Last updated:** [June 19, 2020, 11:06pm UTC](https://discourse.julialang.org/t/test-code-with-multi-threading/41754 "2020-06-19T23:06:53Z")

</div>

Hello, I am writing a multi-threading of my code, but I would like to write unit tests to make sure I get the same results as in the serial case. I am thinking of doing: execute export JULIA\_NUM\_THREADS=6 in the bash …

---

## [Getting a reference to, and not a copy of, a field value](https://discourse.julialang.org/t/getting-a-reference-to-and-not-a-copy-of-a-field-value/9042)

<div class="topic-metadata">

**Author:** [@ablaom](https://discourse.julialang.org/u/ablaom)\
**Replies:** 12\
**Last updated:** [June 19, 2020, 1:08pm UTC](https://discourse.julialang.org/t/getting-a-reference-to-and-not-a-copy-of-a-field-value/9042 "2020-06-19T13:08:40Z")

</div>

The code y = object.x binds a copy of object.x to y. How do I make bind y to object.x itself? The reason for my question is this: To improve readability, I want to do something like this: function foo(cache) X = c…

---

## [Providing precompiled ji files within a package](https://discourse.julialang.org/t/providing-precompiled-ji-files-within-a-package/41709)

<div class="topic-metadata">

**Author:** [@Azzaare](https://discourse.julialang.org/u/Azzaare)\
**Replies:** 4\
**Last updated:** [June 19, 2020, 6:22am UTC](https://discourse.julialang.org/t/providing-precompiled-ji-files-within-a-package/41709 "2020-06-19T06:22:27Z")

</div>

Hi! I am developing a package with a heavy precompilation time (5-10 minutes, but could be a bit more). The .ji are not that big though and it runs pretty fast. Is it possible to provide .ji files (per platform I suppo…

---

## [OpenBLAS is faster than Intel MKL on AMD Hardware (Ryzen)](https://discourse.julialang.org/t/openblas-is-faster-than-intel-mkl-on-amd-hardware-ryzen/8033)

<div class="topic-metadata">

**Author:** [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Replies:** 40\
**Last updated:** [June 19, 2020, 1:03am UTC](https://discourse.julialang.org/t/openblas-is-faster-than-intel-mkl-on-amd-hardware-ryzen/8033 "2020-06-19T01:03:05Z")

</div>

Questions about MKL vs OpenBLAS come up a lot, for example in comparisons with Matlab (linked to MKL), and a lot of users have issues building with MKL, eg here. Of course, one can easily download an MKL binary with Juli…

---

## [Inlining and function boundaries](https://discourse.julialang.org/t/inlining-and-function-boundaries/41686)

<div class="topic-metadata">

**Author:** [@Kiuhnm\_Mnhuik](https://discourse.julialang.org/u/Kiuhnm_Mnhuik)\
**Replies:** 1\
**Last updated:** [June 18, 2020, 7:45pm UTC](https://discourse.julialang.org/t/inlining-and-function-boundaries/41686 "2020-06-18T19:45:42Z")

</div>

I read that inlining, by removing function boundaries, may cause type instability. Is this true? This doesn’t seem too hard to fix, but I’m not familiar with Julia internals.

---

## [Help speedup a tight triple loop](https://discourse.julialang.org/t/help-speedup-a-tight-triple-loop/41648)

<div class="topic-metadata">

**Author:** [@biona001](https://discourse.julialang.org/u/biona001)\
**Replies:** 7\
**Last updated:** [June 18, 2020, 6:15pm UTC](https://discourse.julialang.org/t/help-speedup-a-tight-triple-loop/41648 "2020-06-18T18:15:44Z")

</div>

Hello Julia, The following code is inside a multithreaded loop which gets called a lot. It essentially loops over a symmetric matrix M (dimension ~50k at most) and computes the minimum with respect to each row of N in a…

---

## [Calculate Hessian after providing gradient: NLSolversBase, Optim](https://discourse.julialang.org/t/calculate-hessian-after-providing-gradient-nlsolversbase-optim/41629)

<div class="topic-metadata">

**Author:** [@marinooss](https://discourse.julialang.org/u/marinooss)\
**Replies:** 0\
**Last updated:** [June 17, 2020, 8:48pm UTC](https://discourse.julialang.org/t/calculate-hessian-after-providing-gradient-nlsolversbase-optim/41629 "2020-06-17T20:48:53Z")

</div>

I am using the following special interface from NLSolversBase, to minimize a function. function fg!(F, G, x) common\_calc(…) if !(G == nothing) # mutating calculations specific to g! end if !(F …

---

## [Euclidean distance from one point](https://discourse.julialang.org/t/euclidean-distance-from-one-point/41594)

<div class="topic-metadata">

**Author:** [@Geoffrey](https://discourse.julialang.org/u/Geoffrey)\
**Replies:** 6\
**Last updated:** [June 17, 2020, 3:59pm UTC](https://discourse.julialang.org/t/euclidean-distance-from-one-point/41594 "2020-06-17T15:59:45Z")

</div>

Hi, I’m looking for a way to compute an array representing the radius of the polar or spherical coordinates given the array sizes and a center point. I have this code for now but it’s incredibly slow and I’m looking for …

---

## [Use of "end" in array element selection](https://discourse.julialang.org/t/use-of-end-in-array-element-selection/41598)

<div class="topic-metadata">

**Author:** [@erlebach](https://discourse.julialang.org/u/erlebach)\
**Replies:** 3\
**Last updated:** [June 17, 2020, 3:27pm UTC](https://discourse.julialang.org/t/use-of-end-in-array-element-selection/41598 "2020-06-17T15:27:36Z")

</div>

The end token means “last element of array”, and it is essentially equivalent to -1 in Python. However, that is not always true. Consider the array: a = collection(1:100) b = view(a, 1:20) c = view(a, 30:end) I get the…

---

## [About memory allocation of auxiliary array in successive calls of a function](https://discourse.julialang.org/t/about-memory-allocation-of-auxiliary-array-in-successive-calls-of-a-function/41535)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 6\
**Last updated:** [June 17, 2020, 8:31am UTC](https://discourse.julialang.org/t/about-memory-allocation-of-auxiliary-array-in-successive-calls-of-a-function/41535 "2020-06-17T08:31:02Z")

</div>

If I call a function that internally requires the allocation of an array for some computation, and afterwards I call this same function with the exact same type of input variables, is the auxiliary array which was alloca…

---

## [Plan: when julia base will start to use threads?](https://discourse.julialang.org/t/plan-when-julia-base-will-start-to-use-threads/41507)

<div class="topic-metadata">

**Author:** [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Replies:** 1\
**Last updated:** [June 16, 2020, 4:46pm UTC](https://discourse.julialang.org/t/plan-when-julia-base-will-start-to-use-threads/41507 "2020-06-16T16:46:06Z")

</div>

Hello, I just wonder, if there is a time plan for julia base to use threads to parallelized the computations by default? Right now as I can see, only user defined threads actually can speed up things but not the base-co…

---

## [Understanding Allocations in multithreaded code](https://discourse.julialang.org/t/understanding-allocations-in-multithreaded-code/41442)

<div class="topic-metadata">

**Author:** [@JonasIsensee](https://discourse.julialang.org/u/JonasIsensee)\
**Replies:** 4\
**Last updated:** [June 15, 2020, 5:37pm UTC](https://discourse.julialang.org/t/understanding-allocations-in-multithreaded-code/41442 "2020-06-15T17:37:12Z")

</div>

Hi, I’m working on speeding up particle simulation using multi-threading and I’ve come across odd allocations in the multi-threaded code that I don’t fully understand and much less know how to get rid of. Here’s a much…

---

## [How to tell if A\*B hits BLAS?](https://discourse.julialang.org/t/how-to-tell-if-a-b-hits-blas/41303)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 2\
**Last updated:** [June 14, 2020, 11:43am UTC](https://discourse.julialang.org/t/how-to-tell-if-a-b-hits-blas/41303 "2020-06-14T11:43:53Z")

</div>

Julia’s type system for linear algebra is quite sophisticated. I have a case where, after some reshape and transpose operations, I obtain two matrices A,B for which for some reason, A\*B falls back to the slow generic\_mat…

---

## [Slow arbitrary base exponentiation, a^b](https://discourse.julialang.org/t/slow-arbitrary-base-exponentiation-a-b/25386)

<div class="topic-metadata">

**Author:** [@JesseSantoso](https://discourse.julialang.org/u/JesseSantoso)\
**Replies:** 22\
**Last updated:** [June 14, 2020, 1:49am UTC](https://discourse.julialang.org/t/slow-arbitrary-base-exponentiation-a-b/25386 "2020-06-14T01:49:25Z")

</div>

Hey everyone, I’ve been having fun optimising my code and I’ve noticed that raising a Float64 to the power of another Float64 (e.g. a^b) is very slow compared to base e exponentiation using the exp() function, even to th…

---

## [Make typeof(T::Type) = Type{T}?](https://discourse.julialang.org/t/make-typeof-t-type-type-t/41333)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 0\
**Last updated:** [June 13, 2020, 5:26pm UTC](https://discourse.julialang.org/t/make-typeof-t-type-type-t/41333 "2020-06-13T17:26:35Z")

</div>

Hi Julia pros, if we use e.g. typeof((Vector, Int, 1)) we get Tuple{UnionAll, DataType, Int}, which I guess is due to typeof(Vector) = UnionAll and the like. Wouldn’t it be better for the compiler and hence performance…

---

## [Efficient closures](https://discourse.julialang.org/t/efficient-closures/41262)

<div class="topic-metadata">

**Author:** [@tfr](https://discourse.julialang.org/u/tfr)\
**Replies:** 4\
**Last updated:** [June 13, 2020, 6:18am UTC](https://discourse.julialang.org/t/efficient-closures/41262 "2020-06-13T06:18:23Z")

</div>

Hello. I have a function of many variables, hermite\_interpolation(t, t\_array, f\_array, df\_array), and I want to use this function as the argument of another function, that I shall call do\_something(pulse). However, the …

---

## [Why are my linear interpolations 10x faster in MATLAB?](https://discourse.julialang.org/t/why-are-my-linear-interpolations-10x-faster-in-matlab/41232)

<div class="topic-metadata">

**Author:** [@elenev](https://discourse.julialang.org/u/elenev)\
**Replies:** 26\
**Last updated:** [June 12, 2020, 8:35pm UTC](https://discourse.julialang.org/t/why-are-my-linear-interpolations-10x-faster-in-matlab/41232 "2020-06-12T20:35:06Z")

</div>

The consensus on this forum seems to be that Interpolations.jl is extremely fast, so I must not be using it in a smart way. Here’s an MWE of the Matlab code I’m trying to adapt to Julia. If some stuff looks weird (e.g. …

---

## [Large CPU time overhead RK4 ODE solver for parabolic problem](https://discourse.julialang.org/t/large-cpu-time-overhead-rk4-ode-solver-for-parabolic-problem/41174)

<div class="topic-metadata">

**Author:** [@egcjm](https://discourse.julialang.org/u/egcjm)\
**Replies:** 15\
**Last updated:** [June 12, 2020, 7:00pm UTC](https://discourse.julialang.org/t/large-cpu-time-overhead-rk4-ode-solver-for-parabolic-problem/41174 "2020-06-12T19:00:34Z")

</div>

I am solving a simple periodic vector parabolic equation using DifferentialEquations’ RK4() ODE solver. The code below is self contained. For the parameters specified, the ODE solver on my computer takes 0.23s (average …

---

## [Why there are different execution times for same function calls](https://discourse.julialang.org/t/why-there-are-different-execution-times-for-same-function-calls/41259)

<div class="topic-metadata">

**Author:** [@akhil\_teja](https://discourse.julialang.org/u/akhil_teja)\
**Replies:** 4\
**Last updated:** [June 12, 2020, 3:37pm UTC](https://discourse.julialang.org/t/why-there-are-different-execution-times-for-same-function-calls/41259 "2020-06-12T15:37:54Z")

</div>

Below is my Code: function bisection(custom\_func,starting::T,ending::K) where {T\<:Real,K\<:Real} if custom\_func(starting)==0 return starting elseif custom\_func(ending)==0 return ending elseif …

---

## [Simple way to precompile standard package for batch](https://discourse.julialang.org/t/simple-way-to-precompile-standard-package-for-batch/41192)

<div class="topic-metadata">

**Author:** [@compleat](https://discourse.julialang.org/u/compleat)\
**Replies:** 14\
**Last updated:** [June 11, 2020, 7:37pm UTC](https://discourse.julialang.org/t/simple-way-to-precompile-standard-package-for-batch/41192 "2020-06-11T19:37:22Z")

</div>

I have been Julia quite extensively for over a year now but because I’m me and Julia is Julia, I still consider myself a ‘newbie’, because I still struggle to do very basic things. \[I am not complaining about this, jus…

---

## [Why sortperm(Int32\[\]) return Int64\[\]](https://discourse.julialang.org/t/why-sortperm-int32-return-int64/41216)

<div class="topic-metadata">

**Author:** [@BMval](https://discourse.julialang.org/u/BMval)\
**Replies:** 1\
**Last updated:** [June 11, 2020, 6:37pm UTC](https://discourse.julialang.org/t/why-sortperm-int32-return-int64/41216 "2020-06-11T18:37:00Z")

</div>

Do you know, why is it? a=Int32\[1,2,3,4\] sortperm(a)

---

## [Is the best number of threads used in parallel computing by using distribute 4?](https://discourse.julialang.org/t/is-the-best-number-of-threads-used-in-parallel-computing-by-using-distribute-4/40139)

<div class="topic-metadata">

**Author:** [@MTone](https://discourse.julialang.org/u/MTone)\
**Replies:** 4\
**Last updated:** [June 11, 2020, 4:56pm UTC](https://discourse.julialang.org/t/is-the-best-number-of-threads-used-in-parallel-computing-by-using-distribute-4/40139 "2020-06-11T16:56:33Z")

</div>

I am doing a numerical calculation using Julia, and recently I just tested the speed of my code using parallel computing by applying @distributed in the summation: (It is just part of my code. The attached part is enc…

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

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