# Performance

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

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

**Page:** 18

---

## [Parallelized calls to Optim.optimize use the same number of threads as a single threaded call](https://discourse.julialang.org/t/parallelized-calls-to-optim-optimize-use-the-same-number-of-threads-as-a-single-threaded-call/121388)

<div class="topic-metadata">

**Author:** [@adannenberg](https://discourse.julialang.org/u/adannenberg)\
**Replies:** 4\
**Last updated:** [October 16, 2024, 4:56pm UTC](https://discourse.julialang.org/t/parallelized-calls-to-optim-optimize-use-the-same-number-of-threads-as-a-single-threaded-call/121388 "2024-10-16T16:56:18Z")

</div>

To investigate how sample size affects uncertainty in parameter inference, I do something like: Θ\_example = something #Θ is a vector of the parameters I'm trying to infer Θvec = zeros(numSamples, size(Θ\_example)) for …

---

## [PythonCall spends a lot of time showing stuff for JAX](https://discourse.julialang.org/t/pythoncall-spends-a-lot-of-time-showing-stuff-for-jax/121346)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 3\
**Last updated:** [October 15, 2024, 8:59pm UTC](https://discourse.julialang.org/t/pythoncall-spends-a-lot-of-time-showing-stuff-for-jax/121346 "2024-10-15T20:59:43Z")

</div>

Hi everyone, especially @cjdoris! I’m trying to call JAX from Julia and I find that PythonCall.jl has a lot of overhead in a simple conversion case due to… printing? Has anyone run into the same issue? Setup code: usi…

---

## [Memory allocations when performing operation on Tuple of structs](https://discourse.julialang.org/t/memory-allocations-when-performing-operation-on-tuple-of-structs/121276)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 9\
**Last updated:** [October 15, 2024, 10:18am UTC](https://discourse.julialang.org/t/memory-allocations-when-performing-operation-on-tuple-of-structs/121276 "2024-10-15T10:18:31Z")

</div>

Hello, I’m facing a memory allocation problem on an apparently simple case. I have the following struct struct MyStruct{T1\<:AbstractMatrix, T2} data::T1 other::T2 end where data is a matrix and other is someth…

---

## [Near positive definite (NearPD) of a symmetric matrix in Julia](https://discourse.julialang.org/t/near-positive-definite-nearpd-of-a-symmetric-matrix-in-julia/45793)

<div class="topic-metadata">

**Author:** [@Kokora](https://discourse.julialang.org/u/Kokora)\
**Replies:** 9\
**Last updated:** [October 15, 2024, 7:57am UTC](https://discourse.julialang.org/t/near-positive-definite-nearpd-of-a-symmetric-matrix-in-julia/45793 "2024-10-15T07:57:21Z")

</div>

Hi all, Is there a package in Julia which can be used to find a near positive definite matrix to a symmetric matrix? In R there is a function nearPD that I can use or the function LaplacesDemon::as.positive.definite. T…

---

## [A wrapper of two functions takes longer time to execute](https://discourse.julialang.org/t/a-wrapper-of-two-functions-takes-longer-time-to-execute/121270)

<div class="topic-metadata">

**Author:** [@jsjie](https://discourse.julialang.org/u/jsjie)\
**Replies:** 4\
**Last updated:** [October 15, 2024, 2:25am UTC](https://discourse.julialang.org/t/a-wrapper-of-two-functions-takes-longer-time-to-execute/121270 "2024-10-15T02:25:42Z")

</div>

I’m debugging a complex program within infiltrator, and this is the log: infil\> @inline function my\_set!(ψ\_sm, ψ, atomic) sm = atomic.sub\_mesh np = sm.np\_local @inbounds @simd for i\_p = …

---

## [Performance issue with Vectors vs. 1 Column Matrices](https://discourse.julialang.org/t/performance-issue-with-vectors-vs-1-column-matrices/121240)

<div class="topic-metadata">

**Author:** [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Replies:** 8\
**Last updated:** [October 13, 2024, 7:36pm UTC](https://discourse.julialang.org/t/performance-issue-with-vectors-vs-1-column-matrices/121240 "2024-10-13T19:36:38Z")

</div>

Buried inside a for loop of mine, I have a function which, morally, looks like: function f!(a,b) @. a = b; a end It gets used inside the for loop like: # construct vector x of length nx # construct vector y of len…

---

## [Optimize Apache Arrow data streaming over HTTP](https://discourse.julialang.org/t/optimize-apache-arrow-data-streaming-over-http/113692)

<div class="topic-metadata">

**Author:** [@simsurace](https://discourse.julialang.org/u/simsurace)\
**Replies:** 29\
**Last updated:** [October 12, 2024, 6:56pm UTC](https://discourse.julialang.org/t/optimize-apache-arrow-data-streaming-over-http/113692 "2024-10-12T18:56:55Z")

</div>

Following a request on the Arrow.jl project, I started implementing a simple Julia example here. With the exeption of an upstream issue on macOS, it seems to work. However, the implementation seems to be less performant …

---

## [Pre-allocating array efficiency](https://discourse.julialang.org/t/pre-allocating-array-efficiency/121207)

<div class="topic-metadata">

**Author:** [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Replies:** 5\
**Last updated:** [October 12, 2024, 4:52pm UTC](https://discourse.julialang.org/t/pre-allocating-array-efficiency/121207 "2024-10-12T16:52:22Z")

</div>

Hi there, my understanding was, in vague terms, that pre-allocating an array by specifying size and then populating the elements of that array was more efficient than defining an array without doing so. To test this I j…

---

## [PythonCall.jl with CondaPkg.jl in MPI scenario](https://discourse.julialang.org/t/pythoncall-jl-with-condapkg-jl-in-mpi-scenario/121191)

<div class="topic-metadata">

**Author:** [@J-C-Q](https://discourse.julialang.org/u/J-C-Q)\
**Replies:** 2\
**Last updated:** [October 11, 2024, 12:37pm UTC](https://discourse.julialang.org/t/pythoncall-jl-with-condapkg-jl-in-mpi-scenario/121191 "2024-10-11T12:37:31Z")

</div>

Hi everyone, I’m working on a julia package that has PythonCall.jl and CondaPkg.jl in its dependencies. Now, I want to do some calculations using my package on a cluster with MPI.jl. The problem is (this is my understa…

---

## [Vectorise summation over index in nested for loop](https://discourse.julialang.org/t/vectorise-summation-over-index-in-nested-for-loop/121158)

<div class="topic-metadata">

**Author:** [@eveningsilverfox](https://discourse.julialang.org/u/eveningsilverfox)\
**Replies:** 7\
**Last updated:** [October 10, 2024, 11:33pm UTC](https://discourse.julialang.org/t/vectorise-summation-over-index-in-nested-for-loop/121158 "2024-10-10T23:33:32Z")

</div>

Given a function using LinearAlgebra function test(arr1, arr2, arr3, g) return 1 ./ (arr1 .+ arr2 .+ arr3 .+ im\*g) end N1 = 100000; arr1 = range(0,10,N1); N2 = 5000; arr2 = range(0,10,N2); N3 = 5000; arr3 = range…

---

## [Type-instability of mapreduce vs. map + reduce](https://discourse.julialang.org/t/type-instability-of-mapreduce-vs-map-reduce/121136)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 18\
**Last updated:** [October 10, 2024, 4:43pm UTC](https://discourse.julialang.org/t/type-instability-of-mapreduce-vs-map-reduce/121136 "2024-10-10T16:43:03Z")

</div>

I’m a bit surprised that in this simple example, f is type-stable but g is not. Is this a JET.jl issue (@aviatesk) or a Julia issue? using JET function f(m, n) blocks = map(1:n) do i ones(m) end ret…

---

## [Julia Tab Completion is Slow in directories with many items](https://discourse.julialang.org/t/julia-tab-completion-is-slow-in-directories-with-many-items/121156)

<div class="topic-metadata">

**Author:** [@natgeo-wong](https://discourse.julialang.org/u/natgeo-wong)\
**Replies:** 0\
**Last updated:** [October 10, 2024, 3:09pm UTC](https://discourse.julialang.org/t/julia-tab-completion-is-slow-in-directories-with-many-items/121156 "2024-10-10T15:09:58Z")

</div>

In the REPL, when I try to use strings, REPL keeps hanging in directories with many items. I have a directory with around 400+ items, all of which are dates from 2020-01-01 to 2020-12-31, and Julia keeps hanging (and is…

---

## [Understanding how ForwardDiff.Duals are propagated](https://discourse.julialang.org/t/understanding-how-forwarddiff-duals-are-propagated/121114)

<div class="topic-metadata">

**Author:** [@AndreaRH](https://discourse.julialang.org/u/AndreaRH)\
**Replies:** 6\
**Last updated:** [October 10, 2024, 12:18pm UTC](https://discourse.julialang.org/t/understanding-how-forwarddiff-duals-are-propagated/121114 "2024-10-10T12:18:55Z")

</div>

Hello, I’m trying to understand how ForwardDiff propagates Duals through an ode solver, so how the function defining an ODE system can be overloaded (specialized is another word that could be used?) to handle Duals. Ta…

---

## [SVD 2x slower than in Matlab and how to get best performance on Windows10](https://discourse.julialang.org/t/svd-2x-slower-than-in-matlab-and-how-to-get-best-performance-on-windows10/21645)

<div class="topic-metadata">

**Author:** [@Baicai\_Xiao](https://discourse.julialang.org/u/Baicai_Xiao)\
**Replies:** 20\
**Last updated:** [October 9, 2024, 12:22pm UTC](https://discourse.julialang.org/t/svd-2x-slower-than-in-matlab-and-how-to-get-best-performance-on-windows10/21645 "2024-10-09T12:22:04Z")

</div>

Hello , Recently, I found that julia svd is slower than the one in matlab. It has been discussed once here in https://github.com/JuliaLang/julia/issues/3521, but after reading this, I am still not quite sure what is exa…

---

## [Performance Tips for functions](https://discourse.julialang.org/t/performance-tips-for-functions/121030)

<div class="topic-metadata">

**Author:** [@luke98](https://discourse.julialang.org/u/luke98)\
**Replies:** 9\
**Last updated:** [October 9, 2024, 3:38am UTC](https://discourse.julialang.org/t/performance-tips-for-functions/121030 "2024-10-09T03:38:37Z")

</div>

Hi Everyone, I’m working on optimizing two functions, mplFun and marketEq, and I’m looking for advice on how to make them as efficient as possible. Below, I’ve included a simplified version of the code that allows these…

---

## [Fastest way for GLMM](https://discourse.julialang.org/t/fastest-way-for-glmm/119892)

<div class="topic-metadata">

**Author:** [@Juh](https://discourse.julialang.org/u/Juh)\
**Replies:** 6\
**Last updated:** [October 7, 2024, 11:18pm UTC](https://discourse.julialang.org/t/fastest-way-for-glmm/119892 "2024-10-07T23:18:38Z")

</div>

Hi, I am conducting a single-cell eQTL analysis using Julia. I have several covariates (genotype PCs, sex, age) and a random effect represented by sample ID, as the single-cell data is quite structured. The model should…

---

## [Timing compilation when using threads](https://discourse.julialang.org/t/timing-compilation-when-using-threads/121001)

<div class="topic-metadata">

**Author:** [@theogf](https://discourse.julialang.org/u/theogf)\
**Replies:** 0\
**Last updated:** [October 7, 2024, 11:56am UTC](https://discourse.julialang.org/t/timing-compilation-when-using-threads/121001 "2024-10-07T11:56:38Z")

</div>

Is it possible to correctly measure compilation time when using Tasks on separate threads? I have tried using the 1.11 @timed but get inconsistent timings for the compilation time. I also don’t have a clear picture of …

---

## [Arrays of NamedTuples](https://discourse.julialang.org/t/arrays-of-namedtuples/120910)

<div class="topic-metadata">

**Author:** [@kingaa](https://discourse.julialang.org/u/kingaa)\
**Replies:** 2\
**Last updated:** [October 4, 2024, 1:29pm UTC](https://discourse.julialang.org/t/arrays-of-namedtuples/120910 "2024-10-04T13:29:49Z")

</div>

I’m designing a package based on manipulating arrays of NamedTuples. Should I be aware of any performance pitfalls associated with such structures? In particular, while many use cases will have NamedTuples, the element…

---

## [Type instabilities when introducing a Channel as a parameter in a ODE problem](https://discourse.julialang.org/t/type-instabilities-when-introducing-a-channel-as-a-parameter-in-a-ode-problem/105737)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 10\
**Last updated:** [October 4, 2024, 11:31am UTC](https://discourse.julialang.org/t/type-instabilities-when-introducing-a-channel-as-a-parameter-in-a-ode-problem/105737 "2024-10-04T11:31:40Z")

</div>

Hello. Hello, in the following I show a minimal working example of the problem. I want to implement a type stable function that solves an ODE that implements a Channel as a parameter. But I figured out that the solve fu…

---

## [Calculating Statistics of an Array with A Mask (Masked Array)](https://discourse.julialang.org/t/calculating-statistics-of-an-array-with-a-mask-masked-array/120868)

<div class="topic-metadata">

**Author:** [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Replies:** 1\
**Last updated:** [October 3, 2024, 7:25pm UTC](https://discourse.julialang.org/t/calculating-statistics-of-an-array-with-a-mask-masked-array/120868 "2024-10-03T19:25:23Z")

</div>

I saw a great thread on performance at Slack. I asked to reproduce it here as I think it will be beneficial for many. The participants were: Alexander Plavin, @danielwe, @jar, @mcabbott . It started with Alexander’s q…

---

## [Same performances between type-stable and type-unstable code](https://discourse.julialang.org/t/same-performances-between-type-stable-and-type-unstable-code/120799)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 13\
**Last updated:** [October 3, 2024, 3:22pm UTC](https://discourse.julialang.org/t/same-performances-between-type-stable-and-type-unstable-code/120799 "2024-10-03T15:22:06Z")

</div>

I’m writing some text explaining the importance of having type-stable code in Julia. I made the simple example of global variables: y = 2.4 function bar(x) res = zero(x) for i in 1:1000 res += y \* x …

---

## [How to optimise a linear solve in a hot loop?](https://discourse.julialang.org/t/how-to-optimise-a-linear-solve-in-a-hot-loop/120835)

<div class="topic-metadata">

**Author:** [@marcsgil](https://discourse.julialang.org/u/marcsgil)\
**Replies:** 7\
**Last updated:** [October 3, 2024, 12:55pm UTC](https://discourse.julialang.org/t/how-to-optimise-a-linear-solve-in-a-hot-loop/120835 "2024-10-03T12:55:51Z")

</div>

I have a hot loop that takes the following simplified form: for n in eachindex(result) compute\_A!(A) compute\_b!(b) x = A \\ b result\[n\] = f(x) end Here, A is a tall dense matrix, b is a dense vector, bot…

---

## [Is there a non-allocating version of findall?](https://discourse.julialang.org/t/is-there-a-non-allocating-version-of-findall/120832)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 1\
**Last updated:** [October 2, 2024, 11:47pm UTC](https://discourse.julialang.org/t/is-there-a-non-allocating-version-of-findall/120832 "2024-10-02T23:47:00Z")

</div>

MWEusing StaticArrays, BenchmarkTools # Data vector dat = collect(1:10); # Always five "trues" but at any indices flag = \[trues(3); falses(5); trues(2)\]; # Index with vector of bools @btime ($dat\[$flag\]); @b…

---

## [Trying to understand low performance compared to C++](https://discourse.julialang.org/t/trying-to-understand-low-performance-compared-to-c/120804)

<div class="topic-metadata">

**Author:** [@paulmelis](https://discourse.julialang.org/u/paulmelis)\
**Replies:** 13\
**Last updated:** [October 2, 2024, 1:19pm UTC](https://discourse.julialang.org/t/trying-to-understand-low-performance-compared-to-c/120804 "2024-10-02T13:19:46Z")

</div>

With the toy problem below of approximating Pi by sampling a square I get an almost 4x lower performance with Julia than wit the C++ version. The code is very simple, just two nested 2 loops, no indexing, no type instabi…

---

## [Fast evaluation of linear/bilinear expressions and Jacobians from strings](https://discourse.julialang.org/t/fast-evaluation-of-linear-bilinear-expressions-and-jacobians-from-strings/120721)

<div class="topic-metadata">

**Author:** [@Olegg](https://discourse.julialang.org/u/Olegg)\
**Replies:** 1\
**Last updated:** [October 1, 2024, 5:33pm UTC](https://discourse.julialang.org/t/fast-evaluation-of-linear-bilinear-expressions-and-jacobians-from-strings/120721 "2024-10-01T17:33:23Z")

</div>

I have a set of m equality constraints with linear and/or bilinear terms, defined as strings. For example: \[ “P0\_I\_m − F1\_m − F2\_m”, “P0\_E\_m − F6\_m − F7\_m”, “P0\_dS\_m + P0\_E\_m − P0\_I\_m”, “F1\_m + F2\_m + F4\_m − F3\_m”, …

---

## [Minimize Watson test function for n=12](https://discourse.julialang.org/t/minimize-watson-test-function-for-n-12/119807)

<div class="topic-metadata">

**Author:** [@Hans\_W\_Borchers](https://discourse.julialang.org/u/Hans_W_Borchers)\
**Replies:** 4\
**Last updated:** [September 29, 2024, 5:37am UTC](https://discourse.julialang.org/t/minimize-watson-test-function-for-n-12/119807 "2024-09-29T05:37:49Z")

</div>

More or less by chance I encountered the Watson function, that is test function #20, page 25, in the report “Testing Unconstrained Optimization Software” from 1991 by Moré, Garbow, and Hillstrom. See https://typeset.i…

---

## [Help with optimization](https://discourse.julialang.org/t/help-with-optimization/120522)

<div class="topic-metadata">

**Author:** [@lancejnelson](https://discourse.julialang.org/u/lancejnelson)\
**Replies:** 18\
**Last updated:** [September 28, 2024, 11:47pm UTC](https://discourse.julialang.org/t/help-with-optimization/120522 "2024-09-28T23:47:46Z")

</div>

I have the following function that is going to be called hundreds of thousands of times, and right now it’s running way too slow. function sample\_σ!(metrop::LJ\_metrop,data::DataSet,LJ::LJ,LJ\_next::LJ,std) for j = 1…

---

## [When to use mutable structs?](https://discourse.julialang.org/t/when-to-use-mutable-structs/120391)

<div class="topic-metadata">

**Author:** [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Replies:** 1\
**Last updated:** [September 28, 2024, 4:57pm UTC](https://discourse.julialang.org/t/when-to-use-mutable-structs/120391 "2024-09-28T16:57:15Z")

</div>

@jameson (hope I’ve got the username right, apologies if not!) I think we were getting a bit off-topic in Ref docstring should note clearly that it's an abstract type · Issue #55321 · JuliaLang/julia · GitHub. You’ve sa…

---

## [Rotate lower n bits](https://discourse.julialang.org/t/rotate-lower-n-bits/119923)

<div class="topic-metadata">

**Author:** [@Nichola](https://discourse.julialang.org/u/Nichola)\
**Replies:** 6\
**Last updated:** [September 27, 2024, 8:46am UTC](https://discourse.julialang.org/t/rotate-lower-n-bits/119923 "2024-09-27T08:46:26Z")

</div>

I would like to rotate the lower n bits of an integer x by r. Here is my current solution : function rotate\_lower(x::Int, n::Int, r::Int) mask = (1 \<\< n) - 1 lower\_bits = x & mask rotated\_bits = (lower\_bits…

---

## [Unclear allocations with in-place mutating functions](https://discourse.julialang.org/t/unclear-allocations-with-in-place-mutating-functions/119896)

<div class="topic-metadata">

**Author:** [@fmor](https://discourse.julialang.org/u/fmor)\
**Replies:** 14\
**Last updated:** [September 26, 2024, 6:50pm UTC](https://discourse.julialang.org/t/unclear-allocations-with-in-place-mutating-functions/119896 "2024-09-26T18:50:48Z")

</div>

I am fitting a statistical model and I refactored the code to reduce the allocations it generated. I morally halved them, with respect to the first version, but there are still some unclear sections which I see from runn…

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

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