# Performance

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

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

**Page:** 28

---

## [@btime alters subsequent @time result](https://discourse.julialang.org/t/btime-alters-subsequent-time-result/111384)

<div class="topic-metadata">

**Author:** [@chunjiw](https://discourse.julialang.org/u/chunjiw)\
**Replies:** 6\
**Last updated:** [March 11, 2024, 8:18pm UTC](https://discourse.julialang.org/t/btime-alters-subsequent-time-result/111384 "2024-03-11T20:18:31Z")

</div>

I’m trying to benchmark a struct implementation, where I encounter this. Minimal example: using BenchmarkTools struct S end (s::S)() = 1 let s = S() # @btime $s() @time s() end From which I get output 0.0…

---

## [Make Julia complete the inference of some recursive code](https://discourse.julialang.org/t/make-julia-complete-the-inference-of-some-recursive-code/111449)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 2\
**Last updated:** [March 11, 2024, 2:44pm UTC](https://discourse.julialang.org/t/make-julia-complete-the-inference-of-some-recursive-code/111449 "2024-03-11T14:44:47Z")

</div>

Background I have a function with a real number input coming from a finite interval. To implement the function, I break down that interval into several subintervals and implement the function on each of them. Suppose, fo…

---

## [Static array or tuple allocate at construction](https://discourse.julialang.org/t/static-array-or-tuple-allocate-at-construction/111447)

<div class="topic-metadata">

**Author:** [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Replies:** 2\
**Last updated:** [March 11, 2024, 9:11am UTC](https://discourse.julialang.org/t/static-array-or-tuple-allocate-at-construction/111447 "2024-03-11T09:11:28Z")

</div>

I have some code that allocates on the heap (and shouldn’t) while constructing a StaticArray. The hunt leads me to this MWE: using StaticArrays, BenchmarkTools @btime SVector{4,Float64}(2. \*i for i=1:4) # good, no…

---

## [Filling a StructArray in a type-stable manner](https://discourse.julialang.org/t/filling-a-structarray-in-a-type-stable-manner/111319)

<div class="topic-metadata">

**Author:** [@peremato](https://discourse.julialang.org/u/peremato)\
**Replies:** 3\
**Last updated:** [March 7, 2024, 8:05pm UTC](https://discourse.julialang.org/t/filling-a-structarray-in-a-type-stable-manner/111319 "2024-03-07T20:05:11Z")

</div>

I am trying to create StructArray’s reading from a ROOT file with the UnROOT.jl package, which provides a NamedTuple interface, in a type-stable manner. The following code illustrates the problem: using StructArrays usi…

---

## [Hidden allocations when parallelizing with @batch](https://discourse.julialang.org/t/hidden-allocations-when-parallelizing-with-batch/111051)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 13\
**Last updated:** [March 5, 2024, 10:35pm UTC](https://discourse.julialang.org/t/hidden-allocations-when-parallelizing-with-batch/111051 "2024-03-05T22:35:18Z")

</div>

Hello guys! I’ve hit a bit of a roadblock and need a bit of help to overcome it. I’ve made a parallelized reduction function in which I am using Polyester.@batch. It works very well for 1 dimensional arrays, but now I a…

---

## [Is @distributed using local threads to further distribute?](https://discourse.julialang.org/t/is-distributed-using-local-threads-to-further-distribute/111130)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 2\
**Last updated:** [March 4, 2024, 3:39pm UTC](https://discourse.julialang.org/t/is-distributed-using-local-threads-to-further-distribute/111130 "2024-03-04T15:39:05Z")

</div>

I am looking for a @distributed reducer for ... version which simply parallelizes the function as large as possible. I.e. using both available machines and available threads. Is @distributed already doing so? if not, i…

---

## [Question on TaskLocalValue](https://discourse.julialang.org/t/question-on-tasklocalvalue/110658)

<div class="topic-metadata">

**Author:** [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)\
**Replies:** 10\
**Last updated:** [March 4, 2024, 3:18pm UTC](https://discourse.julialang.org/t/question-on-tasklocalvalue/110658 "2024-03-04T15:18:10Z")

</div>

Continuing the discussion from Inconsistent CPU utilisation in @threads loops: I understand that trying to establish thread-based storage is an invitation to disaster, but on the other hand, when there are many more …

---

## [Plotting slow](https://discourse.julialang.org/t/plotting-slow/111083)

<div class="topic-metadata">

**Author:** [@Fourier](https://discourse.julialang.org/u/Fourier)\
**Replies:** 6\
**Last updated:** [March 4, 2024, 12:57pm UTC](https://discourse.julialang.org/t/plotting-slow/111083 "2024-03-04T12:57:43Z")

</div>

We are currently working on a simulation and the bottleneck is plotting. We are plotting a grid of dimension 1000 x 2000 and saving it. T\_c\_hm = heatmap(x, y, transpose(T\_c\_renh), size = (1000, 400), clim=(0, 0.3)) …

---

## [Is matrix multiplication multi-threaded for Double64?](https://discourse.julialang.org/t/is-matrix-multiplication-multi-threaded-for-double64/111081)

<div class="topic-metadata">

**Author:** [@photor](https://discourse.julialang.org/u/photor)\
**Replies:** 4\
**Last updated:** [March 3, 2024, 5:01am UTC](https://discourse.julialang.org/t/is-matrix-multiplication-multi-threaded-for-double64/111081 "2024-03-03T05:01:22Z")

</div>

I tested multiplication of two Double64 matrices and saw no effects on performance by using BLAS.set\_num\_threads(n).

---

## [Efficient approach to generate optimised methods for special cases of a general function](https://discourse.julialang.org/t/efficient-approach-to-generate-optimised-methods-for-special-cases-of-a-general-function/110892)

<div class="topic-metadata">

**Author:** [@TimHargreaves](https://discourse.julialang.org/u/TimHargreaves)\
**Replies:** 5\
**Last updated:** [March 2, 2024, 6:46pm UTC](https://discourse.julialang.org/t/efficient-approach-to-generate-optimised-methods-for-special-cases-of-a-general-function/110892 "2024-03-02T18:46:55Z")

</div>

I am a fairly new user of Julia so may have misconceptions about the language’s capabilities and behaviour. Problem Statement I have implemented the most general form of an algorithm I am interested in, which is parame…

---

## [Maybe this is off topic but I don't think so](https://discourse.julialang.org/t/maybe-this-is-off-topic-but-i-dont-think-so/111040)

<div class="topic-metadata">

**Author:** [@skypuppy](https://discourse.julialang.org/u/skypuppy)\
**Replies:** 0\
**Last updated:** [March 2, 2024, 3:31am UTC](https://discourse.julialang.org/t/maybe-this-is-off-topic-but-i-dont-think-so/111040 "2024-03-02T03:31:58Z")

</div>

As a present to myself, I built my Christmas gift: Ryzen 9 9750 on an Asrock mobo, 64 gb main memory (128 implementation still has problems AIUI,) and a Unicorn for main NVMe drive (gen 4!- gen 5 still not available to m…

---

## [Multiplication of \`BitMatrix\`s for linear algebra modulo 2](https://discourse.julialang.org/t/multiplication-of-bitmatrix-s-for-linear-algebra-modulo-2/110750)

<div class="topic-metadata">

**Author:** [@Leo\_I](https://discourse.julialang.org/u/Leo_I)\
**Replies:** 10\
**Last updated:** [February 29, 2024, 11:23am UTC](https://discourse.julialang.org/t/multiplication-of-bitmatrix-s-for-linear-algebra-modulo-2/110750 "2024-02-29T11:23:53Z")

</div>

When dealing with matrices over \\mathbb{Z}\_2 that are enormours (e.g. of size 10^5\\times10^5), it is desirable to use implementations that minimize the allocated memory. For instance: julia\> using FiniteFields julia\> si…

---

## [A compiler trick for performance-holic](https://discourse.julialang.org/t/a-compiler-trick-for-performance-holic/110932)

<div class="topic-metadata">

**Author:** [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Replies:** 0\
**Last updated:** [February 29, 2024, 7:35am UTC](https://discourse.julialang.org/t/a-compiler-trick-for-performance-holic/110932 "2024-02-29T07:35:44Z")

</div>

In the settings. "terminal.integrated.env.windows": {"JULIA\_LLVM\_ARGS":\<your LLVM arguments here.\>} LLVM has lots of optimization options you can toggle. Maybe if you dig hard enough, you’ll find something that makes y…

---

## [Dispatch based on symbol parameter](https://discourse.julialang.org/t/dispatch-based-on-symbol-parameter/110849)

<div class="topic-metadata">

**Author:** [@atteson](https://discourse.julialang.org/u/atteson)\
**Replies:** 15\
**Last updated:** [February 29, 2024, 5:40am UTC](https://discourse.julialang.org/t/dispatch-based-on-symbol-parameter/110849 "2024-02-29T05:40:37Z")

</div>

Is there any way to dispatch directly on a symbol function parameter? I have a function which takes a symbol and returns a different type based on a symbol that is passed into it. In order for this function to have a typ…

---

## [Scalar function for reals and arrays: single function definition](https://discourse.julialang.org/t/scalar-function-for-reals-and-arrays-single-function-definition/110886)

<div class="topic-metadata">

**Author:** [@abehersan](https://discourse.julialang.org/u/abehersan)\
**Replies:** 6\
**Last updated:** [February 28, 2024, 12:13pm UTC](https://discourse.julialang.org/t/scalar-function-for-reals-and-arrays-single-function-definition/110886 "2024-02-28T12:13:33Z")

</div>

I often find myself writing two methods for a simple scalar function. E.g. function gauss(x::Real; a=1.0, c=0.0, s=0.7) return a/s/(sqrt(2pi))\*exp(-((x-c)^2/(2\*s^2))) end function gauss(x::AbstractArray{\<:Real}; a=…

---

## [Assistance with optimization](https://discourse.julialang.org/t/assistance-with-optimization/110862)

<div class="topic-metadata">

**Author:** [@narnold0](https://discourse.julialang.org/u/narnold0)\
**Replies:** 0\
**Last updated:** [February 27, 2024, 9:48pm UTC](https://discourse.julialang.org/t/assistance-with-optimization/110862 "2024-02-27T21:48:28Z")

</div>

Hi friends, I made a post about the problem of generating pairs of objects while also filtering them, and it seemed that parallel computing was the main suggestion, so I’m trying to learn CUDA for that, but I’ve run int…

---

## [Allocating OnlineStats on the stack](https://discourse.julialang.org/t/allocating-onlinestats-on-the-stack/110856)

<div class="topic-metadata">

**Author:** [@mattwigway](https://discourse.julialang.org/u/mattwigway)\
**Replies:** 2\
**Last updated:** [February 27, 2024, 4:26pm UTC](https://discourse.julialang.org/t/allocating-onlinestats-on-the-stack/110856 "2024-02-27T16:26:22Z")

</div>

I’m using OnlineStats to calculate a likelihood function, so I’m creating and destroying a LogSumExp for each row. LogSumExps, like all online stats, are mutable structs, so heap-allocated in general, but I thought that …

---

## [What is the actual difference between AvancedMH.jl's Static and RandomWalk Prposals](https://discourse.julialang.org/t/what-is-the-actual-difference-between-avancedmh-jls-static-and-randomwalk-prposals/110838)

<div class="topic-metadata">

**Author:** [@caesoma](https://discourse.julialang.org/u/caesoma)\
**Replies:** 0\
**Last updated:** [February 27, 2024, 9:59am UTC](https://discourse.julialang.org/t/what-is-the-actual-difference-between-avancedmh-jls-static-and-randomwalk-prposals/110838 "2024-02-27T09:59:05Z")

</div>

I am trying to modify the proposal distributions in the Metropolis-Hastings sampler in the AdvancedMH.jl package. It is not clear to me what the Static and RandomWalk proposals do. As I understand it, the former draws a…

---

## [Adaptive proposals in AdvancedMH.jl (or other Metropolis-capable) package](https://discourse.julialang.org/t/adaptive-proposals-in-advancedmh-jl-or-other-metropolis-capable-package/110837)

<div class="topic-metadata">

**Author:** [@caesoma](https://discourse.julialang.org/u/caesoma)\
**Replies:** 0\
**Last updated:** [February 27, 2024, 9:42am UTC](https://discourse.julialang.org/t/adaptive-proposals-in-advancedmh-jl-or-other-metropolis-capable-package/110837 "2024-02-27T09:42:03Z")

</div>

I am trying to run an MCMC chain with a Metropolis-Hastings sampler, but a fixed proposal distribution normally yields poor results. Apparently the AdvancedMH.jl package doesn’t have the feature for tuning the variance o…

---

## [Efficient way for executing multiple models](https://discourse.julialang.org/t/efficient-way-for-executing-multiple-models/110804)

<div class="topic-metadata">

**Author:** [@cirobr](https://discourse.julialang.org/u/cirobr)\
**Replies:** 0\
**Last updated:** [February 26, 2024, 7:51pm UTC](https://discourse.julialang.org/t/efficient-way-for-executing-multiple-models/110804 "2024-02-26T19:51:11Z")

</div>

Cheers, Let chain be a Flux.Chain of FCNs. I want to execute each of the chained models independently with the same input array, then concatenate all outputs as the model result. I did the following: using Flux: Chain…

---

## [What is the fastest way to check if a hermitian matrix is positive semi-definite?](https://discourse.julialang.org/t/what-is-the-fastest-way-to-check-if-a-hermitian-matrix-is-positive-semi-definite/110769)

<div class="topic-metadata">

**Author:** [@marcsgil](https://discourse.julialang.org/u/marcsgil)\
**Replies:** 7\
**Last updated:** [February 26, 2024, 1:46pm UTC](https://discourse.julialang.org/t/what-is-the-fastest-way-to-check-if-a-hermitian-matrix-is-positive-semi-definite/110769 "2024-02-26T13:46:00Z")

</div>

Hello, I would like to check if a hermitian matrix is positive semi-definite (the smallest eigenvalue is \>= 0). The simplest implementation would be using LinearAlgebra is\_positive(A::Hermitian) = eigmin(A) ≥ 0 and ru…

---

## [Reducing Materialize in Profiling](https://discourse.julialang.org/t/reducing-materialize-in-profiling/110698)

<div class="topic-metadata">

**Author:** [@dennispureza](https://discourse.julialang.org/u/dennispureza)\
**Replies:** 5\
**Last updated:** [February 24, 2024, 5:50pm UTC](https://discourse.julialang.org/t/reducing-materialize-in-profiling/110698 "2024-02-24T17:50:51Z")

</div>

Hi! I am profiling my code and roughly 75% of the following line’s time is occupied with Materialize, any ideia how to optimize this? J = sum((dfdWdP.\*(f.- f̄ - ((f̃/g̃)\*(g.-ḡ)))), dims=1)' dfdWdP is a Matrix{Float64…

---

## [Inconsistent CPU utilisation in @threads loops](https://discourse.julialang.org/t/inconsistent-cpu-utilisation-in-threads-loops/110512)

<div class="topic-metadata">

**Author:** [@ysh](https://discourse.julialang.org/u/ysh)\
**Replies:** 20\
**Last updated:** [February 23, 2024, 8:55pm UTC](https://discourse.julialang.org/t/inconsistent-cpu-utilisation-in-threads-loops/110512 "2024-02-23T20:55:43Z")

</div>

Consider a MWE where some moderately-heavy calculations are performed in a parallel loop. Here, I am simulating the calculations by doing eigen: using LinearAlgebra, Random BLAS.set\_num\_threads(1) # turn off BLAS parall…

---

## [Fast solution of a two-point boundary value problem with Shooting](https://discourse.julialang.org/t/fast-solution-of-a-two-point-boundary-value-problem-with-shooting/110531)

<div class="topic-metadata">

**Author:** [@flibe](https://discourse.julialang.org/u/flibe)\
**Replies:** 1\
**Last updated:** [February 23, 2024, 3:01pm UTC](https://discourse.julialang.org/t/fast-solution-of-a-two-point-boundary-value-problem-with-shooting/110531 "2024-02-23T15:01:05Z")

</div>

Dear All, I am trying to find a way to solve as fast as possible a two point boundary value problem (TPBVP) related to the optimal control of a storage system (it arises from the associated optimality necessary conditio…

---

## [Which matrix multiplication is more efficient? A\*B and C\*B or \[A; C\]\*B](https://discourse.julialang.org/t/which-matrix-multiplication-is-more-efficient-a-b-and-c-b-or-a-c-b/110636)

<div class="topic-metadata">

**Author:** [@MatheusJanczkowski](https://discourse.julialang.org/u/MatheusJanczkowski)\
**Replies:** 9\
**Last updated:** [February 23, 2024, 1:07pm UTC](https://discourse.julialang.org/t/which-matrix-multiplication-is-more-efficient-a-b-and-c-b-or-a-c-b/110636 "2024-02-23T13:07:25Z")

</div>

I have pairs of square matrix multiplications which share one of the matrices, for example: AB, CB, where A, B and C are real square matrices. My question is: is it more efficient to compute both multiplications separ…

---

## [Skipping a lot of lines in CSV.read() allocates too much memory](https://discourse.julialang.org/t/skipping-a-lot-of-lines-in-csv-read-allocates-too-much-memory/110121)

<div class="topic-metadata">

**Author:** [@aris](https://discourse.julialang.org/u/aris)\
**Replies:** 77\
**Last updated:** [February 23, 2024, 11:30am UTC](https://discourse.julialang.org/t/skipping-a-lot-of-lines-in-csv-read-allocates-too-much-memory/110121 "2024-02-23T11:30:30Z")

</div>

Hello everyone, Consider the following example: using CSV, DataFrames number\_of\_lines = 10^4 CSV.write("data.csv", DataFrame(rand(number\_of\_lines,10), :auto)) steps = 20 chunk = round(Int,number\_of\_lines/steps) for …

---

## [Type stable generic memoisation](https://discourse.julialang.org/t/type-stable-generic-memoisation/96237)

<div class="topic-metadata">

**Author:** [@mhinsch](https://discourse.julialang.org/u/mhinsch)\
**Replies:** 23\
**Last updated:** [February 22, 2024, 10:06am UTC](https://discourse.julialang.org/t/type-stable-generic-memoisation/96237 "2024-02-22T10:06:57Z")

</div>

I’ve been looking into memoisation in Julia for a bit and although there are quite a few packages, as far as I tell all of them either store the results in some variation of Dict{Any, Any} or require you to commit to a s…

---

## [Help improving the speed of a DataFrames operation](https://discourse.julialang.org/t/help-improving-the-speed-of-a-dataframes-operation/107615)

<div class="topic-metadata">

**Author:** [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)\
**Replies:** 37\
**Last updated:** [February 22, 2024, 9:25am UTC](https://discourse.julialang.org/t/help-improving-the-speed-of-a-dataframes-operation/107615 "2024-02-22T09:25:18Z")

</div>

Hi all, quick question (hopefully) related to doing an operation on DataFrames. I am trying to improve the transformation below so any help would be great. More context and MWE are at the bottom. Thanks for all the hel…

---

## [Fastest approach to returning a vector of elements choose 2](https://discourse.julialang.org/t/fastest-approach-to-returning-a-vector-of-elements-choose-2/110494)

<div class="topic-metadata">

**Author:** [@narnold0](https://discourse.julialang.org/u/narnold0)\
**Replies:** 22\
**Last updated:** [February 22, 2024, 6:18am UTC](https://discourse.julialang.org/t/fastest-approach-to-returning-a-vector-of-elements-choose-2/110494 "2024-02-22T06:18:46Z")

</div>

Hi there. I’m trying to do the following, given a vector of elements, I wish to get the vector of tuples containing the elements choose 2, with the order of the tuples obviously not mattering. Importantly, I am trying t…

---

## [Zero allocated iterator for powersets](https://discourse.julialang.org/t/zero-allocated-iterator-for-powersets/110549)

<div class="topic-metadata">

**Author:** [@RobertGregg](https://discourse.julialang.org/u/RobertGregg)\
**Replies:** 0\
**Last updated:** [February 21, 2024, 10:36pm UTC](https://discourse.julialang.org/t/zero-allocated-iterator-for-powersets/110549 "2024-02-21T22:36:40Z")

</div>

Starting with the empty set, Gray codes can be used to determine the next element to add or remove so that you eventually hit every subset exactly once. Unfortunately, I’m having trouble creating an iterator for this set…

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

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