# Performance

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

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

**Page:** 24

---

## [Type instabilities when dealing with structs and Ref](https://discourse.julialang.org/t/type-instabilities-when-dealing-with-structs-and-ref/115122)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 4\
**Last updated:** [June 3, 2024, 9:35pm UTC](https://discourse.julialang.org/t/type-instabilities-when-dealing-with-structs-and-ref/115122 "2024-06-03T21:35:07Z")

</div>

Hello, I’m facing type instabilities with a struct containing a Ref value. Here I show a minimal example struct Prova{T1\<:Integer} a::Ref{T1} function Prova(a::T1) where {T1} new{T1}(Ref(a)) end end…

---

## [Type inference when just making a tuple](https://discourse.julialang.org/t/type-inference-when-just-making-a-tuple/115071)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 6\
**Last updated:** [June 2, 2024, 9:16pm UTC](https://discourse.julialang.org/t/type-inference-when-just-making-a-tuple/115071 "2024-06-02T21:16:42Z")

</div>

Hello, I’m seeing some type instabilities in my code. I saw that converting a vector into a tuple generates instabilities. Here a very simple example using Test function prova(vec) return Tuple(vec) end T = Floa…

---

## [Help optimise an advice implementation](https://discourse.julialang.org/t/help-optimise-an-advice-implementation/97218)

<div class="topic-metadata">

**Author:** [@tecosaur](https://discourse.julialang.org/u/tecosaur)\
**Replies:** 12\
**Last updated:** [June 2, 2024, 3:30am UTC](https://discourse.julialang.org/t/help-optimise-an-advice-implementation/97218 "2024-06-02T03:30:14Z")

</div>

Hello, in my DataToolkitBase.jl I make extensive use of advised functions, e.g. instead of identity(x) I’ll have @advise identity(x) As such, I’m very interested in minimising the performance impact of advised calls.…

---

## [Type Inference Inferring Any for function that returns Float64](https://discourse.julialang.org/t/type-inference-inferring-any-for-function-that-returns-float64/115007)

<div class="topic-metadata">

**Author:** [@BenCichos](https://discourse.julialang.org/u/BenCichos)\
**Replies:** 11\
**Last updated:** [June 1, 2024, 6:21am UTC](https://discourse.julialang.org/t/type-inference-inferring-any-for-function-that-returns-float64/115007 "2024-06-01T06:21:45Z")

</div>

Hello everyone, I am currently trying to code an Optical Ray Tracing package in Julia, and while trying to optimise the code for performance I ran into some issues that the function trace that performs the tracing does a…

---

## [Failure to vectorize 8 Int64 multiplies when 8 Float64 multiplies vectorize](https://discourse.julialang.org/t/failure-to-vectorize-8-int64-multiplies-when-8-float64-multiplies-vectorize/114939)

<div class="topic-metadata">

**Author:** [@brainandforce](https://discourse.julialang.org/u/brainandforce)\
**Replies:** 8\
**Last updated:** [May 31, 2024, 11:52pm UTC](https://discourse.julialang.org/t/failure-to-vectorize-8-int64-multiplies-when-8-float64-multiplies-vectorize/114939 "2024-05-31T23:52:39Z")

</div>

I’ve come across this interesting observation in my package, CliffordNumbers.jl. For context, the multiplication done here is a geometric product (relevant code here) implemented as a grid multiply between blade coeffici…

---

## [Performance optimizations with runtime dispatch](https://discourse.julialang.org/t/performance-optimizations-with-runtime-dispatch/110653)

<div class="topic-metadata">

**Author:** [@aramend](https://discourse.julialang.org/u/aramend)\
**Replies:** 14\
**Last updated:** [May 30, 2024, 8:01pm UTC](https://discourse.julialang.org/t/performance-optimizations-with-runtime-dispatch/110653 "2024-05-30T20:01:06Z")

</div>

I’m working on types that efficiently wrap polish notation and allow for fast evaluation of mathematical expressions. If I run @profview on the following script, I see that most of the time inside fpass! is spent decidin…

---

## [Slow numerical integration of scalar function](https://discourse.julialang.org/t/slow-numerical-integration-of-scalar-function/114976)

<div class="topic-metadata">

**Author:** [@golanor](https://discourse.julialang.org/u/golanor)\
**Replies:** 1\
**Last updated:** [May 30, 2024, 5:16pm UTC](https://discourse.julialang.org/t/slow-numerical-integration-of-scalar-function/114976 "2024-05-30T17:16:24Z")

</div>

Hi, I’m trying to compute a set of integrals, and the integration takes a lot of time and allocates a lot. Is there a way to speed it up? MWE: using Integrals, BenchmarkTools const ω1, ω2 = 33.807, 37.822; const Ω1, …

---

## [Most efficient implementation of covariance matrix](https://discourse.julialang.org/t/most-efficient-implementation-of-covariance-matrix/114797)

<div class="topic-metadata">

**Author:** [@Salmon](https://discourse.julialang.org/u/Salmon)\
**Replies:** 12\
**Last updated:** [May 28, 2024, 10:26pm UTC](https://discourse.julialang.org/t/most-efficient-implementation-of-covariance-matrix/114797 "2024-05-28T22:26:57Z")

</div>

Hi everyone, I was computing some rather large covariance matrices and noticed that that implementation in Statistics is not multithreaded. TLDR, I want the following to be as fast as possible (ideally, for even larger …

---

## [Changing a "constant" type and triggering recompilation](https://discourse.julialang.org/t/changing-a-constant-type-and-triggering-recompilation/114844)

<div class="topic-metadata">

**Author:** [@RGonTheNoble](https://discourse.julialang.org/u/RGonTheNoble)\
**Replies:** 5\
**Last updated:** [May 28, 2024, 9:59pm UTC](https://discourse.julialang.org/t/changing-a-constant-type-and-triggering-recompilation/114844 "2024-05-28T21:59:25Z")

</div>

I’m writing a calculation engine that is going to run as a service. This is for an industrial system, where data sources (tags) have units. Because many of these units have offsests (Fahrenheit, PSI-gauge) I can’t use Dy…

---

## [Create an indexed line from a vector](https://discourse.julialang.org/t/create-an-indexed-line-from-a-vector/114783)

<div class="topic-metadata">

**Author:** [@Ju\_ska](https://discourse.julialang.org/u/Ju_ska)\
**Replies:** 6\
**Last updated:** [May 28, 2024, 5:43pm UTC](https://discourse.julialang.org/t/create-an-indexed-line-from-a-vector/114783 "2024-05-28T17:43:11Z")

</div>

Hi, I would like to take a vector like: julia\> vector 5-element Vector{Float64}: 90.51 51.79 84.81 66.11 56.68 and output "0" "1:90.51" "2:51.79" "3:84.81" "4:66.11" "5:56.68" that will be written into a …

---

## [Improving speed of runtime dispatch detector](https://discourse.julialang.org/t/improving-speed-of-runtime-dispatch-detector/114697)

<div class="topic-metadata">

**Author:** [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Replies:** 63\
**Last updated:** [May 28, 2024, 8:29am UTC](https://discourse.julialang.org/t/improving-speed-of-runtime-dispatch-detector/114697 "2024-05-28T08:29:52Z")

</div>

I’m working on this small package DispatchDoctor – GitHub - MilesCranmer/DispatchDoctor.jl which helps to address some of the issues discussed in this thread. This package provides the @stable macro as a more ergonomic …

---

## [Examples of when to use @async over @spawn?](https://discourse.julialang.org/t/examples-of-when-to-use-async-over-spawn/114631)

<div class="topic-metadata">

**Author:** [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Replies:** 8\
**Last updated:** [May 28, 2024, 2:26am UTC](https://discourse.julialang.org/t/examples-of-when-to-use-async-over-spawn/114631 "2024-05-28T02:26:17Z")

</div>

I’m trying to figure out if there’s ever a good reason to use @async over Threads.@spawn anymore. It seems like you want Threads.@spawn the vast majority of the time – it’s more composable, gives more freedom to the sch…

---

## [Static mixed type mutable vector - programmatic access?](https://discourse.julialang.org/t/static-mixed-type-mutable-vector-programmatic-access/114768)

<div class="topic-metadata">

**Author:** [@aramend](https://discourse.julialang.org/u/aramend)\
**Replies:** 0\
**Last updated:** [May 27, 2024, 8:55am UTC](https://discourse.julialang.org/t/static-mixed-type-mutable-vector-programmatic-access/114768 "2024-05-27T08:55:23Z")

</div>

I created an interesting structure for my use case. I managed to get everything nice and static, but I’m having trouble using it programmatically. Here are my goals and how they guided the design. Iterate tens of thous…

---

## [Package to avoid allocations in some functions when using StaticArrays.jl](https://discourse.julialang.org/t/package-to-avoid-allocations-in-some-functions-when-using-staticarrays-jl/114539)

<div class="topic-metadata">

**Author:** [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Replies:** 18\
**Last updated:** [May 25, 2024, 2:54pm UTC](https://discourse.julialang.org/t/package-to-avoid-allocations-in-some-functions-when-using-staticarrays-jl/114539 "2024-05-25T14:54:53Z")

</div>

Hi! As I mentioned before, I am trying to build a full satellite attitude control subsystem (ACS) using Julia, which maybe one day will hopefully fly in a CubeSat. One very important requirement is to avoid runtime allo…

---

## [Allocations in sparse matrices](https://discourse.julialang.org/t/allocations-in-sparse-matrices/114540)

<div class="topic-metadata">

**Author:** [@clopen](https://discourse.julialang.org/u/clopen)\
**Replies:** 6\
**Last updated:** [May 24, 2024, 8:45pm UTC](https://discourse.julialang.org/t/allocations-in-sparse-matrices/114540 "2024-05-24T20:45:38Z")

</div>

Hello, I have a code where I use ‘normal’ (Array{Float64,2 } type) matrices and SparseMatrixCSC{Float64} matrices. Lets say A::SparseMatrixCSC{Float64} = sparse(1.0I, 100, 100) a::Float64 = 2.0 If I create other matric…

---

## [Compilation latency with constant propagation and unreachable branches](https://discourse.julialang.org/t/compilation-latency-with-constant-propagation-and-unreachable-branches/114667)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 7\
**Last updated:** [May 24, 2024, 2:44pm UTC](https://discourse.julialang.org/t/compilation-latency-with-constant-propagation-and-unreachable-branches/114667 "2024-05-24T14:44:46Z")

</div>

With julia\> function f(a, b) if a == 1 return b \* b elseif a == 2 return b \* b' elseif a == 3 return b' \* b else re…

---

## [How does constant propagation impact latency with a Val-based dispatch?](https://discourse.julialang.org/t/how-does-constant-propagation-impact-latency-with-a-val-based-dispatch/114545)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 0\
**Last updated:** [May 22, 2024, 5:49am UTC](https://discourse.julialang.org/t/how-does-constant-propagation-impact-latency-with-a-val-based-dispatch/114545 "2024-05-22T05:49:57Z")

</div>

The example here is schematic, and isn’t really an MWE. Suppose I have a set of functions like f() = f('A') Base.@constprop :aggressive f(a, args...) = g(Val(a == 'A'), args...) Base.@constprop :aggressive g(::Val{true…

---

## [Is there a \`CartesianIndex\` using \`Int32\`?](https://discourse.julialang.org/t/is-there-a-cartesianindex-using-int32/114468)

<div class="topic-metadata">

**Author:** [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Replies:** 8\
**Last updated:** [May 20, 2024, 12:18pm UTC](https://discourse.julialang.org/t/is-there-a-cartesianindex-using-int32/114468 "2024-05-20T12:18:15Z")

</div>

The definition in Julia base/multidimensional.jl is restricted to Int64 struct CartesianIndex{N} \<: AbstractCartesianIndex{N} I::NTuple{N,Int} CartesianIndex{N}(index::NTuple{N,Integer}) where {N} = new(in…

---

## [DataFrame transformation is so slow, what am I doing wrong?](https://discourse.julialang.org/t/dataframe-transformation-is-so-slow-what-am-i-doing-wrong/114430)

<div class="topic-metadata">

**Author:** [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Replies:** 17\
**Last updated:** [May 19, 2024, 2:41pm UTC](https://discourse.julialang.org/t/dataframe-transformation-is-so-slow-what-am-i-doing-wrong/114430 "2024-05-19T14:41:29Z")

</div>

I want to do a transformation which may depends on a large number of columns. The MWE & benchmark codes: using DataFrames df = DataFrame(rand(10, 50), :auto) cols = propertynames(df) # due to the design of my actual c…

---

## [Is there a quicker way to obtain normalized multivariate random normal draws?](https://discourse.julialang.org/t/is-there-a-quicker-way-to-obtain-normalized-multivariate-random-normal-draws/114411)

<div class="topic-metadata">

**Author:** [@schwob](https://discourse.julialang.org/u/schwob)\
**Replies:** 15\
**Last updated:** [May 18, 2024, 3:33pm UTC](https://discourse.julialang.org/t/is-there-a-quicker-way-to-obtain-normalized-multivariate-random-normal-draws/114411 "2024-05-18T15:33:39Z")

</div>

I want to make n random draws from a Multivariate Normal distribution, then divide each element in each of the random draws by the norm of the random draw. Mathematically, I want to obtain \\mathbf{y}\_i=\\mathbf{x}\_i/||\\ma…

---

## [Speeding up evaluation of small exponential-like series](https://discourse.julialang.org/t/speeding-up-evaluation-of-small-exponential-like-series/114314)

<div class="topic-metadata">

**Author:** [@isaacsas](https://discourse.julialang.org/u/isaacsas)\
**Replies:** 19\
**Last updated:** [May 17, 2024, 11:07pm UTC](https://discourse.julialang.org/t/speeding-up-evaluation-of-small-exponential-like-series/114314 "2024-05-17T23:07:08Z")

</div>

I have an application where the following function to evaluate an exponential-like series is called many times for different p vectors (the last two inputs are fixed), and takes a good portion of the running time. I was …

---

## [Operation on transpose sparse array is slow](https://discourse.julialang.org/t/operation-on-transpose-sparse-array-is-slow/114330)

<div class="topic-metadata">

**Author:** [@tiZ](https://discourse.julialang.org/u/tiZ)\
**Replies:** 1\
**Last updated:** [May 15, 2024, 11:50pm UTC](https://discourse.julialang.org/t/operation-on-transpose-sparse-array-is-slow/114330 "2024-05-15T23:50:13Z")

</div>

Hi Friends, I am searching for a better solution for speed up my script, my script accept a sparse matrix as input, (some time the sparse matrix is sample X features, and sometimes it is features X sample), I have to tr…

---

## [Matrix handling in memory](https://discourse.julialang.org/t/matrix-handling-in-memory/114258)

<div class="topic-metadata">

**Author:** [@MatheusJanczkowski](https://discourse.julialang.org/u/MatheusJanczkowski)\
**Replies:** 15\
**Last updated:** [May 15, 2024, 3:57pm UTC](https://discourse.julialang.org/t/matrix-handling-in-memory/114258 "2024-05-15T15:57:15Z")

</div>

I have a code that is divided in three parts: pre-processing, iterative scheme, and post-processing. In the pre-processing, it calculates a matrix (that can be very large); but it won’t be used in the iterative scheme, w…

---

## [Poor BigInt performance](https://discourse.julialang.org/t/poor-bigint-performance/106907)

<div class="topic-metadata">

**Author:** [@hlbnet](https://discourse.julialang.org/u/hlbnet)\
**Replies:** 32\
**Last updated:** [May 14, 2024, 11:36am UTC](https://discourse.julialang.org/t/poor-bigint-performance/106907 "2024-05-14T11:36:38Z")

</div>

Hi everybody, I wanted to quick benchmark the BigInt type. I wrote a simple function (with double reccursion just because I want to consume time :wink:). I then tested the same function in Python, and found that Python …

---

## [ForwardDiff.hessian! with StaticArrays, unexpected allocations and performance](https://discourse.julialang.org/t/forwarddiff-hessian-with-staticarrays-unexpected-allocations-and-performance/114082)

<div class="topic-metadata">

**Author:** [@DNF](https://discourse.julialang.org/u/DNF)\
**Replies:** 4\
**Last updated:** [May 13, 2024, 9:59am UTC](https://discourse.julialang.org/t/forwarddiff-hessian-with-staticarrays-unexpected-allocations-and-performance/114082 "2024-05-13T09:59:23Z")

</div>

I am struggling with allocations and performance when calculating Hessians with ForwardDiff.jl. Here’s an MWE using a clean REPL with Julia 1.10.3 julia\> using DiffResults, ForwardDiff, StaticArrays, BenchmarkTools jul…

---

## [Sound use of multiple dispatch?](https://discourse.julialang.org/t/sound-use-of-multiple-dispatch/114093)

<div class="topic-metadata">

**Author:** [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Replies:** 18\
**Last updated:** [May 13, 2024, 8:04am UTC](https://discourse.julialang.org/t/sound-use-of-multiple-dispatch/114093 "2024-05-13T08:04:20Z")

</div>

Is the code below a sound use of multiple dispatch? Are there cleaner or more sound ways to the same? using StaticArrays const Point1D = SVector{1,Float64} const Point2D = SVector{2,Float64} " Generates a one-dimensi…

---

## [Zygote differentiation very slow](https://discourse.julialang.org/t/zygote-differentiation-very-slow/112751)

<div class="topic-metadata">

**Author:** [@KapilKhanal](https://discourse.julialang.org/u/KapilKhanal)\
**Replies:** 13\
**Last updated:** [May 12, 2024, 11:39pm UTC](https://discourse.julialang.org/t/zygote-differentiation-very-slow/112751 "2024-05-12T23:39:39Z")

</div>

I have an inner function I apply like this (a simple replicable example pasted here) . The input are chosen to be (5,5) but they are usually much larger. I did not do benchmark as this is not even close to acceptable. It…

---

## [Why is flux model slower than python?](https://discourse.julialang.org/t/why-is-flux-model-slower-than-python/54154)

<div class="topic-metadata">

**Author:** [@mdsa3d](https://discourse.julialang.org/u/mdsa3d)\
**Replies:** 6\
**Last updated:** [May 11, 2024, 2:50pm UTC](https://discourse.julialang.org/t/why-is-flux-model-slower-than-python/54154 "2024-05-11T14:50:44Z")

</div>

I ran a benchmark test to observe the performance gain using flux. But, rather I observed that the flux runtine is longer than python equivalent. However, the julia is supposed to be faster. May I know, what am I doing …

---

## [Why does an iterator with a vector as state variable allocate?](https://discourse.julialang.org/t/why-does-an-iterator-with-a-vector-as-state-variable-allocate/114128)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 8\
**Last updated:** [May 11, 2024, 1:22pm UTC](https://discourse.julialang.org/t/why-does-an-iterator-with-a-vector-as-state-variable-allocate/114128 "2024-05-11T13:22:24Z")

</div>

Here is an example of a phenomenon that I have noticed more than once: The following type C uses a Vector as state variable for iterate. This of course needs one allocation at the beginning of the iteration. However, the…

---

## [Fastest way to save a large number of DataFrames to disk](https://discourse.julialang.org/t/fastest-way-to-save-a-large-number-of-dataframes-to-disk/114005)

<div class="topic-metadata">

**Author:** [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Replies:** 2\
**Last updated:** [May 10, 2024, 12:07pm UTC](https://discourse.julialang.org/t/fastest-way-to-save-a-large-number-of-dataframes-to-disk/114005 "2024-05-10T12:07:51Z")

</div>

I have a large number of dataframes generated from other sources like using DataFrames N = 1000 df\_dict = Dict(1:N .=\> \[DataFrame(rand(rand(1000:2000), 146), :auto) for \_ in 1:N\]) I’d like to save them into a single fi…

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

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