# Performance

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

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

**Page:** 71

---

## [Compute Distribution among binary vector](https://discourse.julialang.org/t/compute-distribution-among-binary-vector/77792)

<div class="topic-metadata">

**Author:** [@GoYetChallenged](https://discourse.julialang.org/u/GoYetChallenged)\
**Replies:** 1\
**Last updated:** [March 12, 2022, 8:21pm UTC](https://discourse.julialang.org/t/compute-distribution-among-binary-vector/77792 "2022-03-12T20:21:43Z")

</div>

I want to compute marginal distributions among binary data.For example, I have several vectors like a = \[0, 1, 0, 1\] b = \[1, 0, 0, 1\] and compute all possible distributions, like P(a=0, b=0) = 1/4, P(a=0, b=1) = 1/4, P…

---

## [Tullio - multiline syntax - Soft or hard local scope?](https://discourse.julialang.org/t/tullio-multiline-syntax-soft-or-hard-local-scope/77616)

<div class="topic-metadata">

**Author:** [@Emmanuel-R8](https://discourse.julialang.org/u/Emmanuel-R8)\
**Replies:** 6\
**Last updated:** [March 11, 2022, 2:51am UTC](https://discourse.julialang.org/t/tullio-multiline-syntax-soft-or-hard-local-scope/77616 "2022-03-11T02:51:04Z")

</div>

I have a block of code using Tullio with a begin ... end syntax. I discovered that, within the block, only = can be used. No := will be acctepted. My problem now is that on execution that patch\_mean is an unknown symbo…

---

## [Struct of singleton Abstract types performance](https://discourse.julialang.org/t/struct-of-singleton-abstract-types-performance/77679)

<div class="topic-metadata">

**Author:** [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Replies:** 6\
**Last updated:** [March 10, 2022, 5:37pm UTC](https://discourse.julialang.org/t/struct-of-singleton-abstract-types-performance/77679 "2022-03-10T17:37:33Z")

</div>

I understand Julia not being fast when using structs of abstract types and I know that there is no such thing as singleton abstract types. However I would hope that it would be different when using Abstract types of whic…

---

## [Removing precompilation leads to lower allocations!?](https://discourse.julialang.org/t/removing-precompilation-leads-to-lower-allocations/73621)

<div class="topic-metadata">

**Author:** [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Replies:** 5\
**Last updated:** [March 10, 2022, 12:52pm UTC](https://discourse.julialang.org/t/removing-precompilation-leads-to-lower-allocations/73621 "2022-03-10T12:52:27Z")

</div>

In one of my packages I tried to lower import times, so I added a couple of typical usage examples in a “precompile” function. Something like function \_my\_precompile() # my "typical use case" code ... end functi…

---

## [\`@nospecialize\` for variadic and keyword arguments](https://discourse.julialang.org/t/nospecialize-for-variadic-and-keyword-arguments/77517)

<div class="topic-metadata">

**Author:** [@calebwin](https://discourse.julialang.org/u/calebwin)\
**Replies:** 3\
**Last updated:** [March 9, 2022, 9:14pm UTC](https://discourse.julialang.org/t/nospecialize-for-variadic-and-keyword-arguments/77517 "2022-03-09T21:14:20Z")

</div>

I have a function pt: function pt( args::Union{AbstractFuture,PartitionType,PartitionTypeComposition,Vector}...; kwargs..., ) that has a whole bunch of specializations: (determined using SnoopCompile): var"#pt…

---

## [How to find pairs of indices that meet specific criteria](https://discourse.julialang.org/t/how-to-find-pairs-of-indices-that-meet-specific-criteria/77119)

<div class="topic-metadata">

**Author:** [@Shouto](https://discourse.julialang.org/u/Shouto)\
**Replies:** 3\
**Last updated:** [February 26, 2022, 11:18pm UTC](https://discourse.julialang.org/t/how-to-find-pairs-of-indices-that-meet-specific-criteria/77119 "2022-02-26T23:18:59Z")

</div>

Hi all, Let E be an array such that E = \[3,5,3,5,3\] so E\[1\] = 3,…,E\[5\] = 3. I want to find and collect the pairs of two indices such that (E\[1\],E\[2\]), (E\[1\],E\[4\]),(E\[2\],E\[4\]), (E\[2\],E\[5\]), (E\[3\],E\[4\]), (E\[4\], E\[5\]). Th…

---

## [How to sort a vector by an expensive function in place efficiently?](https://discourse.julialang.org/t/how-to-sort-a-vector-by-an-expensive-function-in-place-efficiently/77540)

<div class="topic-metadata">

**Author:** [@taotree](https://discourse.julialang.org/u/taotree)\
**Replies:** 14\
**Last updated:** [March 8, 2022, 4:19pm UTC](https://discourse.julialang.org/t/how-to-sort-a-vector-by-an-expensive-function-in-place-efficiently/77540 "2022-03-08T16:19:20Z")

</div>

The normal sort!(...;by=f) sorts in place by a function, but it results in calling that function many more times than the length of the vector. I tried all the sorting algorithms included in Base and all of them resulted…

---

## [Force specialization on kwargs](https://discourse.julialang.org/t/force-specialization-on-kwargs/34789)

<div class="topic-metadata">

**Author:** [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)\
**Replies:** 15\
**Last updated:** [March 7, 2022, 1:46pm UTC](https://discourse.julialang.org/t/force-specialization-on-kwargs/34789 "2022-03-07T13:46:53Z")

</div>

If I have a function like this: f\_vararg(varargs::Int...) = tuple(varargs...) I can force specialization on varargs with either of the following: g\_vararg(varargs::Vararg{Int, N}) where {N} = tuple(varargs...) h\_vara…

---

## [Accessing a column value from DataFrameRow allocates](https://discourse.julialang.org/t/accessing-a-column-value-from-dataframerow-allocates/77481)

<div class="topic-metadata">

**Author:** [@Hawkes](https://discourse.julialang.org/u/Hawkes)\
**Replies:** 10\
**Last updated:** [March 7, 2022, 1:44pm UTC](https://discourse.julialang.org/t/accessing-a-column-value-from-dataframerow-allocates/77481 "2022-03-07T13:44:54Z")

</div>

Hi, I am a bit puzzled that the following code allocates. According to the docs, a DataFrameRow should be a view and this type of field setting in a Dict should not allocate IMHO. Am I using DataFrames wrong? NamedTuple…

---

## [Why is julia slowest here?](https://discourse.julialang.org/t/why-is-julia-slowest-here/77479)

<div class="topic-metadata">

**Author:** [@matic\_lauko](https://discourse.julialang.org/u/matic_lauko)\
**Replies:** 4\
**Last updated:** [March 6, 2022, 7:47pm UTC](https://discourse.julialang.org/t/why-is-julia-slowest-here/77479 "2022-03-06T19:47:20Z")

</div>

https://github.com/niklas-heer/speed-comparison I tried to convince my friend that Julia is faster than python, he googled it and found this(above), why is it that python is faster than Julia, and even JS. Is it somethi…

---

## [Help with excessive, unpredictable GC time from string allocations](https://discourse.julialang.org/t/help-with-excessive-unpredictable-gc-time-from-string-allocations/77334)

<div class="topic-metadata">

**Author:** [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Replies:** 12\
**Last updated:** [March 5, 2022, 10:49pm UTC](https://discourse.julialang.org/t/help-with-excessive-unpredictable-gc-time-from-string-allocations/77334 "2022-03-05T22:49:24Z")

</div>

I’ve been having a hell of a time with some performance disasters when loading a large number of strings from a file. I am hitting this in my rewrite of a parquet reader and was caught rather by surprise, because despit…

---

## [GPU performance evaluation exceeds target peakflop using CUDA.jl](https://discourse.julialang.org/t/gpu-performance-evaluation-exceeds-target-peakflop-using-cuda-jl/59092)

<div class="topic-metadata">

**Author:** [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Replies:** 6\
**Last updated:** [March 4, 2022, 2:03pm UTC](https://discourse.julialang.org/t/gpu-performance-evaluation-exceeds-target-peakflop-using-cuda-jl/59092 "2022-03-04T14:03:12Z")

</div>

Hi, I use the following kernel (weirdly adding n\_{nin}\*(n\_{nin}-1)/2 to array elements) in order to evaluate the peak performance of my GPU : # CPU bound kernel for large enough values of nin function kernel\_compute\_bo…

---

## [MKL slower than openblas in intel cpu](https://discourse.julialang.org/t/mkl-slower-than-openblas-in-intel-cpu/77169)

<div class="topic-metadata">

**Author:** [@Jae-Mo\_Lihm](https://discourse.julialang.org/u/Jae-Mo_Lihm)\
**Replies:** 7\
**Last updated:** [March 2, 2022, 3:48pm UTC](https://discourse.julialang.org/t/mkl-slower-than-openblas-in-intel-cpu/77169 "2022-03-02T15:48:01Z")

</div>

I found MKL is ~1.5 times slower than openblas for matrix-matrix multiplication (both without multithreading). Since I’m using intel CPU, I expected MKL to be faster. Is there anything obviously wrong in this benchmark?…

---

## [Performance of using CartesianIndices with MArray](https://discourse.julialang.org/t/performance-of-using-cartesianindices-with-marray/77167)

<div class="topic-metadata">

**Author:** [@nchisholm](https://discourse.julialang.org/u/nchisholm)\
**Replies:** 2\
**Last updated:** [March 2, 2022, 3:29pm UTC](https://discourse.julialang.org/t/performance-of-using-cartesianindices-with-marray/77167 "2022-03-02T15:29:10Z")

</div>

Multidimensional algorithms built on CartesianIndices seem to have significant performance overhead when applied to StaticArrays.MArray​s, but not regular Array​s. Writing several functions with nested loops for differe…

---

## [Mapreduce with broadcasting](https://discourse.julialang.org/t/mapreduce-with-broadcasting/77053)

<div class="topic-metadata">

**Author:** [@torrance](https://discourse.julialang.org/u/torrance)\
**Replies:** 9\
**Last updated:** [March 2, 2022, 10:28am UTC](https://discourse.julialang.org/t/mapreduce-with-broadcasting/77053 "2022-03-02T10:28:50Z")

</div>

I want to perform a mapreduce over multiple iterators that don’t have the same dimensions, but which can be broadcast together. For example: arr1 = rand(1, 1, 3) arr2 = rand(100, 100, 1) mapreduce(+, \*, arr1, arr2; dim…

---

## [Allocations when overwriting array elements in-place](https://discourse.julialang.org/t/allocations-when-overwriting-array-elements-in-place/77215)

<div class="topic-metadata">

**Author:** [@misa](https://discourse.julialang.org/u/misa)\
**Replies:** 5\
**Last updated:** [March 1, 2022, 1:07pm UTC](https://discourse.julialang.org/t/allocations-when-overwriting-array-elements-in-place/77215 "2022-03-01T13:07:04Z")

</div>

I have a relatively large matrix, where I want to set all values below a certain threshold to zero: @time A = rand(1000,1000,1000) @time bool = A .\< 0.5 @time A\[bool\] .= 0.0 5.653554 seconds (2 allocations: 7.451 GiB, …

---

## [Reusing preallocated memory without unsafe wraps](https://discourse.julialang.org/t/reusing-preallocated-memory-without-unsafe-wraps/77069)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 8\
**Last updated:** [February 27, 2022, 8:01pm UTC](https://discourse.julialang.org/t/reusing-preallocated-memory-without-unsafe-wraps/77069 "2022-02-27T20:01:04Z")

</div>

Hello, I need to use large arrays of floats in a large number of iterations. In each iteration, the size of the arrays will be different. If memory permits, I can pre-allocate the memory needed for all iterations at o…

---

## [Time cost for using structs](https://discourse.julialang.org/t/time-cost-for-using-structs/77149)

<div class="topic-metadata">

**Author:** [@lineycroc](https://discourse.julialang.org/u/lineycroc)\
**Replies:** 2\
**Last updated:** [February 27, 2022, 2:07pm UTC](https://discourse.julialang.org/t/time-cost-for-using-structs/77149 "2022-02-27T14:07:31Z")

</div>

I am trying to better understand the performance implications of using mutable structs. My actual use case is similar to the Optim package of storing a state variable that will change every iteration (such as https://git…

---

## [Operation between two large N-dimensional arrays](https://discourse.julialang.org/t/operation-between-two-large-n-dimensional-arrays/77141)

<div class="topic-metadata">

**Author:** [@Tzaki](https://discourse.julialang.org/u/Tzaki)\
**Replies:** 2\
**Last updated:** [February 27, 2022, 10:41am UTC](https://discourse.julialang.org/t/operation-between-two-large-n-dimensional-arrays/77141 "2022-02-27T10:41:10Z")

</div>

Hello, I am pretty much new to Julia. I am now trying to do an operation between two large N-dimensional sparse arrays of the same size (typically something like 8-dimensional array with 5 to 10 elements for each dimens…

---

## [Fastest way to initialize StaticArray of dynamic size with state](https://discourse.julialang.org/t/fastest-way-to-initialize-staticarray-of-dynamic-size-with-state/77091)

<div class="topic-metadata">

**Author:** [@taotree](https://discourse.julialang.org/u/taotree)\
**Replies:** 3\
**Last updated:** [February 26, 2022, 12:21am UTC](https://discourse.julialang.org/t/fastest-way-to-initialize-staticarray-of-dynamic-size-with-state/77091 "2022-02-26T00:21:49Z")

</div>

I’m constructing an SVector, but each value depends on the previous calculated value. This is still simple to do with sacollect, but then it has to box the input and so allocates (see example below). What is the optimal …

---

## [Large performance regression in nightly build](https://discourse.julialang.org/t/large-performance-regression-in-nightly-build/76440)

<div class="topic-metadata">

**Author:** [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Replies:** 6\
**Last updated:** [February 25, 2022, 11:05pm UTC](https://discourse.julialang.org/t/large-performance-regression-in-nightly-build/76440 "2022-02-25T23:05:13Z")

</div>

Update the 1.8dev version today and … | | |\_| | | | (\_| | | Version 1.8.0-DEV.1519 (2022-02-13) \_/ |\\\_\_'\_|\_|\_|\\\_\_'\_| | Commit 1978580e72 (1 day old master) |\_\_/ | julia\> cd("C:/v"); @time using…

---

## [Recursive @generated functions with function barriers causes allocations](https://discourse.julialang.org/t/recursive-generated-functions-with-function-barriers-causes-allocations/76910)

<div class="topic-metadata">

**Author:** [@jg-854](https://discourse.julialang.org/u/jg-854)\
**Replies:** 6\
**Last updated:** [February 25, 2022, 1:49pm UTC](https://discourse.julialang.org/t/recursive-generated-functions-with-function-barriers-causes-allocations/76910 "2022-02-25T13:49:48Z")

</div>

Hey! I am using generated functions in a recursive manner, and I have formed a contrived example which highlights how unnecessary allocations can occur. First, I will show you the efficient case @generated function Fac…

---

## [How to generate plots in documentation?](https://discourse.julialang.org/t/how-to-generate-plots-in-documentation/77009)

<div class="topic-metadata">

**Author:** [@Giulio\_Benedetti](https://discourse.julialang.org/u/Giulio_Benedetti)\
**Replies:** 1\
**Last updated:** [February 25, 2022, 12:42pm UTC](https://discourse.julialang.org/t/how-to-generate-plots-in-documentation/77009 "2022-02-25T12:42:38Z")

</div>

Hi! My question is somewhat related to this topic, but its solution doesn’t work in my case. I’d like the code chunks within my docs/src/ directory to automatically generate images inside the docs upon deployment. In fa…

---

## [How to release memory with EzXML](https://discourse.julialang.org/t/how-to-release-memory-with-ezxml/76533)

<div class="topic-metadata">

**Author:** [@jade\_mackay](https://discourse.julialang.org/u/jade_mackay)\
**Replies:** 1\
**Last updated:** [February 25, 2022, 5:56am UTC](https://discourse.julialang.org/t/how-to-release-memory-with-ezxml/76533 "2022-02-25T05:56:55Z")

</div>

Is there any way to release the memory after using EzXML’s readxml(path) function? I have tried doc = readxml(path) doc = nothing GC.gc() Thanks!

---

## [Same code run multiple times gives wildly different timings](https://discourse.julialang.org/t/same-code-run-multiple-times-gives-wildly-different-timings/76976)

<div class="topic-metadata">

**Author:** [@ForceBru](https://discourse.julialang.org/u/ForceBru)\
**Replies:** 39\
**Last updated:** [February 24, 2022, 4:52pm UTC](https://discourse.julialang.org/t/same-code-run-multiple-times-gives-wildly-different-timings/76976 "2022-02-24T16:52:40Z")

</div>

I have some code that heavily uses @tturbo from LoopVectorization for matmul-like operations. The main idea here is that I use Julia’s dispatch to pass settings to the algorithm. For example, I call fit!(option), and thi…

---

## [Accelerate pairwise damage computation](https://discourse.julialang.org/t/accelerate-pairwise-damage-computation/76278)

<div class="topic-metadata">

**Author:** [@maphdze](https://discourse.julialang.org/u/maphdze)\
**Replies:** 12\
**Last updated:** [February 24, 2022, 10:06am UTC](https://discourse.julialang.org/t/accelerate-pairwise-damage-computation/76278 "2022-02-24T10:06:56Z")

</div>

Can someone help me to accelerate the pairwise damage computation? This problem is very similar to the one in Accelerate pairwise L-J force computation. And I adopted the conclusion that the pairlist should be sorted fir…

---

## [Performance issues with CartesianIndices](https://discourse.julialang.org/t/performance-issues-with-cartesianindices/76990)

<div class="topic-metadata">

**Author:** [@nchisholm](https://discourse.julialang.org/u/nchisholm)\
**Replies:** 5\
**Last updated:** [February 24, 2022, 2:54am UTC](https://discourse.julialang.org/t/performance-issues-with-cartesianindices/76990 "2022-02-24T02:54:19Z")

</div>

I am encountering a handful of performance issues using CartesianIndices (versus using hard-coded nested for loops) to write dimension-agnostic code: There is apparent runtime cost associated with using type parameters…

---

## [Unexpected Allocations with Multiple Dispatch](https://discourse.julialang.org/t/unexpected-allocations-with-multiple-dispatch/76988)

<div class="topic-metadata">

**Author:** [@pulsipher](https://discourse.julialang.org/u/pulsipher)\
**Replies:** 2\
**Last updated:** [February 23, 2022, 9:53pm UTC](https://discourse.julialang.org/t/unexpected-allocations-with-multiple-dispatch/76988 "2022-02-23T21:53:58Z")

</div>

I am setting up a multiple dispatch structure and get unexpected allocations when I use more than 3 dispatch types as illustrated in the MWE below: Consider the following composite types: for T in (:A, :B, :C) @eva…

---

## [Speeding up my code](https://discourse.julialang.org/t/speeding-up-my-code/76915)

<div class="topic-metadata">

**Author:** [@nicob](https://discourse.julialang.org/u/nicob)\
**Replies:** 7\
**Last updated:** [February 23, 2022, 5:40pm UTC](https://discourse.julialang.org/t/speeding-up-my-code/76915 "2022-02-23T17:40:25Z")

</div>

Hi, I’m quite new to Julia and I’m looking for suggestions to improve the performance of my code to hopefully beat the Python version. From these 2 functions do you see any margin of improvement? For example I’am trying…

---

## [How to create SMatrix from SVectors efficiently](https://discourse.julialang.org/t/how-to-create-smatrix-from-svectors-efficiently/76969)

<div class="topic-metadata">

**Author:** [@ncxst](https://discourse.julialang.org/u/ncxst)\
**Replies:** 1\
**Last updated:** [February 23, 2022, 12:48pm UTC](https://discourse.julialang.org/t/how-to-create-smatrix-from-svectors-efficiently/76969 "2022-02-23T12:48:31Z")

</div>

Hi, I have a function f(i) = SA\[i,2i\] that generates SVectors. I want to concatenate a small, but variable amount of them into a SMatrix. For a fixed amount I can do: julia\> \[f(1) f(2) f(3)\]' 3×2 SMatrix{3, 2, Int64, 6…

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

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