# Performance

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

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

**Page:** 81

---

## [What does jl\_init\_restored\_modules do? Why does loading my package take so long?](https://discourse.julialang.org/t/what-does-jl-init-restored-modules-do-why-does-loading-my-package-take-so-long/69906)

<div class="topic-metadata">

**Author:** [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Replies:** 12\
**Last updated:** [October 17, 2021, 12:58pm UTC](https://discourse.julialang.org/t/what-does-jl-init-restored-modules-do-why-does-loading-my-package-take-so-long/69906 "2021-10-17T12:58:00Z")

</div>

Here is the ProfileView flamegraph of using PythonCall, which takes about 4.5 seconds: As you can see, almost half the time is spent in \_include\_from\_serialized at this line, namely the jl\_init\_restored\_modules C fun…

---

## [How to do custom allocators](https://discourse.julialang.org/t/how-to-do-custom-allocators/69112)

<div class="topic-metadata">

**Author:** [@goerch](https://discourse.julialang.org/u/goerch)\
**Replies:** 22\
**Last updated:** [October 17, 2021, 11:50am UTC](https://discourse.julialang.org/t/how-to-do-custom-allocators/69112 "2021-10-17T11:50:20Z")

</div>

In the everlasting quest to reduce allocations I stumbled about problems with node based data structures. Constructing a test case based on DataStructures.jl’s singly linked list I tried to eliminate allocations in const…

---

## [Embarrassingly parallel multi-threading doesn't scale](https://discourse.julialang.org/t/embarrassingly-parallel-multi-threading-doesnt-scale/69843)

<div class="topic-metadata">

**Author:** [@Arnau](https://discourse.julialang.org/u/Arnau)\
**Replies:** 17\
**Last updated:** [October 16, 2021, 10:09pm UTC](https://discourse.julialang.org/t/embarrassingly-parallel-multi-threading-doesnt-scale/69843 "2021-10-16T22:09:12Z")

</div>

A simple embarrassingly parallel code, with 4 threads, only halves in speed. Here is a super simplified case :~$ julia -t4 julia\> N = Int(1e8) 100000000 julia\> @elapsed for i in 1:N rand(100) end 46.246…

---

## [How to Efficiently Index PyArrays?](https://discourse.julialang.org/t/how-to-efficiently-index-pyarrays/69785)

<div class="topic-metadata">

**Author:** [@rewindturtle](https://discourse.julialang.org/u/rewindturtle)\
**Replies:** 25\
**Last updated:** [October 16, 2021, 7:59pm UTC](https://discourse.julialang.org/t/how-to-efficiently-index-pyarrays/69785 "2021-10-16T19:59:01Z")

</div>

I have been trying to rewrite a python script I wrote a while back in julia to increase its performance. The python script used a package called gym-retro which ran a videogame emulator that the script could directly int…

---

## [Why are tuple literals better for constant-propagation than array literals?](https://discourse.julialang.org/t/why-are-tuple-literals-better-for-constant-propagation-than-array-literals/69805)

<div class="topic-metadata">

**Author:** [@jules](https://discourse.julialang.org/u/jules)\
**Replies:** 12\
**Last updated:** [October 15, 2021, 2:35pm UTC](https://discourse.julialang.org/t/why-are-tuple-literals-better-for-constant-propagation-than-array-literals/69805 "2021-10-15T14:35:13Z")

</div>

I need functions that check if a symbol references a specific type of struct field, and this is supposed to compile away through constant propagation. Now, I also had this heuristic that I shouldn’t use huge Tuples beca…

---

## [Compact vs Scattered Pinning](https://discourse.julialang.org/t/compact-vs-scattered-pinning/69722)

<div class="topic-metadata">

**Author:** [@tkf](https://discourse.julialang.org/u/tkf)\
**Replies:** 3\
**Last updated:** [October 15, 2021, 7:06am UTC](https://discourse.julialang.org/t/compact-vs-scattered-pinning/69722 "2021-10-15T07:06:47Z")

</div>

@carstenbauer Cool package! I want to de derail this further so let me open a new topic :slight\_smile: When I first looked at it, the performance advantage of scattered pinning was puzzling for me. Intuitively, you wou…

---

## [SOA transform](https://discourse.julialang.org/t/soa-transform/69769)

<div class="topic-metadata">

**Author:** [@goerch](https://discourse.julialang.org/u/goerch)\
**Replies:** 8\
**Last updated:** [October 14, 2021, 8:22pm UTC](https://discourse.julialang.org/t/soa-transform/69769 "2021-10-14T20:22:14Z")

</div>

I’m playing with a SOA transform (AoS and SoA - Wikipedia) via StructArrays.jl. My code: using StructArrays function test1() n = 10 v = Vector{Tuple{Int, Int}}(undef, n) s = 0 for i in 1:n v\[i\] …

---

## [The columns and the rows - puzzled about performance](https://discourse.julialang.org/t/the-columns-and-the-rows-puzzled-about-performance/69741)

<div class="topic-metadata">

**Author:** [@Niceno](https://discourse.julialang.org/u/Niceno)\
**Replies:** 8\
**Last updated:** [October 14, 2021, 12:05pm UTC](https://discourse.julialang.org/t/the-columns-and-the-rows-puzzled-about-performance/69741 "2021-10-14T12:05:29Z")

</div>

Dear all, I have been using Julia for about three weeks now and, to my understanding, she uses a column-major matrix storage system. That would also mean, if I get things right, that loops which access matrix entries i…

---

## [Writing Type Stable Loops](https://discourse.julialang.org/t/writing-type-stable-loops/69705)

<div class="topic-metadata">

**Author:** [@dleather](https://discourse.julialang.org/u/dleather)\
**Replies:** 10\
**Last updated:** [October 13, 2021, 6:49pm UTC](https://discourse.julialang.org/t/writing-type-stable-loops/69705 "2021-10-13T18:49:20Z")

</div>

For /While loops create a local scope. Thus, if you’d like to write a function the outputs variables defined inside of the for /while loop, one must declare these variables as global beforehand, or use a let wrapper. Th…

---

## [Julia vs Fortran speed](https://discourse.julialang.org/t/julia-vs-fortran-speed/69654)

<div class="topic-metadata">

**Author:** [@lancejnelson](https://discourse.julialang.org/u/lancejnelson)\
**Replies:** 5\
**Last updated:** [October 13, 2021, 11:13am UTC](https://discourse.julialang.org/t/julia-vs-fortran-speed/69654 "2021-10-13T11:13:08Z")

</div>

A friend of mine wanted to check the speed of Julia vs a compiled language like C++ or Fortran. So he wrote a simple routine in Julia to invert a matrix. Then he compiled a Fortran code to do the same. Compiler flags wer…

---

## [How to deal with more threads than requested?](https://discourse.julialang.org/t/how-to-deal-with-more-threads-than-requested/69655)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 1\
**Last updated:** [October 13, 2021, 2:17am UTC](https://discourse.julialang.org/t/how-to-deal-with-more-threads-than-requested/69655 "2021-10-13T02:17:36Z")

</div>

I have a program that I instruct to use the 32 physical cores on a machine. But the program typically uses 37 or 38, presumably due to BLAS being used by one of the loaded packages. As a general rule, would it be faste…

---

## [LoopVectorization does not support functions with kwargs?](https://discourse.julialang.org/t/loopvectorization-does-not-support-functions-with-kwargs/69598)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 9\
**Last updated:** [October 12, 2021, 3:52pm UTC](https://discourse.julialang.org/t/loopvectorization-does-not-support-functions-with-kwargs/69598 "2021-10-12T15:52:16Z")

</div>

I get an error when trying to use LoopVectorization below: using LoopVectorization function f(x; kw=kw) x + kw end function add(z; kw=1) s = zero(eltype(kw)) @turbo for x in 1:z s += f(x; kw=kw) …

---

## [Making a fast evaluation of a function and its gradient](https://discourse.julialang.org/t/making-a-fast-evaluation-of-a-function-and-its-gradient/68884)

<div class="topic-metadata">

**Author:** [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Replies:** 32\
**Last updated:** [October 11, 2021, 5:32pm UTC](https://discourse.julialang.org/t/making-a-fast-evaluation-of-a-function-and-its-gradient/68884 "2021-10-11T17:32:33Z")

</div>

Hi everybody, I have written a script that evaluates a non-linear function feta over a 2D domain. The function returns eta that depends on other 2D fields (Exx, Eyy, Exy). I try to compute the gradient of eta w.r.t Exx…

---

## [Performance difference in permuting Arrays](https://discourse.julialang.org/t/performance-difference-in-permuting-arrays/69425)

<div class="topic-metadata">

**Author:** [@mrVeng](https://discourse.julialang.org/u/mrVeng)\
**Replies:** 4\
**Last updated:** [October 11, 2021, 1:23pm UTC](https://discourse.julialang.org/t/performance-difference-in-permuting-arrays/69425 "2021-10-11T13:23:04Z")

</div>

Hi guys, I am trying to permute/shuffle a Vector of Vectors given a certain index. Some vectors can occur several times, so I need a buffer container for no allocations. MWE: vals = \[ \[1, 2, 3\], \[4, 5, 6\], \[7, 8, 9\] \] …

---

## [How do we exec a julia program for competitive programming?](https://discourse.julialang.org/t/how-do-we-exec-a-julia-program-for-competitive-programming/25470)

<div class="topic-metadata">

**Author:** [@p1scescom](https://discourse.julialang.org/u/p1scescom)\
**Replies:** 2\
**Last updated:** [October 11, 2021, 8:38am UTC](https://discourse.julialang.org/t/how-do-we-exec-a-julia-program-for-competitive-programming/25470 "2021-10-11T08:38:57Z")

</div>

Hey everyone. I want your idea to exec a julia program quickly and usefuly for competitive prgramming. You may not know competitive programming. It is A programming competition generally involves the host presenting…

---

## [Fast random number generator for RGBs](https://discourse.julialang.org/t/fast-random-number-generator-for-rgbs/52035)

<div class="topic-metadata">

**Author:** [@boroboro77](https://discourse.julialang.org/u/boroboro77)\
**Replies:** 11\
**Last updated:** [October 9, 2021, 5:43pm UTC](https://discourse.julialang.org/t/fast-random-number-generator-for-rgbs/52035 "2021-10-09T17:43:10Z")

</div>

I would like to generate very fast pseudo random images. The quality of the random numbers to generate random RGBs are not very important to be completely independent. But they sould look “random” for a human eye. Is th…

---

## [Matrix Multiplication 10x+ Speedup](https://discourse.julialang.org/t/matrix-multiplication-10x-speedup/69452)

<div class="topic-metadata">

**Author:** [@laut](https://discourse.julialang.org/u/laut)\
**Replies:** 1\
**Last updated:** [October 8, 2021, 9:22pm UTC](https://discourse.julialang.org/t/matrix-multiplication-10x-speedup/69452 "2021-10-08T21:22:12Z")

</div>

Researchers at MIT’s Computer Science & Artificial Intelligence Lab (CSAIL) have open-sourced Multiply-ADDitioN-lESS (MADDNESS), an algorithm that speeds up machine learning using approximate matrix multiplication (AMM).…

---

## [^ vs exp for exponentiation](https://discourse.julialang.org/t/vs-exp-for-exponentiation/69437)

<div class="topic-metadata">

**Author:** [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Replies:** 3\
**Last updated:** [October 8, 2021, 2:30pm UTC](https://discourse.julialang.org/t/vs-exp-for-exponentiation/69437 "2021-10-08T14:30:38Z")

</div>

One last thing to note: If you care about performance, don’t use ^ whenever possible. exp (or exp2/exp10) will be 5x to 30x faster.

---

## [mul!(::Matrix, ::Matrix, ::UpperTriangular) is really slow](https://discourse.julialang.org/t/mul-matrix-matrix-uppertriangular-is-really-slow/69368)

<div class="topic-metadata">

**Author:** [@Luapulu](https://discourse.julialang.org/u/Luapulu)\
**Replies:** 4\
**Last updated:** [October 8, 2021, 6:57am UTC](https://discourse.julialang.org/t/mul-matrix-matrix-uppertriangular-is-really-slow/69368 "2021-10-08T06:57:25Z")

</div>

There seem to be efficient methods to do mul!(out, ::UpperTriangular, ::Matrix) and mul!(out, ::LowerTriangular, ::Matrix). However, when you reverse the arguments and use mul!(out, ::Matrix, ::UpperTriangular) the perfo…

---

## [Loosing performance with \`Threads.@threads\` for loop](https://discourse.julialang.org/t/loosing-performance-with-threads-threads-for-loop/69358)

<div class="topic-metadata">

**Author:** [@Kevin\_Kleinbeck](https://discourse.julialang.org/u/Kevin_Kleinbeck)\
**Replies:** 10\
**Last updated:** [October 7, 2021, 2:36pm UTC](https://discourse.julialang.org/t/loosing-performance-with-threads-threads-for-loop/69358 "2021-10-07T14:36:45Z")

</div>

I have strange performance issues when I use Threads.@threads to parallelize a for-loop. My machine runs on 40 cores: julia\> Threads.nthreads() 40 Now, I lose performance even with a quite simple example: N = 500 m = …

---

## [Preallocating Vector of Vectors](https://discourse.julialang.org/t/preallocating-vector-of-vectors/69304)

<div class="topic-metadata">

**Author:** [@mrVeng](https://discourse.julialang.org/u/mrVeng)\
**Replies:** 25\
**Last updated:** [October 7, 2021, 12:38pm UTC](https://discourse.julialang.org/t/preallocating-vector-of-vectors/69304 "2021-10-07T12:38:14Z")

</div>

Hi there, I have a project where I need to preallocate a Vector of Vectors. I could just use a multidimensional array, but this complicates things and makes the code less readable as well. Is there a way that I can prea…

---

## [Avoid creation of temporaries in non-trivial iterator](https://discourse.julialang.org/t/avoid-creation-of-temporaries-in-non-trivial-iterator/64498)

<div class="topic-metadata">

**Author:** [@mwallerb](https://discourse.julialang.org/u/mwallerb)\
**Replies:** 16\
**Last updated:** [October 6, 2021, 9:23am UTC](https://discourse.julialang.org/t/avoid-creation-of-temporaries-in-non-trivial-iterator/64498 "2021-10-06T09:23:57Z")

</div>

Consider the following Julia “compound” iterator: it merges two iterators, a and b , each of which are assumed to be sorted according to order, to a single ordered sequence: struct MergeSorted{T,A,B,O} a::A b::B…

---

## [TCP socket allocations](https://discourse.julialang.org/t/tcp-socket-allocations/69254)

<div class="topic-metadata">

**Author:** [@Dilchatto](https://discourse.julialang.org/u/Dilchatto)\
**Replies:** 0\
**Last updated:** [October 5, 2021, 9:00pm UTC](https://discourse.julialang.org/t/tcp-socket-allocations/69254 "2021-10-05T21:00:51Z")

</div>

Hi. I found that this method always dynamically allocates memory. @allocated write(soc::TCPSocket, x) How can I avoid this? Is there some StaticTCPSocket package?

---

## [SharedArrays in function with @distributed](https://discourse.julialang.org/t/sharedarrays-in-function-with-distributed/69096)

<div class="topic-metadata">

**Author:** [@Beh123](https://discourse.julialang.org/u/Beh123)\
**Replies:** 4\
**Last updated:** [October 5, 2021, 5:26pm UTC](https://discourse.julialang.org/t/sharedarrays-in-function-with-distributed/69096 "2021-10-05T17:26:06Z")

</div>

Hi my friends, I have a function with @thread . In this threads function, I use @distribute to speedup calculations loops. But my result is incorrect when I use function. My result is correct without function.

---

## [Automatic differentiation performance & computing derivatives of only a subset of the arguments](https://discourse.julialang.org/t/automatic-differentiation-performance-computing-derivatives-of-only-a-subset-of-the-arguments/69074)

<div class="topic-metadata">

**Author:** [@gianmariomanca](https://discourse.julialang.org/u/gianmariomanca)\
**Replies:** 6\
**Last updated:** [October 2, 2021, 8:46pm UTC](https://discourse.julialang.org/t/automatic-differentiation-performance-computing-derivatives-of-only-a-subset-of-the-arguments/69074 "2021-10-02T20:46:41Z")

</div>

Here is a minimal working example const x = -10:10 f(m) = exp.(-1.5 .\* (x .- m).^2) function rs(d,xs) d0 = f(xs) d .- sum(d .\* d0) / sum(d0 .\* d0) .\* d0 end drs(d,xs) = (rs(d,xs + 1e-6) .- rs(d,xs)) / 1e-6 drs\_aut…

---

## [Clustering using matrix decomp code performance tips](https://discourse.julialang.org/t/clustering-using-matrix-decomp-code-performance-tips/68838)

<div class="topic-metadata">

**Author:** [@spinkney](https://discourse.julialang.org/u/spinkney)\
**Replies:** 5\
**Last updated:** [October 2, 2021, 7:05pm UTC](https://discourse.julialang.org/t/clustering-using-matrix-decomp-code-performance-tips/68838 "2021-10-02T19:05:18Z")

</div>

Hi Julians, I’ve ported this matlab code from Clustering by low-rank doubly stochastic matrix decomposition to Julia. But it’s much too slow for my application. I’m still green to Julia so posting here to see if there’…

---

## [Why is there difference between time and @time?](https://discourse.julialang.org/t/why-is-there-difference-between-time-and-time/69094)

<div class="topic-metadata">

**Author:** [@zhaoli-IHEP](https://discourse.julialang.org/u/zhaoli-IHEP)\
**Replies:** 8\
**Last updated:** [October 2, 2021, 1:57pm UTC](https://discourse.julialang.org/t/why-is-there-difference-between-time-and-time/69094 "2021-10-02T13:57:23Z")

</div>

In a simple script using SymEngine function test() @vars q1, q2 return q1+q2 end # function test @time test() we measure the time by using @time, and then we check the timing in the script run like \[ ~/works/…

---

## [Faster squared euclidean distance calculation](https://discourse.julialang.org/t/faster-squared-euclidean-distance-calculation/68969)

<div class="topic-metadata">

**Author:** [@jroon](https://discourse.julialang.org/u/jroon)\
**Replies:** 11\
**Last updated:** [October 2, 2021, 12:59pm UTC](https://discourse.julialang.org/t/faster-squared-euclidean-distance-calculation/68969 "2021-10-02T12:59:34Z")

</div>

Hi all. Trying to speed up a small function that multiplies an array by vector before doing a distance calculation. A small reprex: using BenchmarkTools using Distances using Tullio function calc1(r::Array{Float64, 1}…

---

## [Mixed partials](https://discourse.julialang.org/t/mixed-partials/69068)

<div class="topic-metadata">

**Author:** [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Replies:** 1\
**Last updated:** [October 1, 2021, 9:29pm UTC](https://discourse.julialang.org/t/mixed-partials/69068 "2021-10-01T21:29:11Z")

</div>

Suppose that I have a scalar function of multiple variables, e.g., z = f(x,y) How can I compute mixed partials using ForwardDiff? E.g., suppose that I want d^2f/dxdy The case for the hessian, it is clear, e.g., d^2f/…

---

## [Why does findfirst(==(T), ...) on a tuple of typed only constant fold for the first?](https://discourse.julialang.org/t/why-does-findfirst-t-on-a-tuple-of-typed-only-constant-fold-for-the-first/68893)

<div class="topic-metadata">

**Author:** [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Replies:** 2\
**Last updated:** [September 29, 2021, 1:32pm UTC](https://discourse.julialang.org/t/why-does-findfirst-t-on-a-tuple-of-typed-only-constant-fold-for-the-first/68893 "2021-09-29T13:32:52Z")

</div>

Consider: position(::T) where T = findfirst(==(T), (Int, Float64, Char)) You might think this would either constant fold or not. But actually, it constant-folds for the Int inputs but not for Float64 or Char. And if …

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

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