# Performance

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

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

**Page:** 92

---

## [Asynchronous Programming and "Threads.@threads for" with limited number of threads](https://discourse.julialang.org/t/asynchronous-programming-and-threads-threads-for-with-limited-number-of-threads/62138)

<div class="topic-metadata">

**Author:** [@AnBenLa](https://discourse.julialang.org/u/AnBenLa)\
**Replies:** 2\
**Last updated:** [June 1, 2021, 3:11pm UTC](https://discourse.julialang.org/t/asynchronous-programming-and-threads-threads-for-with-limited-number-of-threads/62138 "2021-06-01T15:11:50Z")

</div>

Hi, I hope I selected the right topic for my question. Please tell me if I did something wrong as it is my first time posting here. It seems as I am not able to use the @ symbol so I replaced it with \[at\]. I am worki…

---

## [Sub-sample array until a target number of unique elements is left](https://discourse.julialang.org/t/sub-sample-array-until-a-target-number-of-unique-elements-is-left/61981)

<div class="topic-metadata">

**Author:** [@mlanghinrichs](https://discourse.julialang.org/u/mlanghinrichs)\
**Replies:** 18\
**Last updated:** [May 31, 2021, 9:47am UTC](https://discourse.julialang.org/t/sub-sample-array-until-a-target-number-of-unique-elements-is-left/61981 "2021-05-31T09:47:31Z")

</div>

Hey! I’m in need of a fast method that uniformly subsamples the elements of a given array until only a specified number of unique elements is left. For example input array=\[4,1,2,2,4\] and target\_unique\_el=2, then the (r…

---

## [Looking for advice on achieving faster startup times](https://discourse.julialang.org/t/looking-for-advice-on-achieving-faster-startup-times/61160)

<div class="topic-metadata">

**Author:** [@enriquer](https://discourse.julialang.org/u/enriquer)\
**Replies:** 11\
**Last updated:** [May 30, 2021, 7:25am UTC](https://discourse.julialang.org/t/looking-for-advice-on-achieving-faster-startup-times/61160 "2021-05-30T07:25:45Z")

</div>

(reposting from a Julia+ARM thread because this is not really ARM specific) I am testing the feasibility of using Julia for an embedded Linux platform. Our current target hardware has a Cortex-A7 based SOC which can run…

---

## [Simple addition using Transducers via single-threaded foldl , multi-threaded foldxt always calculates two (slightly) different answers](https://discourse.julialang.org/t/simple-addition-using-transducers-via-single-threaded-foldl-multi-threaded-foldxt-always-calculates-two-slightly-different-answers/62024)

<div class="topic-metadata">

**Author:** [@Marc.Cox](https://discourse.julialang.org/u/Marc.Cox)\
**Replies:** 4\
**Last updated:** [May 29, 2021, 10:29pm UTC](https://discourse.julialang.org/t/simple-addition-using-transducers-via-single-threaded-foldl-multi-threaded-foldxt-always-calculates-two-slightly-different-answers/62024 "2021-05-29T22:29:21Z")

</div>

Simple addition using Transducers via single-threaded foldl , multi-threaded foldxt calculates two (slightly) different answers . IOW Is the single-threaded foldl , multi-threaded foldxt, or None of them correct ? Some…

---

## [Possible performance drop when using more than one socket threads](https://discourse.julialang.org/t/possible-performance-drop-when-using-more-than-one-socket-threads/62022)

<div class="topic-metadata">

**Author:** [@shipengcheng1230](https://discourse.julialang.org/u/shipengcheng1230)\
**Replies:** 2\
**Last updated:** [May 29, 2021, 4:50pm UTC](https://discourse.julialang.org/t/possible-performance-drop-when-using-more-than-one-socket-threads/62022 "2021-05-29T16:50:51Z")

</div>

Hello, this is originally raised in an issue. I hope posting here would bring more attention. Some dummy code for solving ODE: # Julia 1.6.1 using FFTW, BenchmarkTools, LinearAlgebra, Printf, Polyester, Random println…

---

## [What's the most efficient way to sum the results of multithreading?](https://discourse.julialang.org/t/whats-the-most-efficient-way-to-sum-the-results-of-multithreading/61944)

<div class="topic-metadata">

**Author:** [@yingqiuz](https://discourse.julialang.org/u/yingqiuz)\
**Replies:** 3\
**Last updated:** [May 28, 2021, 10:23pm UTC](https://discourse.julialang.org/t/whats-the-most-efficient-way-to-sum-the-results-of-multithreading/61944 "2021-05-28T22:23:53Z")

</div>

Hi, I need to sum the outputs of each thread. Is there a standard/efficient way to do this? for example: X = Matrix{Float64}(d, N) Threads.@threads for k = 1:N X\[:, k\] .= some\_calculations() end sum!(ones(Int64, d…

---

## [Massive data-dependent floating-point slowdown](https://discourse.julialang.org/t/massive-data-dependent-floating-point-slowdown/62017)

<div class="topic-metadata">

**Author:** [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Replies:** 3\
**Last updated:** [May 28, 2021, 9:36pm UTC](https://discourse.julialang.org/t/massive-data-dependent-floating-point-slowdown/62017 "2021-05-28T21:36:17Z")

</div>

I encountered a mysterious case where the same floating-point computation experiences a massive slowdown depending on the data — a factor of 20, or even 60 if I use @turbo from LoopVectorization.jl. I’m guessing it has …

---

## [Small, fixed powers](https://discourse.julialang.org/t/small-fixed-powers/61991)

<div class="topic-metadata">

**Author:** [@scheinerman](https://discourse.julialang.org/u/scheinerman)\
**Replies:** 5\
**Last updated:** [May 28, 2021, 2:41pm UTC](https://discourse.julialang.org/t/small-fixed-powers/61991 "2021-05-28T14:41:32Z")

</div>

Consider these two functions for computing the 4-th power: power4(x) = x^4 power31(x) = x \* x^3 The second is much speedier than the first because (looking at code\_llvm or code\_native) the first calls a general helper …

---

## [Fortran calling Julia. Julia 10x slower than Fortran](https://discourse.julialang.org/t/fortran-calling-julia-julia-10x-slower-than-fortran/61736)

<div class="topic-metadata">

**Author:** [@eduardovrs](https://discourse.julialang.org/u/eduardovrs)\
**Replies:** 15\
**Last updated:** [May 27, 2021, 7:11pm UTC](https://discourse.julialang.org/t/fortran-calling-julia-julia-10x-slower-than-fortran/61736 "2021-05-27T19:11:26Z")

</div>

Fortran calling Julia. Julia 10x slower than Fortran Dear Julia community, I am a beginner programmer and I enjoyed learning and coding in Julia a lot. I have been working on a Julia interface for Finite Element Analys…

---

## [Threads.@threads parallelism and htop](https://discourse.julialang.org/t/threads-threads-parallelism-and-htop/61762)

<div class="topic-metadata">

**Author:** [@cricci](https://discourse.julialang.org/u/cricci)\
**Replies:** 2\
**Last updated:** [May 25, 2021, 1:45pm UTC](https://discourse.julialang.org/t/threads-threads-parallelism-and-htop/61762 "2021-05-25T13:45:03Z")

</div>

Hello, on my machine I am observing the following behavior when running julia 1.6 and using DifferentialEquations.jl to solve a PDE. Basically I wrote a function f!(du,u,p,t) that uses the macro Threads.@threads insid…

---

## [Optimization allowed in C++14, not done in Julia, but could it be done?](https://discourse.julialang.org/t/optimization-allowed-in-c-14-not-done-in-julia-but-could-it-be-done/61217)

<div class="topic-metadata">

**Author:** [@Palli](https://discourse.julialang.org/u/Palli)\
**Replies:** 7\
**Last updated:** [May 24, 2021, 5:27am UTC](https://discourse.julialang.org/t/optimization-allowed-in-c-14-not-done-in-julia-but-could-it-be-done/61217 "2021-05-24T05:27:56Z")

</div>

I tried something similar to here: julia\> function demo() for i in 0:9 v = \[1, 2, 3\] push!(v, i) println(size(v)) end end demo (generic function with 1 method)…

---

## [Weird @btime results with \`sin\`](https://discourse.julialang.org/t/weird-btime-results-with-sin/61644)

<div class="topic-metadata">

**Author:** [@cryptic.ax](https://discourse.julialang.org/u/cryptic.ax)\
**Replies:** 1\
**Last updated:** [May 22, 2021, 4:23pm UTC](https://discourse.julialang.org/t/weird-btime-results-with-sin/61644 "2021-05-22T16:23:44Z")

</div>

I was profiling timing differences between using sin, sind, and I noticed some interesting results. julia\> using BenchmarkTools julia\> sin(10); julia\> sind(10); julia\> const ° = π/180; julia\> x = 1.234; julia\> @bti…

---

## [Performance decrease after renaming functions](https://discourse.julialang.org/t/performance-decrease-after-renaming-functions/61577)

<div class="topic-metadata">

**Author:** [@Tusike](https://discourse.julialang.org/u/Tusike)\
**Replies:** 2\
**Last updated:** [May 21, 2021, 2:04pm UTC](https://discourse.julialang.org/t/performance-decrease-after-renaming-functions/61577 "2021-05-21T14:04:09Z")

</div>

Hi! A have a function AND which takes a pre-allocated vector and writes in the result of some operations. Following the julia naming convention, I wanted to change its name to AND! so that this behavior is reflected com…

---

## [Simple random walk performance tips](https://discourse.julialang.org/t/simple-random-walk-performance-tips/61553)

<div class="topic-metadata">

**Author:** [@Babou](https://discourse.julialang.org/u/Babou)\
**Replies:** 6\
**Last updated:** [May 21, 2021, 8:39am UTC](https://discourse.julialang.org/t/simple-random-walk-performance-tips/61553 "2021-05-21T08:39:54Z")

</div>

Hi all I have written a small code chunk for a generic random walk, as I am hoping to use julia for dynamic systems simulations this will be a good toy example for me to improve memory usage. function rwalks(T,N,n) …

---

## [Zygote gradient results in slow Tuple getindex calls](https://discourse.julialang.org/t/zygote-gradient-results-in-slow-tuple-getindex-calls/48767)

<div class="topic-metadata">

**Author:** [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Replies:** 6\
**Last updated:** [May 20, 2021, 6:19pm UTC](https://discourse.julialang.org/t/zygote-gradient-results-in-slow-tuple-getindex-calls/48767 "2021-05-20T18:19:13Z")

</div>

Hey, I’m working on an optimization problem and I’m using Zygote to calculate the gradients (code). Initially a lot of the chain rules were implemented manually by code but then I switched so that Zygote can do this st…

---

## [\[SOLVED\] 37x performance hit when wrapping Refs. Any solution?](https://discourse.julialang.org/t/solved-37x-performance-hit-when-wrapping-refs-any-solution/61499)

<div class="topic-metadata">

**Author:** [@fverdugo](https://discourse.julialang.org/u/fverdugo)\
**Replies:** 2\
**Last updated:** [May 20, 2021, 8:39am UTC](https://discourse.julialang.org/t/solved-37x-performance-hit-when-wrapping-refs-any-solution/61499 "2021-05-20T08:39:08Z")

</div>

Problem I have found that wrapping Ref instances in a struct leads to a sizable performance hit. Here a MWE: using BenchmarkTools struct Foo ref::Ref{Int} Foo(a::Int) = new(Ref(a)) end work(i,ref::Ref) = sqrt(i\*re…

---

## [Mutithreading of 3-nested loops for solving integral equations](https://discourse.julialang.org/t/mutithreading-of-3-nested-loops-for-solving-integral-equations/61485)

<div class="topic-metadata">

**Author:** [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Replies:** 0\
**Last updated:** [May 20, 2021, 12:03am UTC](https://discourse.julialang.org/t/mutithreading-of-3-nested-loops-for-solving-integral-equations/61485 "2021-05-20T00:03:12Z")

</div>

Continuing the discussion from Multithreading for nested loops:

---

## [The Julia REPL: How clean environment variables. VSCODE](https://discourse.julialang.org/t/the-julia-repl-how-clean-environment-variables-vscode/59940)

<div class="topic-metadata">

**Author:** [@Hermes](https://discourse.julialang.org/u/Hermes)\
**Replies:** 5\
**Last updated:** [May 19, 2021, 1:38pm UTC](https://discourse.julialang.org/t/the-julia-repl-how-clean-environment-variables-vscode/59940 "2021-05-19T13:38:52Z")

</div>

How to clean, delete the environment variables initialized during the running of a script in REPL; to avoid conflicts when running another script with variables with the same names but different types. How would it be i…

---

## [Fma's and poly eval](https://discourse.julialang.org/t/fmas-and-poly-eval/61421)

<div class="topic-metadata">

**Author:** [@jarl](https://discourse.julialang.org/u/jarl)\
**Replies:** 4\
**Last updated:** [May 19, 2021, 9:42am UTC](https://discourse.julialang.org/t/fmas-and-poly-eval/61421 "2021-05-19T09:42:33Z")

</div>

I want to evaluate a polynomial of degree 8. Two ways of doing this: @inline function standard\_eval(x) p = evalpoly(x, (0.16666666666666632, 0.04166666666666556, 0.008333333333401227, 0.00138888…

---

## [Timeseries Optimization : Reducing allocations](https://discourse.julialang.org/t/timeseries-optimization-reducing-allocations/61251)

<div class="topic-metadata">

**Author:** [@EdgarHR](https://discourse.julialang.org/u/EdgarHR)\
**Replies:** 10\
**Last updated:** [May 18, 2021, 6:25am UTC](https://discourse.julialang.org/t/timeseries-optimization-reducing-allocations/61251 "2021-05-18T06:25:55Z")

</div>

Hello everyone! I was working on a project and wanted to start reformatting the code to make it faster. As part of this process I am working on reducing the amount of allocations as much as possible. Currently I have a …

---

## [Memory reuse problem in for loop](https://discourse.julialang.org/t/memory-reuse-problem-in-for-loop/61290)

<div class="topic-metadata">

**Author:** [@deil](https://discourse.julialang.org/u/deil)\
**Replies:** 10\
**Last updated:** [May 18, 2021, 2:24am UTC](https://discourse.julialang.org/t/memory-reuse-problem-in-for-loop/61290 "2021-05-18T02:24:31Z")

</div>

I was implementing an algorithm to detect edges in RGB images, when I noticed very high memory usage: function coloredge(img::Matrix{RGB{T}})::Matrix{T} where T \<: AbstractFloat Sy, Sx = size(img) z = zeros…

---

## [Weird allocation issue for fill! with ArrayPartition in Julia \< 1.6](https://discourse.julialang.org/t/weird-allocation-issue-for-fill-with-arraypartition-in-julia-1-6/61296)

<div class="topic-metadata">

**Author:** [@Salmon](https://discourse.julialang.org/u/Salmon)\
**Replies:** 1\
**Last updated:** [May 17, 2021, 3:31pm UTC](https://discourse.julialang.org/t/weird-allocation-issue-for-fill-with-arraypartition-in-julia-1-6/61296 "2021-05-17T15:31:10Z")

</div>

Hello Julians, I have an issue with allocations that I encountered while running my code on a cluster which uses Julia 1.5.4. Basically, once my partition array gets reasonably large, I encounter many allocations when c…

---

## [Strange Pluto performance on Binder](https://discourse.julialang.org/t/strange-pluto-performance-on-binder/61305)

<div class="topic-metadata">

**Author:** [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)\
**Replies:** 0\
**Last updated:** [May 17, 2021, 2:06pm UTC](https://discourse.julialang.org/t/strange-pluto-performance-on-binder/61305 "2021-05-17T14:06:13Z")

</div>

I created a Pluto notebook to capture some the performance tips in the manual, and everything seems to run fine on my home computer. But I am getting an odd result when trying to run the notebook on Binder using this Plu…

---

## [Find Reimann zeta's zeros with SpecialFunctions and Roots](https://discourse.julialang.org/t/find-reimann-zetas-zeros-with-specialfunctions-and-roots/61275)

<div class="topic-metadata">

**Author:** [@Wei\_Yang](https://discourse.julialang.org/u/Wei_Yang)\
**Replies:** 2\
**Last updated:** [May 17, 2021, 2:11am UTC](https://discourse.julialang.org/t/find-reimann-zetas-zeros-with-specialfunctions-and-roots/61275 "2021-05-17T02:11:13Z")

</div>

To find the zeros of the Reimann \\zeta with real part 1/2, and imaginary part less than 1000 in norm, the following is what I’m using at the moment, using SpecialFunctions using Roots g(x) = abs(zeta(.5 + x\*im)) Z =\[\] …

---

## [Same code much faster on a Ryzen than on a Xeon?](https://discourse.julialang.org/t/same-code-much-faster-on-a-ryzen-than-on-a-xeon/60534)

<div class="topic-metadata">

**Author:** [@ederag](https://discourse.julialang.org/u/ederag)\
**Replies:** 10\
**Last updated:** [May 16, 2021, 10:41pm UTC](https://discourse.julialang.org/t/same-code-much-faster-on-a-ryzen-than-on-a-xeon/60534 "2021-05-16T22:41:04Z")

</div>

The time\_evolution ODE kernel below is blazing fast on a Ryzen, and more than 4 times slower on a Xeon. This difference is striking, as usually both machines have similar single thread performances. (more on that below…

---

## [Does Mac M1 in multithreads is slower that in single thread?](https://discourse.julialang.org/t/does-mac-m1-in-multithreads-is-slower-that-in-single-thread/61114)

<div class="topic-metadata">

**Author:** [@BMval](https://discourse.julialang.org/u/BMval)\
**Replies:** 10\
**Last updated:** [May 16, 2021, 6:48pm UTC](https://discourse.julialang.org/t/does-mac-m1-in-multithreads-is-slower-that-in-single-thread/61114 "2021-05-16T18:48:31Z")

</div>

I’ve run a simple code on mac M1 (pro, 8gb ram), Julia is the last version. @Threads for i in 1:1000 rand(1000,1000)/rand(1000,1000) end 1 core = 50 sec 2 core = 62 sec 4 core = 71 sec 8 core = doesn’t work at all. …

---

## [Need help speeding up ode ensemble problem; preallocation and type instability?](https://discourse.julialang.org/t/need-help-speeding-up-ode-ensemble-problem-preallocation-and-type-instability/61216)

<div class="topic-metadata">

**Author:** [@ethansigh](https://discourse.julialang.org/u/ethansigh)\
**Replies:** 5\
**Last updated:** [May 16, 2021, 12:37am UTC](https://discourse.julialang.org/t/need-help-speeding-up-ode-ensemble-problem-preallocation-and-type-instability/61216 "2021-05-16T00:37:55Z")

</div>

Hi! I’m writing some particle tracing code with large ensemble sizes and it’s super slow. Because for my simulations I need really small timesteps, the solution is huge, and this takes a very very long time (like couple …

---

## [Using LinuxPerf for small functions](https://discourse.julialang.org/t/using-linuxperf-for-small-functions/60410)

<div class="topic-metadata">

**Author:** [@shmiggles](https://discourse.julialang.org/u/shmiggles)\
**Replies:** 7\
**Last updated:** [May 15, 2021, 2:39pm UTC](https://discourse.julialang.org/t/using-linuxperf-for-small-functions/60410 "2021-05-15T14:39:09Z")

</div>

LinuxPerf.jl wraps the perf\_event\_open Linux syscall. But using it for small functions gives ridiculous results. The following example reports over 12000 clock cycles and 2000 memory fetches to compute 1+1: using LinuxP…

---

## [Possible enum slowness?](https://discourse.julialang.org/t/possible-enum-slowness/59896)

<div class="topic-metadata">

**Author:** [@lewis](https://discourse.julialang.org/u/lewis)\
**Replies:** 3\
**Last updated:** [May 14, 2021, 11:12pm UTC](https://discourse.julialang.org/t/possible-enum-slowness/59896 "2021-05-14T23:12:10Z")

</div>

I may have encountered enum slowness–looking for insight. The background is a bit long: just skip to my question below. The application is a Covid simulation using a physical event approach at the level of individuals. …

---

## [Integrating functions with additional parameters](https://discourse.julialang.org/t/integrating-functions-with-additional-parameters/61169)

<div class="topic-metadata">

**Author:** [@dkiese](https://discourse.julialang.org/u/dkiese)\
**Replies:** 2\
**Last updated:** [May 14, 2021, 4:47pm UTC](https://discourse.julialang.org/t/integrating-functions-with-additional-parameters/61169 "2021-05-14T16:47:22Z")

</div>

Hello everyone, I have a question regarding performance of the following mwe: using BenchmarkTools function integrate!(f!, buf, a, b, N) h = (b - a) / N buf .= 0.0 for i in 1 : N f!(bu…

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

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