# Performance

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

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

**Page:** 17

---

## [Pointer to stackframe in Julia, VLA/alloca-like; with e.g. StaticString.jl](https://discourse.julialang.org/t/pointer-to-stackframe-in-julia-vla-alloca-like-with-e-g-staticstring-jl/121992)

<div class="topic-metadata">

**Author:** [@Palli](https://discourse.julialang.org/u/Palli)\
**Replies:** 5\
**Last updated:** [October 30, 2024, 2:57pm UTC](https://discourse.julialang.org/t/pointer-to-stackframe-in-julia-vla-alloca-like-with-e-g-staticstring-jl/121992 "2024-10-30T14:57:05Z")

</div>

I’m optimizing allocations away, for printing general strings (one of the last one is because of Libc.malloc(200), effectively in Julia, and it could be on the stack if Julia had such capability like in C). It IS danger…

---

## [Why does a vector with 10 times more elements takes 2x-5x less time to pre-allocate?](https://discourse.julialang.org/t/why-does-a-vector-with-10-times-more-elements-takes-2x-5x-less-time-to-pre-allocate/121828)

<div class="topic-metadata">

**Author:** [@Olegg](https://discourse.julialang.org/u/Olegg)\
**Replies:** 14\
**Last updated:** [October 30, 2024, 1:13pm UTC](https://discourse.julialang.org/t/why-does-a-vector-with-10-times-more-elements-takes-2x-5x-less-time-to-pre-allocate/121828 "2024-10-30T13:13:11Z")

</div>

I’m benchmarking pre-allocation of vectors: display(@benchmark Vector{Int}(undef, 1000) ) display(@benchmark Vector{Int}(undef, 10000) ) display(@benchmark Vector{Int}(undef, 1000) ) display(@benchmark Vector{Int}(u…

---

## [The One Billion Row Challenge](https://discourse.julialang.org/t/the-one-billion-row-challenge/109534)

<div class="topic-metadata">

**Author:** [@3j5a](https://discourse.julialang.org/u/3j5a)\
**Replies:** 29\
**Last updated:** [October 30, 2024, 12:58pm UTC](https://discourse.julialang.org/t/the-one-billion-row-challenge/109534 "2024-10-30T12:58:21Z")

</div>

There’s been a challenge in Java community that generated a considerable amount of interest I’d say: The One Billion Row Challenge “A fun exploration of how quickly 1B rows from a text file can be aggregated with Java”. …

---

## [Optimizing a puzzle from the Balatro game: discarding part of a poker hand to get a pair](https://discourse.julialang.org/t/optimizing-a-puzzle-from-the-balatro-game-discarding-part-of-a-poker-hand-to-get-a-pair/121912)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 14\
**Last updated:** [October 30, 2024, 12:55am UTC](https://discourse.julialang.org/t/optimizing-a-puzzle-from-the-balatro-game-discarding-part-of-a-poker-hand-to-get-a-pair/121912 "2024-10-30T00:55:22Z")

</div>

Interesting problem from Balatro, from a hand of 8 without any pairs, if you discard n and draw n from the remaining deck of 44 cards. What’s the optimum n to maximize your chance of obtaining at least a pair? I am sure…

---

## [10x faster sortperm()](https://discourse.julialang.org/t/10x-faster-sortperm/93026)

<div class="topic-metadata">

**Author:** [@LSchwerdt](https://discourse.julialang.org/u/LSchwerdt)\
**Replies:** 10\
**Last updated:** [October 29, 2024, 8:59pm UTC](https://discourse.julialang.org/t/10x-faster-sortperm/93026 "2024-10-29T20:59:31Z")

</div>

Motivated by LilithHafner s work to add radix sorting to Julia 1.9 and the resulting performance improvements of sort(), I did some tests to see if sortperm() could be sped up as well. To test this, I implemented diffe…

---

## [Argmax over columns of a large matrix](https://discourse.julialang.org/t/argmax-over-columns-of-a-large-matrix/121924)

<div class="topic-metadata">

**Author:** [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Replies:** 2\
**Last updated:** [October 29, 2024, 6:50pm UTC](https://discourse.julialang.org/t/argmax-over-columns-of-a-large-matrix/121924 "2024-10-29T18:50:52Z")

</div>

Hi there, I have a large matrix for e.g (7x10000) and I want to iterate over each of the columns and compute the index of the maximum element. There are naive ways I can think of but since this part of my code is perfor…

---

## [Avoid allocations in retrieving array parts](https://discourse.julialang.org/t/avoid-allocations-in-retrieving-array-parts/121908)

<div class="topic-metadata">

**Author:** [@JTHesse](https://discourse.julialang.org/u/JTHesse)\
**Replies:** 2\
**Last updated:** [October 29, 2024, 9:32am UTC](https://discourse.julialang.org/t/avoid-allocations-in-retrieving-array-parts/121908 "2024-10-29T09:32:11Z")

</div>

Hello, I’m trying to reduce memory allocations and increase efficiency of our software. Most of the allocations will occur while retrieving part of an array. As you can see below, the retrieval is allocating much more…

---

## [JumpProcesses.jl solvers](https://discourse.julialang.org/t/jumpprocesses-jl-solvers/121883)

<div class="topic-metadata">

**Author:** [@hhindley](https://discourse.julialang.org/u/hhindley)\
**Replies:** 4\
**Last updated:** [October 28, 2024, 7:05pm UTC](https://discourse.julialang.org/t/jumpprocesses-jl-solvers/121883 "2024-10-28T19:05:29Z")

</div>

I’m modelling a biochemical system using JumpProcesses.jl. I am coupling a continuous ODE to a jumpset which includes MassActionJumps, ConstantRateJumps and unbounded VariableRateJumps. When I increase my tspan, or in c…

---

## [\`ifelse(x\<y, x, y)\` much faster than \`min()\`](https://discourse.julialang.org/t/ifelse-x-y-x-y-much-faster-than-min/121826)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 16\
**Last updated:** [October 28, 2024, 3:01pm UTC](https://discourse.julialang.org/t/ifelse-x-y-x-y-much-faster-than-min/121826 "2024-10-28T15:01:18Z")

</div>

julia\> using Chairmarks julia\> function g(dij) vmin = Inf for x in dij vmin = min(x, vmin) end return vmin end julia\> function f(dij) vmin = Inf for x in dij vmin = ifelse(x \< vm…

---

## [Can't convert from Irish to British grid using CoordRefSystems](https://discourse.julialang.org/t/cant-convert-from-irish-to-british-grid-using-coordrefsystems/121857)

<div class="topic-metadata">

**Author:** [@TimG](https://discourse.julialang.org/u/TimG)\
**Replies:** 1\
**Last updated:** [October 28, 2024, 11:06am UTC](https://discourse.julialang.org/t/cant-convert-from-irish-to-british-grid-using-coordrefsystems/121857 "2024-10-28T11:06:28Z")

</div>

I’m trying to convert coordinates from Irish to British national grid. I can do this in Proj, but am encountering some compatibility issues. I thought the easiest solution might be to remove any direct dependence on Proj…

---

## [Most Efficient Way to Compute a Quadratic Matrix Form](https://discourse.julialang.org/t/most-efficient-way-to-compute-a-quadratic-matrix-form/66606)

<div class="topic-metadata">

**Author:** [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Replies:** 15\
**Last updated:** [October 27, 2024, 6:24pm UTC](https://discourse.julialang.org/t/most-efficient-way-to-compute-a-quadratic-matrix-form/66606 "2024-10-27T18:24:33Z")

</div>

Given a Symmetric Positive Semi definite Matrix P , what would be the most efficient (Fast) way to calculate the matrix quadratic form: {x}^{T} P x For the following cases: The matrix P is dense. The matrix P i…

---

## [Allocations MVectors](https://discourse.julialang.org/t/allocations-mvectors/121818)

<div class="topic-metadata">

**Author:** [@AdaemmerP](https://discourse.julialang.org/u/AdaemmerP)\
**Replies:** 10\
**Last updated:** [October 27, 2024, 10:38am UTC](https://discourse.julialang.org/t/allocations-mvectors/121818 "2024-10-27T10:38:56Z")

</div>

Why does this: m! = factorial(3) @btime MVector{$m!, Float64}(undef); 576.677 ns (10 allocations: 512 bytes) allocate ten times as much as this: @btime MVector{6, Float64}(undef); 4.148 ns (1 allocation: 64 bytes) I …

---

## [Loop over array of static arrays](https://discourse.julialang.org/t/loop-over-array-of-static-arrays/121769)

<div class="topic-metadata">

**Author:** [@nicolas](https://discourse.julialang.org/u/nicolas)\
**Replies:** 12\
**Last updated:** [October 26, 2024, 3:29pm UTC](https://discourse.julialang.org/t/loop-over-array-of-static-arrays/121769 "2024-10-26T15:29:15Z")

</div>

I have the following loop over arrays (the function double() will obviously be more complicated, but the number of arrays is always the same) double(x) = 2x function doubles\_using\_arrays() xs = \[ones(10) for i in 1…

---

## [What is a good design for a settable global with a known type?](https://discourse.julialang.org/t/what-is-a-good-design-for-a-settable-global-with-a-known-type/121770)

<div class="topic-metadata">

**Author:** [@jakobjpeters](https://discourse.julialang.org/u/jakobjpeters)\
**Replies:** 4\
**Last updated:** [October 26, 2024, 8:49am UTC](https://discourse.julialang.org/t/what-is-a-good-design-for-a-settable-global-with-a-known-type/121770 "2024-10-26T08:49:45Z")

</div>

In a package, I have a const s = "" that is used in a couple of functions. One of these functions doesn’t have a way for a user to specify a different string to use instead. What is a good way to make the value settable? …

---

## [Allocations with StaticArrays and \`+=\` in Julia \`v1.11\`](https://discourse.julialang.org/t/allocations-with-staticarrays-and-in-julia-v1-11/121578)

<div class="topic-metadata">

**Author:** [@kaipartmann](https://discourse.julialang.org/u/kaipartmann)\
**Replies:** 6\
**Last updated:** [October 26, 2024, 7:54am UTC](https://discourse.julialang.org/t/allocations-with-staticarrays-and-in-julia-v1-11/121578 "2024-10-26T07:54:27Z")

</div>

Hello everyone, I am the main author of the package Peridynamics.jl and recently changed to Julia v1.11. With the new Julia version, a significant increase in the simulation time can be found when using a certain mater…

---

## [Rule of thumb to estimate theoretical lower bound on benchmarks?](https://discourse.julialang.org/t/rule-of-thumb-to-estimate-theoretical-lower-bound-on-benchmarks/121509)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 4\
**Last updated:** [October 25, 2024, 4:41pm UTC](https://discourse.julialang.org/t/rule-of-thumb-to-estimate-theoretical-lower-bound-on-benchmarks/121509 "2024-10-25T16:41:32Z")

</div>

I have a somewhat complex inner loop (I can share if needed but I am looking for general rules here) that benchmarks at 200-800 ns with no allocations. A range makes sense, it depends on which conditionals are randomly u…

---

## [@profile slows down MPI?](https://discourse.julialang.org/t/profile-slows-down-mpi/121700)

<div class="topic-metadata">

**Author:** [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Replies:** 0\
**Last updated:** [October 24, 2024, 2:10pm UTC](https://discourse.julialang.org/t/profile-slows-down-mpi/121700 "2024-10-24T14:10:33Z")

</div>

Is anybody else having problems when trying to @profile an MPI program? I seem to find that when I add @profile my code slows down a lot, with a load of time being spent in MPI calls (a lot more than I would expect). I t…

---

## [Type inference difference in \`mapreduce(f, op, t)\` vs \`reduce(op, map(f, t))\`](https://discourse.julialang.org/t/type-inference-difference-in-mapreduce-f-op-t-vs-reduce-op-map-f-t/93265)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 1\
**Last updated:** [October 24, 2024, 8:42am UTC](https://discourse.julialang.org/t/type-inference-difference-in-mapreduce-f-op-t-vs-reduce-op-map-f-t/93265 "2024-10-24T08:42:21Z")

</div>

For tuples, it seems mapreduce has poorer type inference than map + reduce. julia\> using FillArrays, Infinities, InfiniteArrays, Test julia\> ax = Ones{Int}(InfiniteCardinal{0}()); julia\> y = (ax,ax); julia\> @inferred…

---

## [Performance comparison of a custom gcd() function in Julia, C, and Rust](https://discourse.julialang.org/t/performance-comparison-of-a-custom-gcd-function-in-julia-c-and-rust/121665)

<div class="topic-metadata">

**Author:** [@jbytecode](https://discourse.julialang.org/u/jbytecode)\
**Replies:** 7\
**Last updated:** [October 23, 2024, 10:58pm UTC](https://discourse.julialang.org/t/performance-comparison-of-a-custom-gcd-function-in-julia-c-and-rust/121665 "2024-10-23T22:58:53Z")

</div>

Here is the naive implementation of the gcd (Greatest Common Divisor) in Julia: function mygcd(a::Int64, b::Int64)::Int64 if a == b return a elseif a \> b return mygcd(a-b, b) else return m…

---

## [Fast ways to check if an element is in a vector of vector of elements](https://discourse.julialang.org/t/fast-ways-to-check-if-an-element-is-in-a-vector-of-vector-of-elements/121598)

<div class="topic-metadata">

**Author:** [@rakshith95](https://discourse.julialang.org/u/rakshith95)\
**Replies:** 20\
**Last updated:** [October 23, 2024, 3:42pm UTC](https://discourse.julialang.org/t/fast-ways-to-check-if-an-element-is-in-a-vector-of-vector-of-elements/121598 "2024-10-23T15:42:36Z")

</div>

Hello , What would be the most efficient way to look for a number in a vector of vector of numbers? i.e. Data: t = \[ \[1,2,3\] , \[4,5,6\] , \[1,10,12\], \[1,4,5\] \] Input: 1 Output: 1,3,4 I could do something like findall…

---

## [Reshaped views might alias](https://discourse.julialang.org/t/reshaped-views-might-alias/121495)

<div class="topic-metadata">

**Author:** [@lxvm](https://discourse.julialang.org/u/lxvm)\
**Replies:** 5\
**Last updated:** [October 23, 2024, 12:54pm UTC](https://discourse.julialang.org/t/reshaped-views-might-alias/121495 "2024-10-23T12:54:41Z")

</div>

Hi, I have implemented a linear operator as a method of LinearAlgebra.mul!(x, A, b) to use with IterativeSolvers.jl, but when profiling my code I noticed a huge performance difference due to unaliasing arrays when testi…

---

## [What is the best way to re-use a temporary vector](https://discourse.julialang.org/t/what-is-the-best-way-to-re-use-a-temporary-vector/121519)

<div class="topic-metadata">

**Author:** [@HMegh](https://discourse.julialang.org/u/HMegh)\
**Replies:** 16\
**Last updated:** [October 22, 2024, 4:24pm UTC](https://discourse.julialang.org/t/what-is-the-best-way-to-re-use-a-temporary-vector/121519 "2024-10-22T16:24:11Z")

</div>

Hi, I have the following situation: I have a function f(x::Float64) which creates a temporary array A::Vector{Float64}, then finally it returns a Float64. I typically call this function millions of times, so I am wonder…

---

## [Performance hacking \`(&)(a::BitArray, b::BitArray)\`](https://discourse.julialang.org/t/performance-hacking-a-bitarray-b-bitarray/121548)

<div class="topic-metadata">

**Author:** [@AJahraus](https://discourse.julialang.org/u/AJahraus)\
**Replies:** 14\
**Last updated:** [October 22, 2024, 2:44pm UTC](https://discourse.julialang.org/t/performance-hacking-a-bitarray-b-bitarray/121548 "2024-10-22T14:44:09Z")

</div>

I’m trying my hand at performance hacking the bitwise AND function, and although what I have is fairly good, it seems to me like it’s allocating much memory even though it seems as though it’s always just 2 allocations r…

---

## [Strange performance of literal array constructor](https://discourse.julialang.org/t/strange-performance-of-literal-array-constructor/121575)

<div class="topic-metadata">

**Author:** [@DNF](https://discourse.julialang.org/u/DNF)\
**Replies:** 5\
**Last updated:** [October 22, 2024, 1:21pm UTC](https://discourse.julialang.org/t/strange-performance-of-literal-array-constructor/121575 "2024-10-22T13:21:53Z")

</div>

I was surprised by this performance measurement (v.1.11.1): julia\> foo() = Int8\[1 2 3; 4 5 6; 7 8 9\] foo (generic function with 1 method) julia\> bar() = Matrix{Int8}(\[1 2 3; 4 5 6; 7 8 9\]) bar (generic function with 1 …

---

## [Execution of active file in REPL does not work anymore](https://discourse.julialang.org/t/execution-of-active-file-in-repl-does-not-work-anymore/121586)

<div class="topic-metadata">

**Author:** [@mariie](https://discourse.julialang.org/u/mariie)\
**Replies:** 1\
**Last updated:** [October 22, 2024, 1:13pm UTC](https://discourse.julialang.org/t/execution-of-active-file-in-repl-does-not-work-anymore/121586 "2024-10-22T13:13:01Z")

</div>

Hello! I’ve been using julia since 2 months and really enjoyed it. But now I’m facing the problem that I cannot execute code in-line in files anymore, cannot execute an active file in the REPL unless I copy the code fr…

---

## [How to efficiently parse null as NaN in JSON?](https://discourse.julialang.org/t/how-to-efficiently-parse-null-as-nan-in-json/121561)

<div class="topic-metadata">

**Author:** [@berjine](https://discourse.julialang.org/u/berjine)\
**Replies:** 1\
**Last updated:** [October 22, 2024, 12:00am UTC](https://discourse.julialang.org/t/how-to-efficiently-parse-null-as-nan-in-json/121561 "2024-10-22T00:00:10Z")

</div>

Hi I want to parse lines of JSON containing among other things a vector of signed ints with some values being “null”, like that : {"data":\[98,null,-51,null\]} The way I do it currently is by using a conversion function…

---

## [Obtaining field values over an array of composite types](https://discourse.julialang.org/t/obtaining-field-values-over-an-array-of-composite-types/121518)

<div class="topic-metadata">

**Author:** [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Replies:** 11\
**Last updated:** [October 21, 2024, 8:32pm UTC](https://discourse.julialang.org/t/obtaining-field-values-over-an-array-of-composite-types/121518 "2024-10-21T20:32:50Z")

</div>

Hi there, I defined a composite type Product tho store relevant characteristics of a set of products. I then construct an array of Product and I am ultimately interested in accessing the field values of this array as ef…

---

## [Performance hit of allocation regardless of size](https://discourse.julialang.org/t/performance-hit-of-allocation-regardless-of-size/119937)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 7\
**Last updated:** [October 21, 2024, 5:05pm UTC](https://discourse.julialang.org/t/performance-hit-of-allocation-regardless-of-size/119937 "2024-10-21T17:05:29Z")

</div>

Hi there performance fanatics! @amontoison and I are working on our matrix coloring code, and in one of our algorithms we need to split a vector into groups, one for each color. Semantically, this is what we want to ach…

---

## [Is the triple \`@inbounds @fastmath @simd\` necessary for absolute peak performance?](https://discourse.julialang.org/t/is-the-triple-inbounds-fastmath-simd-necessary-for-absolute-peak-performance/121499)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 7\
**Last updated:** [October 21, 2024, 3:45pm UTC](https://discourse.julialang.org/t/is-the-triple-inbounds-fastmath-simd-necessary-for-absolute-peak-performance/121499 "2024-10-21T15:45:58Z")

</div>

using BenchmarkTools using LoopVectorization function a1(x) y = zero(eltype(x)) for i in eachindex(x) y += x\[i\] end y end function a2(x) y = zero(eltype(x)) @simd for i in eachindex(x) …

---

## [How can I allocate a buffer contains different types of data (for MPI communication, for example)?](https://discourse.julialang.org/t/how-can-i-allocate-a-buffer-contains-different-types-of-data-for-mpi-communication-for-example/121478)

<div class="topic-metadata">

**Author:** [@Blumenkranz](https://discourse.julialang.org/u/Blumenkranz)\
**Replies:** 10\
**Last updated:** [October 20, 2024, 8:12am UTC](https://discourse.julialang.org/t/how-can-i-allocate-a-buffer-contains-different-types-of-data-for-mpi-communication-for-example/121478 "2024-10-20T08:12:23Z")

</div>

I need to communicate data of Vector{Int8} and Vector{Float64} using MPI.jl. How can I achieve this with a single communication?

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

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