# Performance

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

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

**Page:** 44

---

## [Tracking the cause of allocation in the presence of a generated function](https://discourse.julialang.org/t/tracking-the-cause-of-allocation-in-the-presence-of-a-generated-function/98215)

<div class="topic-metadata">

**Author:** [@mateuszbaran](https://discourse.julialang.org/u/mateuszbaran)\
**Replies:** 1\
**Last updated:** [May 8, 2023, 2:04pm UTC](https://discourse.julialang.org/t/tracking-the-cause-of-allocation-in-the-presence-of-a-generated-function/98215 "2023-05-08T14:04:42Z")

</div>

I have some trouble tracking why the following code allocates: julia\> using HybridArrays, StaticArrays \[ Info: Precompiling HybridArrays \[1baab800-613f-4b0a-84e4-9cd3431bfbb9\] julia\> using BenchmarkTools julia\> H = Hy…

---

## [Performance of function with pre-allocated outputs](https://discourse.julialang.org/t/performance-of-function-with-pre-allocated-outputs/98457)

<div class="topic-metadata">

**Author:** [@jekyllstein](https://discourse.julialang.org/u/jekyllstein)\
**Replies:** 3\
**Last updated:** [May 8, 2023, 8:19am UTC](https://discourse.julialang.org/t/performance-of-function-with-pre-allocated-outputs/98457 "2023-05-08T08:19:37Z")

</div>

Consider the following mutating function that mutates a vector input: function f\_test!(xout::Vector{T}, a::T, b::T) where T \<: Real xout .= a .\* b view(xout, 1:max(1, lastindex(xout)-5)) .-= b return xout end I time…

---

## [Strange performance issue on 1.9.0-rc3](https://discourse.julialang.org/t/strange-performance-issue-on-1-9-0-rc3/98427)

<div class="topic-metadata">

**Author:** [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Replies:** 9\
**Last updated:** [May 7, 2023, 10:44pm UTC](https://discourse.julialang.org/t/strange-performance-issue-on-1-9-0-rc3/98427 "2023-05-07T22:44:34Z")

</div>

I’m seeing a weird performance issue related to the presence of an if-statement in my function, regardless of the if-statement being triggered or not. I can only reproduce this in 1.9.0, not earlier Julia versions. I ha…

---

## [Best practices for removing singleton dimension](https://discourse.julialang.org/t/best-practices-for-removing-singleton-dimension/98435)

<div class="topic-metadata">

**Author:** [@gaspardb](https://discourse.julialang.org/u/gaspardb)\
**Replies:** 3\
**Last updated:** [May 7, 2023, 1:30pm UTC](https://discourse.julialang.org/t/best-practices-for-removing-singleton-dimension/98435 "2023-05-07T13:30:31Z")

</div>

Hi! I often use reduction like sum or prod by specifying dimensions with the dims keyword argument. I’m wondering now how to get rid of the singleton dimension. Typically, if X is an array of size (1, n), we can do se…

---

## [Hard to find error (might relate to Zygote)](https://discourse.julialang.org/t/hard-to-find-error-might-relate-to-zygote/98421)

<div class="topic-metadata">

**Author:** [@erlebach](https://discourse.julialang.org/u/erlebach)\
**Replies:** 11\
**Last updated:** [May 6, 2023, 9:31pm UTC](https://discourse.julialang.org/t/hard-to-find-error-might-relate-to-zygote/98421 "2023-05-06T21:31:27Z")

</div>

@ChrisRackauckas Note the stack trace below. But first some comments: There is an error in the init(::Nothing, ::Tsit5...) function. I should be able to locate this Init function in the Julia library. I have not found …

---

## [Array could not broadcast to match destination in solve](https://discourse.julialang.org/t/array-could-not-broadcast-to-match-destination-in-solve/98397)

<div class="topic-metadata">

**Author:** [@erlebach](https://discourse.julialang.org/u/erlebach)\
**Replies:** 8\
**Last updated:** [May 6, 2023, 4:04pm UTC](https://discourse.julialang.org/t/array-could-not-broadcast-to-match-destination-in-solve/98397 "2023-05-06T16:04:55Z")

</div>

@ChrisRackauckas Here is a MWE solving a simple 3x3 equation, where I use the SizedVector from StaticArrays.jl: using DifferentialEquations using StaticArrays # Set up the Giesekus model function dudt!(du, σ, p, t) …

---

## [Using LoopVectorization with StructArrays](https://discourse.julialang.org/t/using-loopvectorization-with-structarrays/98154)

<div class="topic-metadata">

**Author:** [@DylanMMarques](https://discourse.julialang.org/u/DylanMMarques)\
**Replies:** 3\
**Last updated:** [May 6, 2023, 11:47am UTC](https://discourse.julialang.org/t/using-loopvectorization-with-structarrays/98154 "2023-05-06T11:47:21Z")

</div>

Hello, I am using LoopVectorization combined with StructArrays to vectorize some code that used structures. I have created a simple example of what I am trying to achive using the struct Point2D. using StructArrays, Lo…

---

## [Importing packages takes very long inside jupyter notebook](https://discourse.julialang.org/t/importing-packages-takes-very-long-inside-jupyter-notebook/98306)

<div class="topic-metadata">

**Author:** [@Optimization](https://discourse.julialang.org/u/Optimization)\
**Replies:** 7\
**Last updated:** [May 6, 2023, 9:07am UTC](https://discourse.julialang.org/t/importing-packages-takes-very-long-inside-jupyter-notebook/98306 "2023-05-06T09:07:42Z")

</div>

Hello, Is there any particular resoan that importing packages in Jupyter notebook takes quite a long time. Every time it takes somewhere around 7 minutes while when not working with jupyter the import only takes a few s…

---

## [Efficient way of creating a vector of length L with unique elements](https://discourse.julialang.org/t/efficient-way-of-creating-a-vector-of-length-l-with-unique-elements/98388)

<div class="topic-metadata">

**Author:** [@dm17017](https://discourse.julialang.org/u/dm17017)\
**Replies:** 3\
**Last updated:** [May 5, 2023, 4:45pm UTC](https://discourse.julialang.org/t/efficient-way-of-creating-a-vector-of-length-l-with-unique-elements/98388 "2023-05-05T16:45:31Z")

</div>

Hi, I am looking to fill a vector of a desired length up with randomly chosen, unique elements. Currently I have the code below which has the desired effect however, I suspect I can speed it up. If anyone has any ideas …

---

## [What is the most efficient way to compute the inverse of a sparse matrix?](https://discourse.julialang.org/t/what-is-the-most-efficient-way-to-compute-the-inverse-of-a-sparse-matrix/98167)

<div class="topic-metadata">

**Author:** [@schwob](https://discourse.julialang.org/u/schwob)\
**Replies:** 15\
**Last updated:** [May 5, 2023, 4:06pm UTC](https://discourse.julialang.org/t/what-is-the-most-efficient-way-to-compute-the-inverse-of-a-sparse-matrix/98167 "2023-05-05T16:06:57Z")

</div>

I have a sparse matrix Q that is a covariance matrix for a Gaussian Process. I need to invert Q for computations in Bayesian full-conditional distributions. For example, I need to compute terms like \\boldsymbol{\\beta}^T\\…

---

## [Struggling to get Julia as fast as Matlab mex. (Filling large matrix, doing pairwise calculations over particles)](https://discourse.julialang.org/t/struggling-to-get-julia-as-fast-as-matlab-mex-filling-large-matrix-doing-pairwise-calculations-over-particles/98379)

<div class="topic-metadata">

**Author:** [@p\_f](https://discourse.julialang.org/u/p_f)\
**Replies:** 7\
**Last updated:** [May 5, 2023, 3:31pm UTC](https://discourse.julialang.org/t/struggling-to-get-julia-as-fast-as-matlab-mex-filling-large-matrix-doing-pairwise-calculations-over-particles/98379 "2023-05-05T15:31:30Z")

</div>

I have a system with Ntot particles. I am creating a matrix Mh that is 6Ntot x 6Ntot and symmetric, and elements are given by pairwise calculations between particles. I’ve tried my best to speed up my Julia code, but fe…

---

## [Why does it make allocation when using tuples parameters in closure?](https://discourse.julialang.org/t/why-does-it-make-allocation-when-using-tuples-parameters-in-closure/98369)

<div class="topic-metadata">

**Author:** [@wly](https://discourse.julialang.org/u/wly)\
**Replies:** 3\
**Last updated:** [May 5, 2023, 8:32am UTC](https://discourse.julialang.org/t/why-does-it-make-allocation-when-using-tuples-parameters-in-closure/98369 "2023-05-05T08:32:00Z")

</div>

The following code have some allocation: using BenchmarkTools function memoize\_test(n\_outputs) function foo\_i(i::Int64, u...) end return \[(u...) -\> foo\_i(i, u...) for i in 1:n\_outputs\] end fun = memoize\_te…

---

## [How to efficiently save and read dictionaries in Julia?](https://discourse.julialang.org/t/how-to-efficiently-save-and-read-dictionaries-in-julia/98337)

<div class="topic-metadata">

**Author:** [@F\_A](https://discourse.julialang.org/u/F_A)\
**Replies:** 3\
**Last updated:** [May 4, 2023, 7:02pm UTC](https://discourse.julialang.org/t/how-to-efficiently-save-and-read-dictionaries-in-julia/98337 "2023-05-04T19:02:43Z")

</div>

Hi, I’d like to save a dictionary to a file with more than 12500 entries. I’ve read some suggestion here and here. But I was wondering whether these are the most efficient way to do so? Thanks a lot.

---

## [Early exit from Threads.@threads](https://discourse.julialang.org/t/early-exit-from-threads-threads/98267)

<div class="topic-metadata">

**Author:** [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Replies:** 0\
**Last updated:** [May 3, 2023, 6:08pm UTC](https://discourse.julialang.org/t/early-exit-from-threads-threads/98267 "2023-05-03T18:08:22Z")

</div>

So I think I follow how Threads.@threads works in typical cases. I.e. this pattern: Threads.@threads for i = 1:N something(i) end where the something(i) will be called N times with concurrency by being scheduled to, …

---

## [Error saving MCMC Chain](https://discourse.julialang.org/t/error-saving-mcmc-chain/98225)

<div class="topic-metadata">

**Author:** [@ALIAN\_LI\_MARTIN](https://discourse.julialang.org/u/ALIAN_LI_MARTIN)\
**Replies:** 0\
**Last updated:** [May 3, 2023, 1:04am UTC](https://discourse.julialang.org/t/error-saving-mcmc-chain/98225 "2023-05-03T01:04:03Z")

</div>

Hello, I have an error when saving the MCMC strings. Could someone help me with this problem. Thank you so much. MethodError: no method matching write(::IOStream, ::Chains{Float64, AxisArrays.AxisArray{Float64, 3, Array…

---

## [Compiler Can't Optimize Away Unnecessary Memory Allocs with Convenience Variables](https://discourse.julialang.org/t/compiler-cant-optimize-away-unnecessary-memory-allocs-with-convenience-variables/98045)

<div class="topic-metadata">

**Author:** [@ejmeitz](https://discourse.julialang.org/u/ejmeitz)\
**Replies:** 14\
**Last updated:** [May 3, 2023, 12:09am UTC](https://discourse.julialang.org/t/compiler-cant-optimize-away-unnecessary-memory-allocs-with-convenience-variables/98045 "2023-05-03T00:09:58Z")

</div>

I have code doing some broadcasted operations and it takes ~2 microseconds which is great ΔU2 += sum((Δuᵢ .\* u .\* @view F2\[:,i\]) .+ (Δuⱼ .\* u .\* @view F2\[:,j\]) .+ (Δuₖ .\* u .\* @view F2\[:,k\])) However, this is entirely …

---

## [Evaluating a MvNormal density with a sparse covariance matrix](https://discourse.julialang.org/t/evaluating-a-mvnormal-density-with-a-sparse-covariance-matrix/98173)

<div class="topic-metadata">

**Author:** [@schwob](https://discourse.julialang.org/u/schwob)\
**Replies:** 1\
**Last updated:** [May 1, 2023, 9:09pm UTC](https://discourse.julialang.org/t/evaluating-a-mvnormal-density-with-a-sparse-covariance-matrix/98173 "2023-05-01T21:09:55Z")

</div>

Suppose that Q is a sparse covariance matrix, and I want to evaluate \\mathbf{y} \\sim N(\\boldsymbol{0},Q). Can I leverage the sparsity of Q? Right now, I have Q as a SparseMatrixCSC{Float64, Int64}. Roughly 97% of the mat…

---

## [Is there a faster alternative to \`hcat(xx...)\`?](https://discourse.julialang.org/t/is-there-a-faster-alternative-to-hcat-xx/98112)

<div class="topic-metadata">

**Author:** [@\_stla](https://discourse.julialang.org/u/_stla)\
**Replies:** 16\
**Last updated:** [April 30, 2023, 12:01pm UTC](https://discourse.julialang.org/t/is-there-a-faster-alternative-to-hcat-xx/98112 "2023-04-30T12:01:27Z")

</div>

Hello, I have this piece of code in a function: triangles = Matrix{Int}(undef, 3, 0) for i in 1:ntriangles a, b, c = triangle = ∂₂₀(i) nkeep = tokeep\[a\] + tokeep\[b\] + tokeep\[c\] if nkeep \> 0 push!(…

---

## [Multithreading broadcast/map calls](https://discourse.julialang.org/t/multithreading-broadcast-map-calls/97956)

<div class="topic-metadata">

**Author:** [@bmit](https://discourse.julialang.org/u/bmit)\
**Replies:** 7\
**Last updated:** [April 30, 2023, 1:34am UTC](https://discourse.julialang.org/t/multithreading-broadcast-map-calls/97956 "2023-04-30T01:34:38Z")

</div>

I’m working on improving the performance of code and one simple step is making broadcast calls multithreaded. After seeing that Threads.@threads macro doesn’t work for broadcast lines, I started converting code like b …

---

## [Optimizing Direct 1D Convolution Code](https://discourse.julialang.org/t/optimizing-direct-1d-convolution-code/97658)

<div class="topic-metadata">

**Author:** [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Replies:** 21\
**Last updated:** [April 28, 2023, 2:53pm UTC](https://discourse.julialang.org/t/optimizing-direct-1d-convolution-code/97658 "2023-04-28T14:53:46Z")

</div>

I am trying to create a function for a direct (Not fft() based) 1D convolution. Originally I used the classic implementation: using BenchmarkTools; function \_Conv1D!( vO :: Array{T, 1}, vA :: Array{T, 1}, vB :: Array{…

---

## [Fail to deploy from Documenter to GITHUB](https://discourse.julialang.org/t/fail-to-deploy-from-documenter-to-github/98021)

<div class="topic-metadata">

**Author:** [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Replies:** 14\
**Last updated:** [April 28, 2023, 10:44am UTC](https://discourse.julialang.org/t/fail-to-deploy-from-documenter-to-github/98021 "2023-04-28T10:44:09Z")

</div>

I am working on Muscade.jl (work in progress!), and I have a first incomplete documentation I wish to deploy. Everything works fine… except I get a 404. Here is the dump: My repo structure includes Muscade docs …

---

## [Octavian Matmul slow in for loop](https://discourse.julialang.org/t/octavian-matmul-slow-in-for-loop/98030)

<div class="topic-metadata">

**Author:** [@c\_sell](https://discourse.julialang.org/u/c_sell)\
**Replies:** 0\
**Last updated:** [April 28, 2023, 9:19am UTC](https://discourse.julialang.org/t/octavian-matmul-slow-in-for-loop/98030 "2023-04-28T09:19:13Z")

</div>

Hey. I want to use octavian matmul in a foor loop. However, the code gets around 10 times slower in the loop. using BenchmarkTools using LinearAlgebra using LoopVectorization struct cust\_Dense W :: Array{Float32,2} …

---

## [Broadcast function performance of Julia vs Numpy vs Nd4J](https://discourse.julialang.org/t/broadcast-function-performance-of-julia-vs-numpy-vs-nd4j/98007)

<div class="topic-metadata">

**Author:** [@Vyacheslav\_Vorobyov](https://discourse.julialang.org/u/Vyacheslav_Vorobyov)\
**Replies:** 12\
**Last updated:** [April 28, 2023, 6:39am UTC](https://discourse.julialang.org/t/broadcast-function-performance-of-julia-vs-numpy-vs-nd4j/98007 "2023-04-28T06:39:09Z")

</div>

Hi everybody! Recently suddenly faced the fact, that in Julia, applying function to a matrix a bit(but consistently) slower than in Numpy(Python) or Nd4J(Java), and that was a bit surprised me because I believe all usin…

---

## [Julia slower than Python to sort and reverse a list of integers](https://discourse.julialang.org/t/julia-slower-than-python-to-sort-and-reverse-a-list-of-integers/97453)

<div class="topic-metadata">

**Author:** [@lucasmsoares96](https://discourse.julialang.org/u/lucasmsoares96)\
**Replies:** 40\
**Last updated:** [April 28, 2023, 4:42am UTC](https://discourse.julialang.org/t/julia-slower-than-python-to-sort-and-reverse-a-list-of-integers/97453 "2023-04-28T04:42:38Z")

</div>

My goal is to compare Julia’s performance against other languages like Python, Scala and Rust to perform some simple tasks. My first task was to sort an array of 999999 integers read from a text file. The code below run…

---

## [How to speed up LoopVectorized code - 3x slower than C++ code](https://discourse.julialang.org/t/how-to-speed-up-loopvectorized-code-3x-slower-than-c-code/96440)

<div class="topic-metadata">

**Author:** [@Zentrik](https://discourse.julialang.org/u/Zentrik)\
**Replies:** 19\
**Last updated:** [April 27, 2023, 5:35pm UTC](https://discourse.julialang.org/t/how-to-speed-up-loopvectorized-code-3x-slower-than-c-code/96440 "2023-04-27T17:35:52Z")

</div>

using StaticArrays, Parameters, LinearAlgebra, BenchmarkTools, StructArrays, LoopVectorization const T = Float32 const Point = SVector{3, T} @with\_kw struct Ray @deftype Point origin = zeros(Point) direction = …

---

## [Improve type inference in iterating over \`Eigen\`](https://discourse.julialang.org/t/improve-type-inference-in-iterating-over-eigen/97987)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 5\
**Last updated:** [April 27, 2023, 11:26am UTC](https://discourse.julialang.org/t/improve-type-inference-in-iterating-over-eigen/97987 "2023-04-27T11:26:15Z")

</div>

In the following example: julia\> @code\_warntype (A -\> ((λ,v) = eigen(A); (λ,v)))(rand(2,2)) MethodInstance for (::var"#19#20")(::Matrix{Float64}) from (::var"#19#20")(A) @ Main REPL\[14\]:1 Arguments #self#::Core.Cons…

---

## [Collecting Base.Broadcast.Broadcasted](https://discourse.julialang.org/t/collecting-base-broadcast-broadcasted/97933)

<div class="topic-metadata">

**Author:** [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Replies:** 2\
**Last updated:** [April 26, 2023, 9:59am UTC](https://discourse.julialang.org/t/collecting-base-broadcast-broadcasted/97933 "2023-04-26T09:59:51Z")

</div>

when overloading broadcasted() one may sometimes want to call collect. However, this seems to not remember the size: julia\> a = reshape(1:100,(10,10)) 10×10 reshape(::UnitRange{Int64}, 10, 10) with eltype Int64: 1 11…

---

## [Precompiling LanguageServer.runserver() with PrecompileTools.jl](https://discourse.julialang.org/t/precompiling-languageserver-runserver-with-precompiletools-jl/97926)

<div class="topic-metadata">

**Author:** [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Replies:** 0\
**Last updated:** [April 26, 2023, 3:39am UTC](https://discourse.julialang.org/t/precompiling-languageserver-runserver-with-precompiletools-jl/97926 "2023-04-26T03:39:14Z")

</div>

After a conversation on Slack, with Tom McLaughlin, I decided to try adding some precompilation to LanguageServer.jl. Tom had noticed about 10 second lag in the execution of LanguageServer.runserver(). This is part of j…

---

## [Redefining a single function broadcast rule?](https://discourse.julialang.org/t/redefining-a-single-function-broadcast-rule/97890)

<div class="topic-metadata">

**Author:** [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Replies:** 2\
**Last updated:** [April 25, 2023, 10:01am UTC](https://discourse.julialang.org/t/redefining-a-single-function-broadcast-rule/97890 "2023-04-25T10:01:01Z")

</div>

I would like to redefine a single broadcast rule relating to the coalesce. broadcast. The reason is that the ShiftedArray type can return missing or nothing for out-of-bound shifted access. If the user uses coalesce.(my…

---

## [Calling Julia program from C and avoiding recompiling](https://discourse.julialang.org/t/calling-julia-program-from-c-and-avoiding-recompiling/97800)

<div class="topic-metadata">

**Author:** [@mb96](https://discourse.julialang.org/u/mb96)\
**Replies:** 2\
**Last updated:** [April 24, 2023, 9:44pm UTC](https://discourse.julialang.org/t/calling-julia-program-from-c-and-avoiding-recompiling/97800 "2023-04-24T21:44:34Z")

</div>

Hi! I am planning on calling my Julia programs from my C script where the calling will have to be done many times. However, I am worried about whether this will mean having to recompile the functions all the time as if …

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

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