# Performance

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

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

**Page:** 40

---

## [Having issues speeding up code with multithreading](https://discourse.julialang.org/t/having-issues-speeding-up-code-with-multithreading/101508)

<div class="topic-metadata">

**Author:** [@RobertGregg](https://discourse.julialang.org/u/RobertGregg)\
**Replies:** 19\
**Last updated:** [July 16, 2023, 6:14am UTC](https://discourse.julialang.org/t/having-issues-speeding-up-code-with-multithreading/101508 "2023-07-16T06:14:24Z")

</div>

I’m trying to speed up some code that takes subsets of columns from a data matrix and calculates a maximum score. The orginal code is complicated, so I’ve tried to simplfy it was much as possible here: using Combinatori…

---

## [Fast Hessian and Gradient for PINNS using Enzyme/Zygote](https://discourse.julialang.org/t/fast-hessian-and-gradient-for-pinns-using-enzyme-zygote/101993)

<div class="topic-metadata">

**Author:** [@Baba\_Yara\_Fahiz](https://discourse.julialang.org/u/Baba_Yara_Fahiz)\
**Replies:** 0\
**Last updated:** [July 23, 2023, 11:41pm UTC](https://discourse.julialang.org/t/fast-hessian-and-gradient-for-pinns-using-enzyme-zygote/101993 "2023-07-23T23:41:34Z")

</div>

I am working on a problem that involves solving partial differential equations using neural networks. The current bottleneck in my code is computing the gradient and Hessian of batched data. My current implementation us…

---

## [Runtime of program using a large amount of memory stalls](https://discourse.julialang.org/t/runtime-of-program-using-a-large-amount-of-memory-stalls/99981)

<div class="topic-metadata">

**Author:** [@ilanggear](https://discourse.julialang.org/u/ilanggear)\
**Replies:** 4\
**Last updated:** [July 22, 2023, 6:41am UTC](https://discourse.julialang.org/t/runtime-of-program-using-a-large-amount-of-memory-stalls/99981 "2023-07-22T06:41:32Z")

</div>

I’m working on code to collect unigram and bigram counts of words and word features. For now I’m just working with less than a dozen smallish documents. Below are the results of @time on the first few docs. After the la…

---

## [Push! vs. pushfirst! performance issue with BitArrays](https://discourse.julialang.org/t/push-vs-pushfirst-performance-issue-with-bitarrays/101845)

<div class="topic-metadata">

**Author:** [@tradler](https://discourse.julialang.org/u/tradler)\
**Replies:** 1\
**Last updated:** [July 20, 2023, 5:28pm UTC](https://discourse.julialang.org/t/push-vs-pushfirst-performance-issue-with-bitarrays/101845 "2023-07-20T17:28:12Z")

</div>

push! seems to have equal speed as pushfirst! for non-bit vectors. In addition, for bit and non-bit vectors push! is equally fast. For bit and non-bit vectors pushfirst! is ~10Kx slower. Does this seem like an issue, or …

---

## [\`@fastmath\` is not applied to macros](https://discourse.julialang.org/t/fastmath-is-not-applied-to-macros/101835)

<div class="topic-metadata">

**Author:** [@Keluaa](https://discourse.julialang.org/u/Keluaa)\
**Replies:** 5\
**Last updated:** [July 20, 2023, 4:21pm UTC](https://discourse.julialang.org/t/fastmath-is-not-applied-to-macros/101835 "2023-07-20T16:21:30Z")

</div>

Today I discovered that @fastmath is not applied to inlined function calls (maybe this should be in the docs?), I understand that there is a good reason behind it. However I would have expected this to work on expressio…

---

## [Multithreading using more CPUs than expected](https://discourse.julialang.org/t/multithreading-using-more-cpus-than-expected/101599)

<div class="topic-metadata">

**Author:** [@lzxnl](https://discourse.julialang.org/u/lzxnl)\
**Replies:** 11\
**Last updated:** [July 20, 2023, 5:10am UTC](https://discourse.julialang.org/t/multithreading-using-more-cpus-than-expected/101599 "2023-07-20T05:10:57Z")

</div>

I opened a Jupyter Notebook kernel with 25 threads (threadid() prints out 25 in the beginning). I then proceed to run some code that manages to use 8900% CPU, as recorded by top on the terminal, i.e. 89 threads worth of …

---

## [Optimizing nested loops with conditional inside](https://discourse.julialang.org/t/optimizing-nested-loops-with-conditional-inside/101724)

<div class="topic-metadata">

**Author:** [@Luis\_Alberto\_R](https://discourse.julialang.org/u/Luis_Alberto_R)\
**Replies:** 10\
**Last updated:** [July 19, 2023, 3:30am UTC](https://discourse.julialang.org/t/optimizing-nested-loops-with-conditional-inside/101724 "2023-07-19T03:30:34Z")

</div>

Hello, I’m trying to build hydrodynamic codes in 1D, 2D and 3D in Julia. So far I have the codes working with first order solvers, and I’ve managed to make the 1D and 2D faster than Python and C++, now I’m trying to impl…

---

## [Better ways to deal with CompatHelper and compatibility upgrades](https://discourse.julialang.org/t/better-ways-to-deal-with-compathelper-and-compatibility-upgrades/88677)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 1\
**Last updated:** [July 18, 2023, 7:47am UTC](https://discourse.julialang.org/t/better-ways-to-deal-with-compathelper-and-compatibility-upgrades/88677 "2023-07-18T07:47:17Z")

</div>

After some time of innactivity, the CompatHelper bot stops working. Of course this is not an issue for large projects that are very active, but for smaller packages it is. Thus, I would like to know: Is there a way t…

---

## [Optimizing dinucleotides count in a DNA sequence type \`LongDNA\`](https://discourse.julialang.org/t/optimizing-dinucleotides-count-in-a-dna-sequence-type-longdna/101583)

<div class="topic-metadata">

**Author:** [@camilogarciabotero](https://discourse.julialang.org/u/camilogarciabotero)\
**Replies:** 21\
**Last updated:** [July 17, 2023, 5:33pm UTC](https://discourse.julialang.org/t/optimizing-dinucleotides-count-in-a-dna-sequence-type-longdna/101583 "2023-07-17T17:33:43Z")

</div>

I am working with the BioSequences.jl package, particularly a LongSequence{DNAAlphabet{4}} (a very efficient string) type like the following random DNA sequence seq = dna"ACACATCATCTACTATCAT" and I want a function that c…

---

## [Define multiple methods or one method with union types?](https://discourse.julialang.org/t/define-multiple-methods-or-one-method-with-union-types/101674)

<div class="topic-metadata">

**Author:** [@kunzaatko](https://discourse.julialang.org/u/kunzaatko)\
**Replies:** 4\
**Last updated:** [July 17, 2023, 2:03pm UTC](https://discourse.julialang.org/t/define-multiple-methods-or-one-method-with-union-types/101674 "2023-07-17T14:03:17Z")

</div>

What is the preferred way to implement methods that allow multiple types? Option A: function method(a::Union{Tuple{Integer,Integer}, Integer}, b::Union{Tuple{Integer,Integer}, Integer}) a = a isa Integer ? (a,a) : …

---

## [Efficiently computing Hessians of Neural Networks output with respect to inputs](https://discourse.julialang.org/t/efficiently-computing-hessians-of-neural-networks-output-with-respect-to-inputs/101666)

<div class="topic-metadata">

**Author:** [@Baba\_Yara\_Fahiz](https://discourse.julialang.org/u/Baba_Yara_Fahiz)\
**Replies:** 1\
**Last updated:** [July 16, 2023, 5:29am UTC](https://discourse.julialang.org/t/efficiently-computing-hessians-of-neural-networks-output-with-respect-to-inputs/101666 "2023-07-16T05:29:44Z")

</div>

Hello everyone, I’m currently working on a problem that involves approximating a partial differential equation using neural networks. I’ve created a script that generates a set of neural networks, computes their outputs…

---

## [Inline function returns tuple of mixed type, assigned to a tuple of variables in the caller](https://discourse.julialang.org/t/inline-function-returns-tuple-of-mixed-type-assigned-to-a-tuple-of-variables-in-the-caller/101598)

<div class="topic-metadata">

**Author:** [@Lian\_Yunlong](https://discourse.julialang.org/u/Lian_Yunlong)\
**Replies:** 2\
**Last updated:** [July 14, 2023, 6:30am UTC](https://discourse.julialang.org/t/inline-function-returns-tuple-of-mixed-type-assigned-to-a-tuple-of-variables-in-the-caller/101598 "2023-07-14T06:30:46Z")

</div>

Dear Julia community, I wish to learn the appropriate usage of Julia tuples. Consider the following scenario. One needs to make an inline function to separate a block of code inside a very complicated function. Natural…

---

## [In-place matrix operations slower?](https://discourse.julialang.org/t/in-place-matrix-operations-slower/101469)

<div class="topic-metadata">

**Author:** [@lzxnl](https://discourse.julialang.org/u/lzxnl)\
**Replies:** 9\
**Last updated:** [July 14, 2023, 3:23am UTC](https://discourse.julialang.org/t/in-place-matrix-operations-slower/101469 "2023-07-14T03:23:49Z")

</div>

I have the following two functions for linear regression. function ordinary\_least\_squares\_regression(x,y;lambda=0,weights=0) if weights == 0 X = x' \* x + lambda\*I return X\\(x'y) else w = …

---

## [Comparing Julia structs](https://discourse.julialang.org/t/comparing-julia-structs/101554)

<div class="topic-metadata">

**Author:** [@math\_opt](https://discourse.julialang.org/u/math_opt)\
**Replies:** 8\
**Last updated:** [July 13, 2023, 6:54pm UTC](https://discourse.julialang.org/t/comparing-julia-structs/101554 "2023-07-13T18:54:20Z")

</div>

How should I do comparison of data structures involving structs. For example: struct Type1 a::Vector{Int} b::Float64 end struct Type2 c::Vector{Type1} d::Dict{Tuple{Int, Int}, Int} end obj1\_type1 = Typ…

---

## [Performance Warning when Solving Parameterized ODE](https://discourse.julialang.org/t/performance-warning-when-solving-parameterized-ode/101541)

<div class="topic-metadata">

**Author:** [@wg030](https://discourse.julialang.org/u/wg030)\
**Replies:** 2\
**Last updated:** [July 13, 2023, 2:57pm UTC](https://discourse.julialang.org/t/performance-warning-when-solving-parameterized-ode/101541 "2023-07-13T14:57:02Z")

</div>

Hi! With one of the latest Julia updates I got the following warning while running my code: Warning: Using arrays or dicts to store parameters of different types can hurt performance. │ Consider using tuples instead. …

---

## [Broadcasting Heisen-allocations](https://discourse.julialang.org/t/broadcasting-heisen-allocations/101572)

<div class="topic-metadata">

**Author:** [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Replies:** 2\
**Last updated:** [July 13, 2023, 2:14pm UTC](https://discourse.julialang.org/t/broadcasting-heisen-allocations/101572 "2023-07-13T14:14:48Z")

</div>

I have a weird code snippet that was reduced from a real codebase that was mysteriously allocating where it shouldn’t, for all I could tell: using BenchmarkTools using StaticArrays test(z::SVector{N}) where {N} = prob…

---

## [Is there a function to make an abstractly-typed variable "more" concrete?](https://discourse.julialang.org/t/is-there-a-function-to-make-an-abstractly-typed-variable-more-concrete/101439)

<div class="topic-metadata">

**Author:** [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Replies:** 11\
**Last updated:** [July 11, 2023, 7:31pm UTC](https://discourse.julialang.org/t/is-there-a-function-to-make-an-abstractly-typed-variable-more-concrete/101439 "2023-07-11T19:31:37Z")

</div>

Is there a way to find the most concrete type representation of a variable and apply it ? For example say we got our hands to a Dict{Any, Any} julia\> d = Dict{Any,Any}("one" =\> 1, "two" =\> 2) Dict{Any, Any} with 2 entr…

---

## [Eliminate runtime dispatch for repeated @async calls](https://discourse.julialang.org/t/eliminate-runtime-dispatch-for-repeated-async-calls/101480)

<div class="topic-metadata">

**Author:** [@erathorn](https://discourse.julialang.org/u/erathorn)\
**Replies:** 0\
**Last updated:** [July 11, 2023, 11:54am UTC](https://discourse.julialang.org/t/eliminate-runtime-dispatch-for-repeated-async-calls/101480 "2023-07-11T11:54:05Z")

</div>

Hi all! I am writing some code where I need to call a function repeatedly, which is executed in a distributed fashion. Below you find some pseudocode to illustrate the problem. In outer\_function I followed the suggestio…

---

## [Efficient approach to multiply three matrices (M1\*M2\*M3) and two vectors and a matrix (x\*M\*y)](https://discourse.julialang.org/t/efficient-approach-to-multiply-three-matrices-m1-m2-m3-and-two-vectors-and-a-matrix-x-m-y/66130)

<div class="topic-metadata">

**Author:** [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Replies:** 18\
**Last updated:** [July 10, 2023, 10:16pm UTC](https://discourse.julialang.org/t/efficient-approach-to-multiply-three-matrices-m1-m2-m3-and-two-vectors-and-a-matrix-x-m-y/66130 "2023-07-10T22:16:18Z")

</div>

I am trying to optimise a small function in which I am performing linear algebra operations. This function is called in a loop about a thousand times and thus speed is critical. The main points that I would like to opti…

---

## [Help to reduce memory allocations in a function](https://discourse.julialang.org/t/help-to-reduce-memory-allocations-in-a-function/101422)

<div class="topic-metadata">

**Author:** [@Lian\_Yunlong](https://discourse.julialang.org/u/Lian_Yunlong)\
**Replies:** 2\
**Last updated:** [July 10, 2023, 8:44am UTC](https://discourse.julialang.org/t/help-to-reduce-memory-allocations-in-a-function/101422 "2023-07-10T08:44:54Z")

</div>

Hello Julia experts, I have been working on the function shortest\_distance2\_t for quite a while, trying to optimise its performance. I do not have very advanced perf tools. Currently I use BenchmarkTools and PProf. I re…

---

## [Task/thread-local caches/buffers](https://discourse.julialang.org/t/task-thread-local-caches-buffers/101309)

<div class="topic-metadata">

**Author:** [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Replies:** 12\
**Last updated:** [July 9, 2023, 10:56am UTC](https://discourse.julialang.org/t/task-thread-local-caches-buffers/101309 "2023-07-09T10:56:05Z")

</div>

What is currently the best way to handle task/thread-local caches/buffers that need to be accessed efficiently from functions called from a Threads.@threads for loop? The background is as follows. As described in the re…

---

## [Shared data between processes](https://discourse.julialang.org/t/shared-data-between-processes/101350)

<div class="topic-metadata">

**Author:** [@pitsianis](https://discourse.julialang.org/u/pitsianis)\
**Replies:** 0\
**Last updated:** [July 8, 2023, 3:20pm UTC](https://discourse.julialang.org/t/shared-data-between-processes/101350 "2023-07-08T15:20:23Z")

</div>

I was surprised that SharedArrays.jl does not support SparseArrays. Is there any package that can place any data structure in a shared memory segment so that collaborating processes from Distributed.jl can access them w…

---

## [Low rank factorized AbstractMatrix](https://discourse.julialang.org/t/low-rank-factorized-abstractmatrix/19838)

<div class="topic-metadata">

**Author:** [@jarl](https://discourse.julialang.org/u/jarl)\
**Replies:** 18\
**Last updated:** [July 7, 2023, 8:52pm UTC](https://discourse.julialang.org/t/low-rank-factorized-abstractmatrix/19838 "2023-07-07T20:52:02Z")

</div>

Basic question: Is there an AbstractMatrix which can represent a low-rank factorized matrix? Example: I have the rank-one matrix: n1=900; n2=100; u=\[zeros(n1);randn(n2)\]; A=u\*u'; I want to use A in functions which tak…

---

## [Mapreduce performance and dispatch](https://discourse.julialang.org/t/mapreduce-performance-and-dispatch/101322)

<div class="topic-metadata">

**Author:** [@bmit](https://discourse.julialang.org/u/bmit)\
**Replies:** 0\
**Last updated:** [July 7, 2023, 5:49pm UTC](https://discourse.julialang.org/t/mapreduce-performance-and-dispatch/101322 "2023-07-07T17:49:14Z")

</div>

I’m having trouble getting mapreduce to dispatch correctly and am looking for tips. From profiling I can see that it dispatches to map and reduce independently rather than something better like mapfoldl. There’s a simil…

---

## [1.10 alpha significantly slower to start REPL](https://discourse.julialang.org/t/1-10-alpha-significantly-slower-to-start-repl/101293)

<div class="topic-metadata">

**Author:** [@albheim](https://discourse.julialang.org/u/albheim)\
**Replies:** 9\
**Last updated:** [July 7, 2023, 2:00pm UTC](https://discourse.julialang.org/t/1-10-alpha-significantly-slower-to-start-repl/101293 "2023-07-07T14:00:01Z")

</div>

Got the new alpha from juliaup, and the REPL seemed significantly slower to boot than in the release. Did a very simple test where I pressed Ctrl-D as soon as I saw the julia prompt, so might be a little variability fro…

---

## [Customize a random function to sample 3 out of a list of 4097 real numbers](https://discourse.julialang.org/t/customize-a-random-function-to-sample-3-out-of-a-list-of-4097-real-numbers/100876)

<div class="topic-metadata">

**Author:** [@Lian\_Yunlong](https://discourse.julialang.org/u/Lian_Yunlong)\
**Replies:** 5\
**Last updated:** [July 7, 2023, 6:42am UTC](https://discourse.julialang.org/t/customize-a-random-function-to-sample-3-out-of-a-list-of-4097-real-numbers/100876 "2023-07-07T06:42:28Z")

</div>

I need a very fast random sampler to choose n numbers from a precomputed 1D array, say X. We can assume that n is much smaller than length(X). I have tried rand(X,n), \[rand(X) for i=1:n\] , but neither gives satisfactory …

---

## [Help me improve this simple function](https://discourse.julialang.org/t/help-me-improve-this-simple-function/101198)

<div class="topic-metadata">

**Author:** [@laborg](https://discourse.julialang.org/u/laborg)\
**Replies:** 12\
**Last updated:** [July 5, 2023, 2:08pm UTC](https://discourse.julialang.org/t/help-me-improve-this-simple-function/101198 "2023-07-05T14:08:10Z")

</div>

Hi, The following function is used to apply a calibration captured in correction to a matrix of 3D sample points. using BenchmarkTools function correct(points, correction) epoints = hcat(points, ones(size(points, 1…

---

## [How can this code be faster than MATLAB?](https://discourse.julialang.org/t/how-can-this-code-be-faster-than-matlab/101196)

<div class="topic-metadata">

**Author:** [@XuJingye2022](https://discourse.julialang.org/u/XuJingye2022)\
**Replies:** 12\
**Last updated:** [July 5, 2023, 6:22am UTC](https://discourse.julialang.org/t/how-can-this-code-be-faster-than-matlab/101196 "2023-07-05T06:22:04Z")

</div>

using BenchmarkTools zvec, δvec = randn(10000) \* 1e-2, randn(10000) \* 1e-3 # Physical constant const restenergy = 0.511e6 const clight = 3e8 # Computation settings nturns = 10001 # Machine parameter struct Par v1…

---

## [Why does Pkg.activate(".") require compilation? Time to first project activation](https://discourse.julialang.org/t/why-does-pkg-activate-require-compilation-time-to-first-project-activation/101193)

<div class="topic-metadata">

**Author:** [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Replies:** 2\
**Last updated:** [July 5, 2023, 3:00am UTC](https://discourse.julialang.org/t/why-does-pkg-activate-require-compilation-time-to-first-project-activation/101193 "2023-07-05T03:00:18Z")

</div>

Pkg.activate(".") seems to to take about 200 milliseconds, mostly due to compilation. It still takes 40 milliseconds even after activating the same environment again. $ julia -e 'using Pkg; for i in 1:5; @time Pkg.activ…

---

## [Need help understanding allocations while calling external C library (Proj)](https://discourse.julialang.org/t/need-help-understanding-allocations-while-calling-external-c-library-proj/101133)

<div class="topic-metadata">

**Author:** [@disberd](https://discourse.julialang.org/u/disberd)\
**Replies:** 3\
**Last updated:** [July 4, 2023, 5:15pm UTC](https://discourse.julialang.org/t/need-help-understanding-allocations-while-calling-external-c-library-proj/101133 "2023-07-04T17:15:33Z")

</div>

Hello everyone, I have been scratching my head around allocations I have in a package I am developing that I can’t seem to eliminate. Moreover it seems that the allocation results I get from @allocations and @btime fro…

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

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