# Performance

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

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

**Page:** 11

---

## [How to properly generate a function based on a condition?](https://discourse.julialang.org/t/how-to-properly-generate-a-function-based-on-a-condition/127573)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 13\
**Last updated:** [April 1, 2025, 11:17am UTC](https://discourse.julialang.org/t/how-to-properly-generate-a-function-based-on-a-condition/127573 "2025-04-01T11:17:55Z")

</div>

Hello! I have some pseudo code from a package I am working on: function GenerateOutputKernelValues(SimMetaData) flag = SimMetaData.FlagOutputKernelValues if flag # Return a func…

---

## [How to make the Optim.jl zero allocated?](https://discourse.julialang.org/t/how-to-make-the-optim-jl-zero-allocated/126375)

<div class="topic-metadata">

**Author:** [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Replies:** 1\
**Last updated:** [March 31, 2025, 6:27pm UTC](https://discourse.julialang.org/t/how-to-make-the-optim-jl-zero-allocated/126375 "2025-03-31T18:27:28Z")

</div>

Hi guys, Right now I am using Optim.jl to optimise my problem, however, @btime shows the whole script has around hundreds allocations…which is quite a lot. So is there any trick to reduce the allocations to zero? and al…

---

## [Counter-intuitive performance difference](https://discourse.julialang.org/t/counter-intuitive-performance-difference/127477)

<div class="topic-metadata">

**Author:** [@photor](https://discourse.julialang.org/u/photor)\
**Replies:** 7\
**Last updated:** [March 30, 2025, 4:35pm UTC](https://discourse.julialang.org/t/counter-intuitive-performance-difference/127477 "2025-03-30T16:35:14Z")

</div>

julia\> using BenchmarkTools julia\> for i=1000 A=randn(2i,2i) vA=@view A\[1:i,1:i\] C=randn(i,i) @btime @. $C+=$vA end 1.325 ms (0 allocations: 0 bytes) julia\> for i=10…

---

## [Cuda kernel help](https://discourse.julialang.org/t/cuda-kernel-help/127488)

<div class="topic-metadata">

**Author:** [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Replies:** 2\
**Last updated:** [March 29, 2025, 4:23pm UTC](https://discourse.julialang.org/t/cuda-kernel-help/127488 "2025-03-29T16:23:52Z")

</div>

Hello, I’m somewhat new to kernel programing and I stuggle understanding why the two kernels bellow don’t do the same thing using CUDA f(x,y) = x+y function mykernel!(out,space) ig = blockIdx().x jg = blockIdx…

---

## [The Prospero Challenge](https://discourse.julialang.org/t/the-prospero-challenge/127342)

<div class="topic-metadata">

**Author:** [@maxfreu](https://discourse.julialang.org/u/maxfreu)\
**Replies:** 17\
**Last updated:** [March 29, 2025, 1:24pm UTC](https://discourse.julialang.org/t/the-prospero-challenge/127342 "2025-03-29T13:24:26Z")

</div>

I just found the “Prospero Challenge” on hackernews and thought it’s a really nice toy example to write a parser and to analyze compile times. Maybe it’s even possible to compile the entire document, the parent repo also…

---

## [Matrix multiplication with Duals](https://discourse.julialang.org/t/matrix-multiplication-with-duals/127453)

<div class="topic-metadata">

**Author:** [@Luis\_Calderon](https://discourse.julialang.org/u/Luis_Calderon)\
**Replies:** 12\
**Last updated:** [March 28, 2025, 10:01pm UTC](https://discourse.julialang.org/t/matrix-multiplication-with-duals/127453 "2025-03-28T22:01:47Z")

</div>

I was wondering if I could make this function faster. XC\_dual would come in as a Dual with 10-100 Partials. Here is the MWE: using LinearAlgebra, Random, ForwardDiff, Test, BenchmarkTools # Set a seed for reproducibilit…

---

## [Confusion on performance when using the broadcasting macro @. vs explicit . operators](https://discourse.julialang.org/t/confusion-on-performance-when-using-the-broadcasting-macro-vs-explicit-operators/127380)

<div class="topic-metadata">

**Author:** [@PetrosStefanou](https://discourse.julialang.org/u/PetrosStefanou)\
**Replies:** 7\
**Last updated:** [March 27, 2025, 11:51am UTC](https://discourse.julialang.org/t/confusion-on-performance-when-using-the-broadcasting-macro-vs-explicit-operators/127380 "2025-03-27T11:51:29Z")

</div>

Hi everyone, I am confused about the performance of the following code when using the @. macro as opposed to manually adding . before each operator. Below is a MWE function get\_f(θ, ϕ) α0 = 1.5 θ1 = π/4 ϕ1…

---

## [Kwargs allocating (?)](https://discourse.julialang.org/t/kwargs-allocating/127326)

<div class="topic-metadata">

**Author:** [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Replies:** 6\
**Last updated:** [March 27, 2025, 4:21am UTC](https://discourse.julialang.org/t/kwargs-allocating/127326 "2025-03-27T04:21:00Z")

</div>

Hi there, consider the following simple function: M = \[1.0 2.0; 3.0 4.0\] n = size(M,1) I\_n = Matrix{Float64}(I, n, n) A\_temp = zeros(n, n) diff\_temp = zeros(n, n) function inf\_norm\_dif…

---

## [Parallel feeding of a dataframe](https://discourse.julialang.org/t/parallel-feeding-of-a-dataframe/127061)

<div class="topic-metadata">

**Author:** [@Ju\_ska](https://discourse.julialang.org/u/Ju_ska)\
**Replies:** 17\
**Last updated:** [March 26, 2025, 12:39am UTC](https://discourse.julialang.org/t/parallel-feeding-of-a-dataframe/127061 "2025-03-26T00:39:12Z")

</div>

Hi, this is my problem: I have files of the same type in year folders, e.g.: ./2024/file1.csv ./2024/file2.csv ./2023/file1.csv ./2023/file2.csv etc. I want to fill a dataframe with all this data. I already use read…

---

## [Any reason to specify triu()?](https://discourse.julialang.org/t/any-reason-to-specify-triu/127361)

<div class="topic-metadata">

**Author:** [@Huputus](https://discourse.julialang.org/u/Huputus)\
**Replies:** 1\
**Last updated:** [March 25, 2025, 5:46pm UTC](https://discourse.julialang.org/t/any-reason-to-specify-triu/127361 "2025-03-25T17:46:14Z")

</div>

Is there any reason to use triu() when working with upper triangular matrices? Performance-wise, it doesn’t seem to have any impact. Here is sample code: function upper\_triangular\_means(mate) n = size(mate, 1) …

---

## [@threads and vmap](https://discourse.julialang.org/t/threads-and-vmap/127340)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 5\
**Last updated:** [March 25, 2025, 12:13pm UTC](https://discourse.julialang.org/t/threads-and-vmap/127340 "2025-03-25T12:13:46Z")

</div>

Is it possible to speed this up further? f(x) = sin(x)cos(x)sin(x)cos(x) X = repeat( \[randn(10^7)\], 5 ) @time for x in X; map(f,x) end # 1.0s @time Threads.@threads for x in X; map…

---

## [Solving a linear system without modifying and allocating arrays](https://discourse.julialang.org/t/solving-a-linear-system-without-modifying-and-allocating-arrays/127315)

<div class="topic-metadata">

**Author:** [@cneverett](https://discourse.julialang.org/u/cneverett)\
**Replies:** 3\
**Last updated:** [March 25, 2025, 10:48am UTC](https://discourse.julialang.org/t/solving-a-linear-system-without-modifying-and-allocating-arrays/127315 "2025-03-25T10:48:41Z")

</div>

Hi, I have a setup where I need to repeatedly solve a linear system like A \\ B = C every timestep of a system. A is a matrix, B is a vector and both changing each timestep and more importantly A is reused later each time…

---

## [Why does my iterable allocate?](https://discourse.julialang.org/t/why-does-my-iterable-allocate/86216)

<div class="topic-metadata">

**Author:** [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Replies:** 18\
**Last updated:** [March 22, 2025, 11:25pm UTC](https://discourse.julialang.org/t/why-does-my-iterable-allocate/86216 "2025-03-22T23:25:47Z")

</div>

I ran into unexpected allocations in a complex iterator and was able to simplify it down into this MWE which uses complex logic to always yield nothing. struct MyIter end Base.iterate(::MyIter) = (nothing, \[true\]) func…

---

## [Plot pane and focus in vscode](https://discourse.julialang.org/t/plot-pane-and-focus-in-vscode/127214)

<div class="topic-metadata">

**Author:** [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Replies:** 1\
**Last updated:** [March 21, 2025, 4:21pm UTC](https://discourse.julialang.org/t/plot-pane-and-focus-in-vscode/127214 "2025-03-21T16:21:11Z")

</div>

Hi, I have a problem when working in vscode. Figure produced within the vscode window are not easily “copy-able” (Julia: Copy Plot). It yields the error message: Failed to copy plot: Plot pane does not have focus I nee…

---

## [Interpolation between two dataframe columns](https://discourse.julialang.org/t/interpolation-between-two-dataframe-columns/127136)

<div class="topic-metadata">

**Author:** [@Ju\_ska](https://discourse.julialang.org/u/Ju_ska)\
**Replies:** 4\
**Last updated:** [March 21, 2025, 12:31pm UTC](https://discourse.julialang.org/t/interpolation-between-two-dataframe-columns/127136 "2025-03-21T12:31:14Z")

</div>

Hi, I think my code is highly sub-optimised, is there a more monolithic way (and preferably faster) to interpolate, e.g. without using eachrow, push etc. Code: using DataFrames using Interpolations # Dates, then valu…

---

## [How to select elements of a three-dimensional array fast](https://discourse.julialang.org/t/how-to-select-elements-of-a-three-dimensional-array-fast/127185)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 4\
**Last updated:** [March 20, 2025, 10:28pm UTC](https://discourse.julialang.org/t/how-to-select-elements-of-a-three-dimensional-array-fast/127185 "2025-03-20T22:28:50Z")

</div>

I have large three-dimensional arrays A that have different values, but from which I always wish to select the same set of entries. So A is a different matrix each time, but it has the same size and I need to collect th…

---

## [Why is this code allocating?](https://discourse.julialang.org/t/why-is-this-code-allocating/127175)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 1\
**Last updated:** [March 20, 2025, 2:48pm UTC](https://discourse.julialang.org/t/why-is-this-code-allocating/127175 "2025-03-20T14:48:07Z")

</div>

Why is the following code allocating: using VortexStepMethod # Step 1: Define wing parameters n\_panels = 20 # Number of panels span = 20.0 # Wing span \[m\] chord = 1.0 # Chord length \[m\] v…

---

## [Threads are not speeding up computation a lot](https://discourse.julialang.org/t/threads-are-not-speeding-up-computation-a-lot/126305)

<div class="topic-metadata">

**Author:** [@Nyan](https://discourse.julialang.org/u/Nyan)\
**Replies:** 70\
**Last updated:** [March 20, 2025, 6:00am UTC](https://discourse.julialang.org/t/threads-are-not-speeding-up-computation-a-lot/126305 "2025-03-20T06:00:03Z")

</div>

Hi. I googled and read many things about this topic, but cannot figure up what is the problem, and why I see no meaningful speedup for my code. My code: module Keygen using Base.Threads using Base.Iterators include("./…

---

## [Floops multithreading HasBoxedVariableError](https://discourse.julialang.org/t/floops-multithreading-hasboxedvariableerror/127139)

<div class="topic-metadata">

**Author:** [@s\_amap](https://discourse.julialang.org/u/s_amap)\
**Replies:** 7\
**Last updated:** [March 19, 2025, 3:54pm UTC](https://discourse.julialang.org/t/floops-multithreading-hasboxedvariableerror/127139 "2025-03-19T15:54:34Z")

</div>

I’ve been trying to adjust a parallel loop after some changes, and I need some clarification to make sure I’m not at risk of false sharing. The loop conceptually works like this: object # holds a state, which is a tupl…

---

## [Understanding GC time](https://discourse.julialang.org/t/understanding-gc-time/127127)

<div class="topic-metadata">

**Author:** [@pjuergens](https://discourse.julialang.org/u/pjuergens)\
**Replies:** 1\
**Last updated:** [March 19, 2025, 11:51am UTC](https://discourse.julialang.org/t/understanding-gc-time/127127 "2025-03-19T11:51:14Z")

</div>

Hello together, I am wondering what determines the time that the garbage collector needs. I have a complex simulation where I was hunting down allocations, but surprisingly even though I could heavily reduce number and …

---

## [Pairwise reduction significantly slower than two scalar reductions](https://discourse.julialang.org/t/pairwise-reduction-significantly-slower-than-two-scalar-reductions/127064)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 11\
**Last updated:** [March 18, 2025, 12:33am UTC](https://discourse.julialang.org/t/pairwise-reduction-significantly-slower-than-two-scalar-reductions/127064 "2025-03-18T00:33:17Z")

</div>

I’ve written two reductions which both do the same thing: compute the sum and the squared norm of a vector. One does this in one pass through the data, accumulating two values as it goes. The second does two passes throu…

---

## [Best practices about how to hide API Keys in Julia applications](https://discourse.julialang.org/t/best-practices-about-how-to-hide-api-keys-in-julia-applications/127001)

<div class="topic-metadata">

**Author:** [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Replies:** 3\
**Last updated:** [March 16, 2025, 4:42pm UTC](https://discourse.julialang.org/t/best-practices-about-how-to-hide-api-keys-in-julia-applications/127001 "2025-03-16T16:42:31Z")

</div>

The Federal Reserve Bank of St. Louis in the FRED Economic Data website states that: Developers should request a distinct API key for each application they build. All users of an application shall use their own API key…

---

## [Runtime dispatch for plan\_fft](https://discourse.julialang.org/t/runtime-dispatch-for-plan-fft/126958)

<div class="topic-metadata">

**Author:** [@henry2004y](https://discourse.julialang.org/u/henry2004y)\
**Replies:** 1\
**Last updated:** [March 14, 2025, 5:24pm UTC](https://discourse.julialang.org/t/runtime-dispatch-for-plan-fft/126958 "2025-03-14T17:24:10Z")

</div>

Hi, I am learning about JET.jl while optimizing a function that involves FFT. I happened to find that JET.jl detected a runtime dispatch for plan\_fft or plan\_fft!: using JET using FFTW julia\> @report\_opt plan\_fft!(zer…

---

## [Reducing the number of allocations in a function](https://discourse.julialang.org/t/reducing-the-number-of-allocations-in-a-function/126906)

<div class="topic-metadata">

**Author:** [@andrea\_bertozzi](https://discourse.julialang.org/u/andrea_bertozzi)\
**Replies:** 14\
**Last updated:** [March 14, 2025, 12:30pm UTC](https://discourse.julialang.org/t/reducing-the-number-of-allocations-in-a-function/126906 "2025-03-14T12:30:39Z")

</div>

Hello, I have this function. When running benchmark, I get 519 allocations. Does anyone know how I can reduce those? Thank you! using LinearAlgebra struct Settings rho::Float64 g\_earth::Vector{Float64} cd…

---

## [Matrix view based on BitVector?](https://discourse.julialang.org/t/matrix-view-based-on-bitvector/126922)

<div class="topic-metadata">

**Author:** [@AdaemmerP](https://discourse.julialang.org/u/AdaemmerP)\
**Replies:** 1\
**Last updated:** [March 13, 2025, 3:15pm UTC](https://discourse.julialang.org/t/matrix-view-based-on-bitvector/126922 "2025-03-13T15:15:17Z")

</div>

I have a pre-allocated BitVector that fills randomly inside a loop. Based on that BitVector, I want to create a view of a Matrix but it allocates. Is there a workaround? A simple example: using Chairmarks ix = BitVecto…

---

## [Optimizing or replacing IF-ELSEIF-ELSE statements](https://discourse.julialang.org/t/optimizing-or-replacing-if-elseif-else-statements/126867)

<div class="topic-metadata">

**Author:** [@hssn15](https://discourse.julialang.org/u/hssn15)\
**Replies:** 9\
**Last updated:** [March 12, 2025, 4:30pm UTC](https://discourse.julialang.org/t/optimizing-or-replacing-if-elseif-else-statements/126867 "2025-03-12T16:30:58Z")

</div>

I am developing a simulator but I dont have a lot experience and tricks about Julia. I have a case that seems like it has some kind of other way around that is much more efficient and optimized. I will give you and exam…

---

## [Distributed.jl vs MPI.jl](https://discourse.julialang.org/t/distributed-jl-vs-mpi-jl/71315)

<div class="topic-metadata">

**Author:** [@Niceno](https://discourse.julialang.org/u/Niceno)\
**Replies:** 26\
**Last updated:** [January 31, 2022, 4:13am UTC](https://discourse.julialang.org/t/distributed-jl-vs-mpi-jl/71315 "2022-01-31T04:13:13Z")

</div>

Hi all, I am relatively new to Julia, but have ported one of my older programs from Fortran to Julia. I picked a program from my collection which doesn’t have any parallelims in it with the intention to implement it fr…

---

## [Min/max swap using SIMD](https://discourse.julialang.org/t/min-max-swap-using-simd/126832)

<div class="topic-metadata">

**Author:** [@gitboy16](https://discourse.julialang.org/u/gitboy16)\
**Replies:** 18\
**Last updated:** [March 12, 2025, 11:35am UTC](https://discourse.julialang.org/t/min-max-swap-using-simd/126832 "2025-03-12T11:35:22Z")

</div>

I would like to request some help to SIMD the following code: import Test: @test n = 10\_000\_000 A = repeat(\[3, 1, 4, 2, 7, 8, 5, 6\], outer=n); B = repeat(\[5, 6, 0, 7, 2, 3, 1, 4\], outer=n); C = copy(A); D = copy(B); …

---

## [Globally Available Environments and State of Package Compilation](https://discourse.julialang.org/t/globally-available-environments-and-state-of-package-compilation/126732)

<div class="topic-metadata">

**Author:** [@Maddy](https://discourse.julialang.org/u/Maddy)\
**Replies:** 8\
**Last updated:** [March 11, 2025, 12:47am UTC](https://discourse.julialang.org/t/globally-available-environments-and-state-of-package-compilation/126732 "2025-03-11T00:47:13Z")

</div>

1. Environments in Julia I recently started using Conda environments for Python in my Class and realized how simple and efficient it is to use them. Unlike how I do things in Julia - for each new project, I just create …

---

## [Improve removing members of one array from another](https://discourse.julialang.org/t/improve-removing-members-of-one-array-from-another/125922)

<div class="topic-metadata">

**Author:** [@jzakiya](https://discourse.julialang.org/u/jzakiya)\
**Replies:** 10\
**Last updated:** [March 10, 2025, 9:35pm UTC](https://discourse.julialang.org/t/improve-removing-members-of-one-array-from-another/125922 "2025-03-10T21:35:51Z")

</div>

The following Julua code is much slower than Ruby and Python because of the slow way it removes the members of one array from another. function prime\_pairs\_lohi(n) if (n&1 == 1 || n \< 4) return println("Input not even…

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

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