# Performance

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

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

**Page:** 58

---

## [Efficiently copying a tree with shared children](https://discourse.julialang.org/t/efficiently-copying-a-tree-with-shared-children/87787)

<div class="topic-metadata">

**Author:** [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Replies:** 20\
**Last updated:** [September 27, 2022, 4:07pm UTC](https://discourse.julialang.org/t/efficiently-copying-a-tree-with-shared-children/87787 "2022-09-27T16:07:35Z")

</div>

What is the most efficient way to copy a tree with shared children? While this is technically a graph rather than a tree, here there is a clear root node and directionality, so it’s more intuitive to think of it as a tre…

---

## [How to pass a buffer to a C callback function?](https://discourse.julialang.org/t/how-to-pass-a-buffer-to-a-c-callback-function/87716)

<div class="topic-metadata">

**Author:** [@tt1234567](https://discourse.julialang.org/u/tt1234567)\
**Replies:** 10\
**Last updated:** [September 27, 2022, 10:27am UTC](https://discourse.julialang.org/t/how-to-pass-a-buffer-to-a-c-callback-function/87716 "2022-09-27T10:27:00Z")

</div>

Following my question in Help with real-time performance needed - #16 by tt1234567, I’ve been thinking about writing a non-allocating recv\_into! function to receive a UDP packet into an existing buffer without creating a…

---

## [Gnuplot error](https://discourse.julialang.org/t/gnuplot-error/83863)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 31\
**Last updated:** [September 26, 2022, 4:56pm UTC](https://discourse.julialang.org/t/gnuplot-error/83863 "2022-09-26T16:56:19Z")

</div>

I’m now getting these errors with Gnuplot.jl: Cound not start a gnuplot process with command "gnuplot". Enabling dry sessions... How does one debug something like this? I checked, and gnuplot can be started from …

---

## [CUDA.jl kernel is half as fast as c++ Kernel](https://discourse.julialang.org/t/cuda-jl-kernel-is-half-as-fast-as-c-kernel/87651)

<div class="topic-metadata">

**Author:** [@fft](https://discourse.julialang.org/u/fft)\
**Replies:** 11\
**Last updated:** [September 26, 2022, 2:19am UTC](https://discourse.julialang.org/t/cuda-jl-kernel-is-half-as-fast-as-c-kernel/87651 "2022-09-26T02:19:11Z")

</div>

I have a kernel I wrote using CUDA.jl. It gets the correct answer, but is half as fast as the equivalent c++/cuda kernel I coded up. I was hoping someone could look at it and see if there are any optimizations to be done…

---

## [Help with real-time performance needed](https://discourse.julialang.org/t/help-with-real-time-performance-needed/87635)

<div class="topic-metadata">

**Author:** [@tt1234567](https://discourse.julialang.org/u/tt1234567)\
**Replies:** 20\
**Last updated:** [September 25, 2022, 7:14pm UTC](https://discourse.julialang.org/t/help-with-real-time-performance-needed/87635 "2022-09-25T19:14:50Z")

</div>

I have an application which reads sensor data packets from a UDP multicast socket over a dedicated ethernet link, processes them and updates a display using the excellent Makie. This was working fine on our original syst…

---

## [Explain Performance of a Ylm Code](https://discourse.julialang.org/t/explain-performance-of-a-ylm-code/87764)

<div class="topic-metadata">

**Author:** [@cortner](https://discourse.julialang.org/u/cortner)\
**Replies:** 6\
**Last updated:** [September 25, 2022, 5:55pm UTC](https://discourse.julialang.org/t/explain-performance-of-a-ylm-code/87764 "2022-09-25T17:55:42Z")

</div>

The code below evaluates the standard complex spherical harmonics for a batch of inputs given in terms of cos, sin and the associated legendre functions (which are already precomputed - in the “real” scenario they would …

---

## [Major performance boost when precaching random inputs to \`\`\`exp\`\`\`?](https://discourse.julialang.org/t/major-performance-boost-when-precaching-random-inputs-to-exp/85740)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 8\
**Last updated:** [September 25, 2022, 1:28pm UTC](https://discourse.julialang.org/t/major-performance-boost-when-precaching-random-inputs-to-exp/85740 "2022-09-25T13:28:41Z")

</div>

I’m writing a Monte Carlo simulation which requires exponentials of uniformly distributed random numbers. Calling exp takes a sizeable portion of my my inner loop runtime, and so I thought to cache pre-calculated value. …

---

## [Reducing allocations in a stencil function](https://discourse.julialang.org/t/reducing-allocations-in-a-stencil-function/87733)

<div class="topic-metadata">

**Author:** [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Replies:** 6\
**Last updated:** [September 24, 2022, 12:20pm UTC](https://discourse.julialang.org/t/reducing-allocations-in-a-stencil-function/87733 "2022-09-24T12:20:38Z")

</div>

I’m writing a function that takes a matrix X and returns a matrix Y of the same dimensions such that Y\[i, j\] is the sum of the values in the eight cells surrounding X\[i, j\]. This function is the “number of neighbors” fun…

---

## [Multithreaded LAPACK function in a Threads.@threads loop](https://discourse.julialang.org/t/multithreaded-lapack-function-in-a-threads-threads-loop/45205)

<div class="topic-metadata">

**Author:** [@migarstka](https://discourse.julialang.org/u/migarstka)\
**Replies:** 2\
**Last updated:** [September 24, 2022, 6:42am UTC](https://discourse.julialang.org/t/multithreaded-lapack-function-in-a-threads-threads-loop/45205 "2022-09-24T06:42:31Z")

</div>

Hi everyone, Problem I am trying to understand how to optimally set the number of BLAS threads when I am using a multithreaded LAPACK function in a Threads.@threads loop. More specifically I want to compute the eigende…

---

## [Get vector of vectors of indice of appearances for every unique element of an array](https://discourse.julialang.org/t/get-vector-of-vectors-of-indice-of-appearances-for-every-unique-element-of-an-array/87671)

<div class="topic-metadata">

**Author:** [@elii17](https://discourse.julialang.org/u/elii17)\
**Replies:** 5\
**Last updated:** [September 23, 2022, 5:35pm UTC](https://discourse.julialang.org/t/get-vector-of-vectors-of-indice-of-appearances-for-every-unique-element-of-an-array/87671 "2022-09-23T17:35:44Z")

</div>

Hey, I am trying to get a vector of vectors containing the indices of the appearance of every unique element of an array. So far i have tried y = \[1,2,2,3,5,5,6,1\] unique\_elements = unique(y) unique\_elements = \[1,2,3…

---

## [A limit to free operations of my own type](https://discourse.julialang.org/t/a-limit-to-free-operations-of-my-own-type/87690)

<div class="topic-metadata">

**Author:** [@mongi](https://discourse.julialang.org/u/mongi)\
**Replies:** 0\
**Last updated:** [September 23, 2022, 8:33am UTC](https://discourse.julialang.org/t/a-limit-to-free-operations-of-my-own-type/87690 "2022-09-23T08:33:38Z")

</div>

Hi, I have my own type (fields Vector and Int) and implemented (+,-,\*,/) for it “mulT(args…), addT, subT, divT”, and it works without allocations until length(args)\>7 for multiplication and 9 for addition. For each oper…

---

## [Code becomes really slow when I combine StaticArrays and DoubleFloats](https://discourse.julialang.org/t/code-becomes-really-slow-when-i-combine-staticarrays-and-doublefloats/87661)

<div class="topic-metadata">

**Author:** [@jisutich](https://discourse.julialang.org/u/jisutich)\
**Replies:** 18\
**Last updated:** [September 23, 2022, 4:19am UTC](https://discourse.julialang.org/t/code-becomes-really-slow-when-i-combine-staticarrays-and-doublefloats/87661 "2022-09-23T04:19:50Z")

</div>

Hi: I have some code to frequently generate haar random matrices and I want it to run fast. I use the suggestion in https://discourse.julialang.org/t/code-speed-decreases-when-loop-number-increases/78920 that I can use S…

---

## [How to use my CPU's](https://discourse.julialang.org/t/how-to-use-my-cpus/87390)

<div class="topic-metadata">

**Author:** [@Ross\_Boylan](https://discourse.julialang.org/u/Ross_Boylan)\
**Replies:** 13\
**Last updated:** [September 22, 2022, 10:50pm UTC](https://discourse.julialang.org/t/how-to-use-my-cpus/87390 "2022-09-22T22:50:32Z")

</div>

I instantiated an environment and watched for 533 seconds as it compiled over 100 packages. During this time julia cpu useage maxed at 12%, i.e., one of the 8 cores I have. What is the best way to use more of my cores?…

---

## [Allocations due to Boolean keyword arguments - how to avoid them?](https://discourse.julialang.org/t/allocations-due-to-boolean-keyword-arguments-how-to-avoid-them/87654)

<div class="topic-metadata">

**Author:** [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Replies:** 9\
**Last updated:** [September 22, 2022, 6:00pm UTC](https://discourse.julialang.org/t/allocations-due-to-boolean-keyword-arguments-how-to-avoid-them/87654 "2022-09-22T18:00:08Z")

</div>

Deep in one of my projects I have a function that slightly changes behavior depending on a boolean keyword. It seems if the keyword is Val{Bool} there are no allocations but if it is Bool, then it allocates. Here is a co…

---

## [How to run two tasks on parallel?](https://discourse.julialang.org/t/how-to-run-two-tasks-on-parallel/86902)

<div class="topic-metadata">

**Author:** [@Amro](https://discourse.julialang.org/u/Amro)\
**Replies:** 30\
**Last updated:** [September 22, 2022, 1:29pm UTC](https://discourse.julialang.org/t/how-to-run-two-tasks-on-parallel/86902 "2022-09-22T13:29:07Z")

</div>

if I have two tasks and I need to them on parallel. What is the organization to do that in Julia? For example the following using LinearAlgebra, SparseArrays, n = 1000; d = 10; A1 = sprand(n,n,d/n); x1 = rand(n); A2 = s…

---

## [Dataframes combine over 100s of columns](https://discourse.julialang.org/t/dataframes-combine-over-100s-of-columns/87446)

<div class="topic-metadata">

**Author:** [@bicepjai](https://discourse.julialang.org/u/bicepjai)\
**Replies:** 22\
**Last updated:** [September 21, 2022, 8:36pm UTC](https://discourse.julialang.org/t/dataframes-combine-over-100s-of-columns/87446 "2022-09-21T20:36:52Z")

</div>

Trying to perform combine over one columns logged over multiple days and get delta (max - min) for 300 columns in a dataset with 10 million rows. How can i do this efficiently ? I also notice if i combine over 10 co…

---

## [Sum of rationals](https://discourse.julialang.org/t/sum-of-rationals/87581)

<div class="topic-metadata">

**Author:** [@fa-bien](https://discourse.julialang.org/u/fa-bien)\
**Replies:** 1\
**Last updated:** [September 21, 2022, 3:51pm UTC](https://discourse.julialang.org/t/sum-of-rationals/87581 "2022-09-21T15:51:06Z")

</div>

I wrote the following function to calculate the sum of a vector of rational numbers: function rationalsum(numbers::Vector{T} where T\<:Rational) den = lcm(\[x.den for x in numbers\]) nums = (x.num \* div(den, x.den)…

---

## [Allocations with BlockArrays multiplication](https://discourse.julialang.org/t/allocations-with-blockarrays-multiplication/87331)

<div class="topic-metadata">

**Author:** [@moataz-sabry](https://discourse.julialang.org/u/moataz-sabry)\
**Replies:** 1\
**Last updated:** [September 21, 2022, 1:39pm UTC](https://discourse.julialang.org/t/allocations-with-blockarrays-multiplication/87331 "2022-09-21T13:39:14Z")

</div>

I’m trying to do a vector matrix multiplication and store the result in a block vector from the BlockArrays package. But I ended up with a lot of allocations. Any ideas why? using BlockArrays, BenchmarkTools, LinearAlge…

---

## [How to match performance of sum(A, dims=1)?](https://discourse.julialang.org/t/how-to-match-performance-of-sum-a-dims-1/87543)

<div class="topic-metadata">

**Author:** [@torrance](https://discourse.julialang.org/u/torrance)\
**Replies:** 14\
**Last updated:** [September 21, 2022, 6:25am UTC](https://discourse.julialang.org/t/how-to-match-performance-of-sum-a-dims-1/87543 "2022-09-21T06:25:50Z")

</div>

Well, this is a bit embarrassing… I’m writing up a set of slides to present to colleagues about Julia, and I wanted to show an example how explicit looping and so on is fine and dandy and as fast as any other language co…

---

## [Optimizing a 2D masked mean](https://discourse.julialang.org/t/optimizing-a-2d-masked-mean/87455)

<div class="topic-metadata">

**Author:** [@kiranshila](https://discourse.julialang.org/u/kiranshila)\
**Replies:** 10\
**Last updated:** [September 20, 2022, 4:30pm UTC](https://discourse.julialang.org/t/optimizing-a-2d-masked-mean/87455 "2022-09-20T16:30:48Z")

</div>

Hey everyone! I’m working on a small package to be used as RFI mitigation in a radio telescope, and I’m getting a little stuck optimizing a small piece of the code. Specifically, I need to be able to take the mean down …

---

## [Vectorize but break early?](https://discourse.julialang.org/t/vectorize-but-break-early/87362)

<div class="topic-metadata">

**Author:** [@abulak](https://discourse.julialang.org/u/abulak)\
**Replies:** 3\
**Last updated:** [September 20, 2022, 3:10pm UTC](https://discourse.julialang.org/t/vectorize-but-break-early/87362 "2022-09-20T15:10:14Z")

</div>

I’d like to properly vectorize this: """ issuffix(u, v) Check if \`u\` is a suffix of \`v\` """ function issuffix(u::AbstractVector, v::AbstractVector) lu = length(u) lu ≤ length(v) || return false @inbounds…

---

## [Nested Loop optimization](https://discourse.julialang.org/t/nested-loop-optimization/87498)

<div class="topic-metadata">

**Author:** [@Jojo](https://discourse.julialang.org/u/Jojo)\
**Replies:** 2\
**Last updated:** [September 20, 2022, 12:01am UTC](https://discourse.julialang.org/t/nested-loop-optimization/87498 "2022-09-20T00:01:50Z")

</div>

Hello, I’ve been working on a solver where I have a nested loop and I want to improve the performance. I think that I’m making unnecessary allocations, for instance I have to write a=copy(a) to force the inner loop to up…

---

## [Optimizing nested for loops and memory allocation in finite differences routine](https://discourse.julialang.org/t/optimizing-nested-for-loops-and-memory-allocation-in-finite-differences-routine/87488)

<div class="topic-metadata">

**Author:** [@Jojo](https://discourse.julialang.org/u/Jojo)\
**Replies:** 3\
**Last updated:** [September 19, 2022, 9:54pm UTC](https://discourse.julialang.org/t/optimizing-nested-for-loops-and-memory-allocation-in-finite-differences-routine/87488 "2022-09-19T21:54:34Z")

</div>

Hi, guys. I’ve been working in a nonlinear wave equation solver using finite differences. My code works properly but I’d like to improve the performance, im working on a 12000\*39000 grid and the average @btime is 15s. I’…

---

## [Pre-allocate for findall](https://discourse.julialang.org/t/pre-allocate-for-findall/87454)

<div class="topic-metadata">

**Author:** [@MacKenzieHnC](https://discourse.julialang.org/u/MacKenzieHnC)\
**Replies:** 16\
**Last updated:** [September 19, 2022, 1:24am UTC](https://discourse.julialang.org/t/pre-allocate-for-findall/87454 "2022-09-19T01:24:43Z")

</div>

I am absolutely sure something like this has been asked before but I cannot for the life of me find it. I’m currently working on a memory- and speed-efficient way to access the first 1 billion primes as part of a differ…

---

## [Allocation during construction of compile-time sized structure](https://discourse.julialang.org/t/allocation-during-construction-of-compile-time-sized-structure/87435)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 1\
**Last updated:** [September 18, 2022, 12:25pm UTC](https://discourse.julialang.org/t/allocation-during-construction-of-compile-time-sized-structure/87435 "2022-09-18T12:25:04Z")

</div>

I have a simple, immutable structure that wraps a statically sized matrix. When I construct it with an initialization value, it causes a memory allocation. I expected there to be no such allocation. Should there be an al…

---

## [Nice work on Julia 1.8/1.8.1 on MacOS ARM](https://discourse.julialang.org/t/nice-work-on-julia-1-8-1-8-1-on-macos-arm/87378)

<div class="topic-metadata">

**Author:** [@lewis](https://discourse.julialang.org/u/lewis)\
**Replies:** 0\
**Last updated:** [September 16, 2022, 4:18pm UTC](https://discourse.julialang.org/t/nice-work-on-julia-1-8-1-8-1-on-macos-arm/87378 "2022-09-16T16:18:42Z")

</div>

This build is giving me no problems at all. I’d say the Julia native ARM version is around 30% faster than the Intel version running on Rosetta (Apple’s Intel emulation layer) based on very informal timings. I time sect…

---

## [Shouldn't 1.8.0 be faster than Julia 1.7?](https://discourse.julialang.org/t/shouldnt-1-8-0-be-faster-than-julia-1-7/82143)

<div class="topic-metadata">

**Author:** [@mindaslab](https://discourse.julialang.org/u/mindaslab)\
**Replies:** 30\
**Last updated:** [September 16, 2022, 3:01pm UTC](https://discourse.julialang.org/t/shouldnt-1-8-0-be-faster-than-julia-1-7/82143 "2022-09-16T15:01:12Z")

</div>

---

## [Question on Julia Blog Post regarding Performance](https://discourse.julialang.org/t/question-on-julia-blog-post-regarding-performance/87342)

<div class="topic-metadata">

**Author:** [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)\
**Replies:** 1\
**Last updated:** [September 16, 2022, 3:48am UTC](https://discourse.julialang.org/t/question-on-julia-blog-post-regarding-performance/87342 "2022-09-16T03:48:15Z")

</div>

I was searching around for Julia comparisons to C++ and found this write-up from 2019. I follow most of it but one point I was curious about is near the end where they implemented @simd, @fastmath, and @inbounds. I wou…

---

## [Code in Threads.@threads takes longer than in single-threaded code](https://discourse.julialang.org/t/code-in-threads-threads-takes-longer-than-in-single-threaded-code/87313)

<div class="topic-metadata">

**Author:** [@dafred](https://discourse.julialang.org/u/dafred)\
**Replies:** 0\
**Last updated:** [September 15, 2022, 1:57pm UTC](https://discourse.julialang.org/t/code-in-threads-threads-takes-longer-than-in-single-threaded-code/87313 "2022-09-15T13:57:27Z")

</div>

So I’m trying to reduce execution times of closure loss that is returned from construct loss. I figured that multithreading might help me. I am mostly interested in speeding up ForwardDiff.gradient(loss, p\_initial) but…

---

## [Threads.@threads ~44 times slower than single threaded code](https://discourse.julialang.org/t/threads-threads-44-times-slower-than-single-threaded-code/87282)

<div class="topic-metadata">

**Author:** [@Kaguro](https://discourse.julialang.org/u/Kaguro)\
**Replies:** 8\
**Last updated:** [September 14, 2022, 8:15pm UTC](https://discourse.julialang.org/t/threads-threads-44-times-slower-than-single-threaded-code/87282 "2022-09-14T20:15:43Z")

</div>

Hello All. I have a program where I basically solve a system of ODEs at N time points using Euler method, and add the solution to an array. N is ~1000 Then I wrap this in another loop which runs the inner loop M times.…

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

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