# Performance

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

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

**Page:** 91

---

## [Help speedup a brute-force solution](https://discourse.julialang.org/t/help-speedup-a-brute-force-solution/62894)

<div class="topic-metadata">

**Author:** [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Replies:** 13\
**Last updated:** [June 18, 2021, 8:50am UTC](https://discourse.julialang.org/t/help-speedup-a-brute-force-solution/62894 "2021-06-18T08:50:36Z")

</div>

The following function calculates all possible subsets of a set 1:n such that all subsets are primes. This is only a brute-force algorithm to test a solution, so it’s too slow as expected. The number of allocations is hu…

---

## [Allocations when passing closure as parameter](https://discourse.julialang.org/t/allocations-when-passing-closure-as-parameter/63082)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 2\
**Last updated:** [June 17, 2021, 1:13pm UTC](https://discourse.julialang.org/t/allocations-when-passing-closure-as-parameter/63082 "2021-06-17T13:13:04Z")

</div>

I struggling to obtain a minimal working example. But I have one situation which looks like: function outer!(f::Function, output,x::AbstractVector) for i in 1:10 output = inner!(f,output,x) end return output …

---

## [Type instability with static matrices when full size not given?](https://discourse.julialang.org/t/type-instability-with-static-matrices-when-full-size-not-given/63079)

<div class="topic-metadata">

**Author:** [@nabla](https://discourse.julialang.org/u/nabla)\
**Replies:** 4\
**Last updated:** [June 17, 2021, 12:45pm UTC](https://discourse.julialang.org/t/type-instability-with-static-matrices-when-full-size-not-given/63079 "2021-06-17T12:45:20Z")

</div>

I ran across the following, very wierd situation: if I don’t specify the 4th parameter in a SMatrix (which is supposed to be computed as the product of the sizes, then the code slows down considerably. MWE: using Benchm…

---

## [Evaluating the "for" condition](https://discourse.julialang.org/t/evaluating-the-for-condition/63050)

<div class="topic-metadata">

**Author:** [@marllos](https://discourse.julialang.org/u/marllos)\
**Replies:** 10\
**Last updated:** [June 17, 2021, 7:35am UTC](https://discourse.julialang.org/t/evaluating-the-for-condition/63050 "2021-06-17T07:35:12Z")

</div>

Hello everyone. The following simple example is just to ask the question: will Julia evaluate the length function 5 times? Thank you. function test() v = \[1,2,3,4,5\] for i = 1:length(v) println(v\[i\]) end end

---

## [Selectdim behaviour for arrays of dimension greater than 2](https://discourse.julialang.org/t/selectdim-behaviour-for-arrays-of-dimension-greater-than-2/52211)

<div class="topic-metadata">

**Author:** [@OlivierHnt](https://discourse.julialang.org/u/OlivierHnt)\
**Replies:** 5\
**Last updated:** [June 1, 2021, 2:27pm UTC](https://discourse.julialang.org/t/selectdim-behaviour-for-arrays-of-dimension-greater-than-2/52211 "2021-06-01T14:27:45Z")

</div>

I just noticed a type-instability with selectdim. Consider the function f(A) = selectdim(A, 1, 1) For a matrix, we have that the return type of f is a 1D SubArray (as expected): julia\> A = rand(2,2); julia\> @code\_war…

---

## [Overloading Base.hash is 2x slower than an identical function](https://discourse.julialang.org/t/overloading-base-hash-is-2x-slower-than-an-identical-function/63058)

<div class="topic-metadata">

**Author:** [@odow](https://discourse.julialang.org/u/odow)\
**Replies:** 1\
**Last updated:** [June 17, 2021, 1:20am UTC](https://discourse.julialang.org/t/overloading-base-hash-is-2x-slower-than-an-identical-function/63058 "2021-06-17T01:20:55Z")

</div>

Can anyone explain (or reproduce) the following? Why is the Base.hash version slower and why the allocation? julia\> using BenchmarkTools julia\> mutable struct Foo end julia\> struct Bar f::Foo x:…

---

## [The fastest way to calculate matrix inversion](https://discourse.julialang.org/t/the-fastest-way-to-calculate-matrix-inversion/62892)

<div class="topic-metadata">

**Author:** [@yingqiuz](https://discourse.julialang.org/u/yingqiuz)\
**Replies:** 9\
**Last updated:** [June 15, 2021, 12:14am UTC](https://discourse.julialang.org/t/the-fastest-way-to-calculate-matrix-inversion/62892 "2021-06-15T00:14:32Z")

</div>

Hi all I need to calculate the inverse of a positive definite matrix H of the form H = (X’ \* X + Diagonal(d)). X is a flat matrix, having (dominantly) more columns than rows. d consists of positive, large values. The m…

---

## [Indexing a document using Dictionary](https://discourse.julialang.org/t/indexing-a-document-using-dictionary/62724)

<div class="topic-metadata">

**Author:** [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Replies:** 10\
**Last updated:** [June 15, 2021, 8:54am UTC](https://discourse.julialang.org/t/indexing-a-document-using-dictionary/62724 "2021-06-15T08:54:22Z")

</div>

Dear All, I would like to ask, if there is a Dict that would be suitable for indexing a large collection of documents. Specifically imagine that each document is composed by a set of words doc1 = \[1,2,3,4,5,\] doc2 = \[3…

---

## [Performance comparison of Nvidia A100, V100, RTX2080Ti](https://discourse.julialang.org/t/performance-comparison-of-nvidia-a100-v100-rtx2080ti/62602)

<div class="topic-metadata">

**Author:** [@yixingfu](https://discourse.julialang.org/u/yixingfu)\
**Replies:** 17\
**Last updated:** [June 14, 2021, 12:58pm UTC](https://discourse.julialang.org/t/performance-comparison-of-nvidia-a100-v100-rtx2080ti/62602 "2021-06-14T12:58:47Z")

</div>

When running a bunch of code mostly based on CUDA.jl and consists of mainly (sparse or dense) linear algebra operations, I come to notice that the code runs almost at the same speed for RTX2080Ti and V100, and much faste…

---

## [Asynchronous requests HTTP.jl + LibPQ](https://discourse.julialang.org/t/asynchronous-requests-http-jl-libpq/62736)

<div class="topic-metadata">

**Author:** [@Michal](https://discourse.julialang.org/u/Michal)\
**Replies:** 2\
**Last updated:** [June 14, 2021, 5:10am UTC](https://discourse.julialang.org/t/asynchronous-requests-http-jl-libpq/62736 "2021-06-14T05:10:30Z")

</div>

1. HTTP.jl I’m looking for correct solution for asynchronous handling requests by HTTP.jl. Please, do you know how should I implement this behavior? 1 thread request handling: function requestHandler(req::HTTP.Request…

---

## [Make this Tuple code faster](https://discourse.julialang.org/t/make-this-tuple-code-faster/62824)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 11\
**Last updated:** [June 13, 2021, 6:37pm UTC](https://discourse.julialang.org/t/make-this-tuple-code-faster/62824 "2021-06-13T18:37:51Z")

</div>

I have a Tuple and want to replace its starting segment: function switch\_front(new\_front, t) n = length(t) k = length(new\_front) @assert k \<= n (new\_front..., t\[k+1:n\]...) end using Test @test switch\_fr…

---

## [Dot operator, 1. with array-indexing expression on the left-hand side and 2. with Matrix\*Vector-multiplication](https://discourse.julialang.org/t/dot-operator-1-with-array-indexing-expression-on-the-left-hand-side-and-2-with-matrix-vector-multiplication/62743)

<div class="topic-metadata">

**Author:** [@hardy](https://discourse.julialang.org/u/hardy)\
**Replies:** 18\
**Last updated:** [June 13, 2021, 3:52pm UTC](https://discourse.julialang.org/t/dot-operator-1-with-array-indexing-expression-on-the-left-hand-side-and-2-with-matrix-vector-multiplication/62743 "2021-06-13T15:52:56Z")

</div>

Hallo, I would like to understand how the dot operator works. There are two specific problems: at Performance Tips · The Julia Language (headline: Consider using views for slicing) I learned that “…on the left-ha…

---

## [Testing nested parallelization with @distributed and @spawn/@threads](https://discourse.julialang.org/t/testing-nested-parallelization-with-distributed-and-spawn-threads/62803)

<div class="topic-metadata">

**Author:** [@swishmas](https://discourse.julialang.org/u/swishmas)\
**Replies:** 0\
**Last updated:** [June 12, 2021, 4:37pm UTC](https://discourse.julialang.org/t/testing-nested-parallelization-with-distributed-and-spawn-threads/62803 "2021-06-12T16:37:22Z")

</div>

I know this is a popular topic, but I wanted to check my understanding on nested parallelization with @distributed, @spawn, and @threads. Here’s a working example of a few different strategies using LinearAlgebra impor…

---

## [Optimizing Code to Fit a Generalized Pareto Distribution to Data](https://discourse.julialang.org/t/optimizing-code-to-fit-a-generalized-pareto-distribution-to-data/62690)

<div class="topic-metadata">

**Author:** [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Replies:** 17\
**Last updated:** [June 12, 2021, 12:45am UTC](https://discourse.julialang.org/t/optimizing-code-to-fit-a-generalized-pareto-distribution-to-data/62690 "2021-06-12T00:45:54Z")

</div>

I’m trying to optimize the following very performance-critical piece of code: using Memoization, Statistics, LinearAlgebra, Tullio, LoopVectorization """ gpdfit(sample::AbstractArray, wip::Bool = true, min\_grid\_pts…

---

## [Question about allocations and generators](https://discourse.julialang.org/t/question-about-allocations-and-generators/62693)

<div class="topic-metadata">

**Author:** [@RomainPct](https://discourse.julialang.org/u/RomainPct)\
**Replies:** 2\
**Last updated:** [June 11, 2021, 7:51pm UTC](https://discourse.julialang.org/t/question-about-allocations-and-generators/62693 "2021-06-11T19:51:08Z")

</div>

Hello, this this question is out of curiosity, hoping to understand more about Julia. Those three functions allocate differently: g1(v::Vector{Int64}) = SVector{length(v), Int64}(v...) g2(v::Vector{Int64}, n) = SVector…

---

## [Sparse Matrix with CUDA.jl](https://discourse.julialang.org/t/sparse-matrix-with-cuda-jl/62627)

<div class="topic-metadata">

**Author:** [@boutor2](https://discourse.julialang.org/u/boutor2)\
**Replies:** 3\
**Last updated:** [June 10, 2021, 4:14pm UTC](https://discourse.julialang.org/t/sparse-matrix-with-cuda-jl/62627 "2021-06-10T16:14:32Z")

</div>

Hi everyone, I am looking for the most performant way to create a CuArray where coefficients are 0 everywhere but 1 at specified indices. An easy way to do that with regular arrays would be a = randn(1000,1000) imin = …

---

## [An embarrassingly parallel problem: threads or MPI?](https://discourse.julialang.org/t/an-embarrassingly-parallel-problem-threads-or-mpi/48049)

<div class="topic-metadata">

**Author:** [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Replies:** 14\
**Last updated:** [June 10, 2021, 6:10pm UTC](https://discourse.julialang.org/t/an-embarrassingly-parallel-problem-threads-or-mpi/48049 "2021-06-10T18:10:31Z")

</div>

Monte Carlo is one of the archetypal embarrassingly parallel problems. I have been wondering for some time what’s the fastest way to do Monte Carlo in Julia, for problems where each replication has enough cost to make pa…

---

## [Overuse of memory leads to computer freeze](https://discourse.julialang.org/t/overuse-of-memory-leads-to-computer-freeze/62671)

<div class="topic-metadata">

**Author:** [@theogf](https://discourse.julialang.org/u/theogf)\
**Replies:** 10\
**Last updated:** [June 10, 2021, 3:26pm UTC](https://discourse.julialang.org/t/overuse-of-memory-leads-to-computer-freeze/62671 "2021-06-10T15:26:07Z")

</div>

I have a memory issue. On my small laptop (8Gb RAM) when I build overly big matrices I get a nice OutOfMemory error, the function is stopped and all is well. However on my desktop (~48Gb RAM) overly big matrices will ta…

---

## [Optim.jl vs scipy.optimize once again](https://discourse.julialang.org/t/optim-jl-vs-scipy-optimize-once-again/61661)

<div class="topic-metadata">

**Author:** [@rht](https://discourse.julialang.org/u/rht)\
**Replies:** 54\
**Last updated:** [June 10, 2021, 12:23am UTC](https://discourse.julialang.org/t/optim-jl-vs-scipy-optimize-once-again/61661 "2021-06-10T00:23:27Z")

</div>

I have been using Python’s scipy.optimize.minimize(method="LBFGSB") for my research, and have been looking to speed the code because it doesn’t scale. And so I tried to rewrite my code in Julia using Optim.jl, with Opti…

---

## [Confusion about type stability: functions or methods?](https://discourse.julialang.org/t/confusion-about-type-stability-functions-or-methods/62277)

<div class="topic-metadata">

**Author:** [@fedario](https://discourse.julialang.org/u/fedario)\
**Replies:** 17\
**Last updated:** [June 9, 2021, 2:39pm UTC](https://discourse.julialang.org/t/confusion-about-type-stability-functions-or-methods/62277 "2021-06-09T14:39:03Z")

</div>

Hi! Reading the documentation about type stability actually made me unsure if I understood the concept correctly. The documentation states that When possible, it helps to ensure that a function always returns a value…

---

## [Fully parallelized for-loop becomes slower with more threads](https://discourse.julialang.org/t/fully-parallelized-for-loop-becomes-slower-with-more-threads/62614)

<div class="topic-metadata">

**Author:** [@vmuser](https://discourse.julialang.org/u/vmuser)\
**Replies:** 2\
**Last updated:** [June 9, 2021, 9:29am UTC](https://discourse.julialang.org/t/fully-parallelized-for-loop-becomes-slower-with-more-threads/62614 "2021-06-09T09:29:02Z")

</div>

Basically the title says it all: I have a for-loop that is fully parallelizable, so all the operations in the loop can be calculated independently. They only need access to the same multidimensional array but I make sure…

---

## [Improving performance in solving SDEProblem](https://discourse.julialang.org/t/improving-performance-in-solving-sdeproblem/62396)

<div class="topic-metadata">

**Author:** [@Frazze](https://discourse.julialang.org/u/Frazze)\
**Replies:** 8\
**Last updated:** [June 9, 2021, 9:00am UTC](https://discourse.julialang.org/t/improving-performance-in-solving-sdeproblem/62396 "2021-06-09T09:00:56Z")

</div>

Hi everyone, I’m studying part of the 2D Swift Hohenberg model with an additive noise term, but I’m really new to the SDEProblems so I don’t know if my way to build the model is the best way to solve it. I’ve take a lo…

---

## [What is the best way to wrap C double pointers into a Julia \`Matrix\`?](https://discourse.julialang.org/t/what-is-the-best-way-to-wrap-c-double-pointers-into-a-julia-matrix/62472)

<div class="topic-metadata">

**Author:** [@sapo](https://discourse.julialang.org/u/sapo)\
**Replies:** 3\
**Last updated:** [June 8, 2021, 7:38pm UTC](https://discourse.julialang.org/t/what-is-the-best-way-to-wrap-c-double-pointers-into-a-julia-matrix/62472 "2021-06-08T19:38:01Z")

</div>

Take this code which represents a matrix in C. int\*\* mat = (int\*\*) malloc(rows \* sizeof(int\*)) for (int index=0;index\<row;++index) { mat\[index\] = (int\*) malloc(cols \* sizeof(int)); } What is the best way to wrap m…

---

## [Reduced performance for parallel loops in larger code?](https://discourse.julialang.org/t/reduced-performance-for-parallel-loops-in-larger-code/62450)

<div class="topic-metadata">

**Author:** [@swishmas](https://discourse.julialang.org/u/swishmas)\
**Replies:** 10\
**Last updated:** [June 6, 2021, 3:42pm UTC](https://discourse.julialang.org/t/reduced-performance-for-parallel-loops-in-larger-code/62450 "2021-06-06T15:42:30Z")

</div>

I’ve prepared a code that works pretty well in isolation. A minimal working example is below, but I’m basically taking values from a set of input arrays to another set of output arrays. Edit: I’m going to simplify thi…

---

## [@turbo speeds routine, slows down everything else](https://discourse.julialang.org/t/turbo-speeds-routine-slows-down-everything-else/62163)

<div class="topic-metadata">

**Author:** [@rpmuller](https://discourse.julialang.org/u/rpmuller)\
**Replies:** 16\
**Last updated:** [June 5, 2021, 6:25am UTC](https://discourse.julialang.org/t/turbo-speeds-routine-slows-down-everything-else/62163 "2021-06-05T06:25:14Z")

</div>

I’ve been playing with LoopVectorization.jl to speed up the bottleneck in my code. I’ve included @turbo several times in the innermost loops in this routine, and nowhere else in the code. It currently speeds up that rout…

---

## [Parallel sampling](https://discourse.julialang.org/t/parallel-sampling/62310)

<div class="topic-metadata">

**Author:** [@marouane](https://discourse.julialang.org/u/marouane)\
**Replies:** 5\
**Last updated:** [June 4, 2021, 12:57am UTC](https://discourse.julialang.org/t/parallel-sampling/62310 "2021-06-04T00:57:35Z")

</div>

it is the first time i’m trying the parallel computing and before i go to my actual code, i decided to try it on a simple code to see the speed of the execution of the code @everywhere function sampler(x, y) z=…

---

## [Minimize Allocations](https://discourse.julialang.org/t/minimize-allocations/62362)

<div class="topic-metadata">

**Author:** [@natgeo-wong](https://discourse.julialang.org/u/natgeo-wong)\
**Replies:** 3\
**Last updated:** [June 3, 2021, 11:04pm UTC](https://discourse.julialang.org/t/minimize-allocations/62362 "2021-06-03T23:04:01Z")

</div>

Hi! How do I minimize allocations here? I thought that since all variables involved here are scalars, there should be minimal allocations? function ϕfield!( ϕn::Array{FT}, ϕ::Array{FT}, u::Array{FT}, v::Array{FT},…

---

## [How to speed up permutedims for high dimensional tensors](https://discourse.julialang.org/t/how-to-speed-up-permutedims-for-high-dimensional-tensors/62351)

<div class="topic-metadata">

**Author:** [@1115](https://discourse.julialang.org/u/1115)\
**Replies:** 3\
**Last updated:** [June 3, 2021, 8:58pm UTC](https://discourse.julialang.org/t/how-to-speed-up-permutedims-for-high-dimensional-tensors/62351 "2021-06-03T20:58:51Z")

</div>

I find permutedims is so slow, this is something can not be explained by complexity theory. It is because the permutedims is not fully optimized? it occupies \>90% of the computing time of my tensor program. julia\> a = …

---

## [Closure in struct type inference](https://discourse.julialang.org/t/closure-in-struct-type-inference/62180)

<div class="topic-metadata">

**Author:** [@cdawg](https://discourse.julialang.org/u/cdawg)\
**Replies:** 12\
**Last updated:** [June 3, 2021, 1:57pm UTC](https://discourse.julialang.org/t/closure-in-struct-type-inference/62180 "2021-06-03T13:57:10Z")

</div>

This comes up a lot in my code style. I’ve been doing this thing which is to store methods inside a struct as closures. (sort of like oo programming I guess?). This is a lot more convenient than storing the captured valu…

---

## [Parallelizing a for-loop with a matrix](https://discourse.julialang.org/t/parallelizing-a-for-loop-with-a-matrix/62250)

<div class="topic-metadata">

**Author:** [@natgeo-wong](https://discourse.julialang.org/u/natgeo-wong)\
**Replies:** 2\
**Last updated:** [June 2, 2021, 7:00am UTC](https://discourse.julialang.org/t/parallelizing-a-for-loop-with-a-matrix/62250 "2021-06-02T07:00:50Z")

</div>

I have a simple for-loop with a matrix, where I calculate a slice of the matrix via each step of the for-loop. e.g. for ilat = 1 : nlat, ilon = 1 : nlon for ip = 1 : np; esat\[ip+1\] = t2esat(Ta\[ilon,ilat,ip\],p\[ip+1…

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

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