# Performance

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

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

**Page:** 126

---

## [PSA: Microbenchmarks remember branch history](https://discourse.julialang.org/t/psa-microbenchmarks-remember-branch-history/17436)

<div class="topic-metadata">

**Author:** [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Replies:** 36\
**Last updated:** [October 1, 2019, 8:08am UTC](https://discourse.julialang.org/t/psa-microbenchmarks-remember-branch-history/17436 "2019-10-01T08:08:13Z")

</div>

Something to keep in mind when running microbenchmarks: The sneaky CPU can remember astoundingly long branch history patterns. If you run @btime on somthing, then you generate a periodic branching pattern: The period len…

---

## [Why making \`a\[range\] = b\[range\]\` seems to make unnecessary allocations?](https://discourse.julialang.org/t/why-making-a-range-b-range-seems-to-make-unnecessary-allocations/29325)

<div class="topic-metadata">

**Author:** [@pedrohnv](https://discourse.julialang.org/u/pedrohnv)\
**Replies:** 4\
**Last updated:** [September 30, 2019, 10:18pm UTC](https://discourse.julialang.org/t/why-making-a-range-b-range-seems-to-make-unnecessary-allocations/29325 "2019-09-30T22:18:33Z")

</div>

I was wondering why making a\[range\] = b\[range\] seems to make unnecessary allocations and if (why) that is intended. For example: function f!(a, b, n) a\[1:n, 1:n\] = b\[1:n, 1:n\] end function g!(a, b, n) copyto!(a…

---

## [Optimal way to make a line and column permutation copy of an array](https://discourse.julialang.org/t/optimal-way-to-make-a-line-and-column-permutation-copy-of-an-array/29331)

<div class="topic-metadata">

**Author:** [@pedrohnv](https://discourse.julialang.org/u/pedrohnv)\
**Replies:** 0\
**Last updated:** [September 30, 2019, 3:26pm UTC](https://discourse.julialang.org/t/optimal-way-to-make-a-line-and-column-permutation-copy-of-an-array/29331 "2019-09-30T15:26:24Z")

</div>

How can I optimize the following functions that copy a line-, column- or both- permutation (pl, pc, pcl, respectively) of a src array into a dest array? In particular, can the temp array be avoided in pcl? using Benchm…

---

## [Specialization tips to shrink 45x performance gap when comparing structs](https://discourse.julialang.org/t/specialization-tips-to-shrink-45x-performance-gap-when-comparing-structs/29249)

<div class="topic-metadata">

**Author:** [@milesf](https://discourse.julialang.org/u/milesf)\
**Replies:** 7\
**Last updated:** [September 30, 2019, 6:24am UTC](https://discourse.julialang.org/t/specialization-tips-to-shrink-45x-performance-gap-when-comparing-structs/29249 "2019-09-30T06:24:37Z")

</div>

I’m seeking tips on how to improve performance of struct comparisons where the specific comparison rule is selected at runtime. I have a struct with n fields, and I’d like to sort by each field in either order. Perform…

---

## [Simulate Nested Array Without Allocating New Memory Every Loop?](https://discourse.julialang.org/t/simulate-nested-array-without-allocating-new-memory-every-loop/29215)

<div class="topic-metadata">

**Author:** [@dylanjm](https://discourse.julialang.org/u/dylanjm)\
**Replies:** 13\
**Last updated:** [September 28, 2019, 10:50am UTC](https://discourse.julialang.org/t/simulate-nested-array-without-allocating-new-memory-every-loop/29215 "2019-09-28T10:50:51Z")

</div>

To start off, here is some necessary information julia\> versioninfo() Julia Version 1.2.0 Commit c6da87ff4b (2019-08-20 00:03 UTC) Platform Info: OS: macOS (x86\_64-apple-darwin18.6.0) CPU: Intel(R) Core(TM) i7-9750H…

---

## [What is the recommended way to decorate an IO stream with a filter in Julia](https://discourse.julialang.org/t/what-is-the-recommended-way-to-decorate-an-io-stream-with-a-filter-in-julia/29226)

<div class="topic-metadata">

**Author:** [@pszufe](https://discourse.julialang.org/u/pszufe)\
**Replies:** 1\
**Last updated:** [September 27, 2019, 1:34pm UTC](https://discourse.julialang.org/t/what-is-the-recommended-way-to-decorate-an-io-stream-with-a-filter-in-julia/29226 "2019-09-27T13:34:40Z")

</div>

What is the recommended way to decorate a IO stream with a filter? One great example of stream decorators is CodecZlib.jl that provides compression and decompression decorators for output and input streams respectively. …

---

## [Non-intuitive perf diff between \`matrix \* vector\`, \`matrix' \* vector\` and \`copy(matrix') \* vector\`](https://discourse.julialang.org/t/non-intuitive-perf-diff-between-matrix-vector-matrix-vector-and-copy-matrix-vector/29207)

<div class="topic-metadata">

**Author:** [@jeremejevs](https://discourse.julialang.org/u/jeremejevs)\
**Replies:** 2\
**Last updated:** [September 27, 2019, 7:09am UTC](https://discourse.julialang.org/t/non-intuitive-perf-diff-between-matrix-vector-matrix-vector-and-copy-matrix-vector/29207 "2019-09-27T07:09:25Z")

</div>

I’m using Julia 1.2. This is my test: a = rand(1000, 1000) b = a' c = copy(b) @btime a \* x setup=(x=rand(1000)) # 114.757 μs @btime b \* x setup=(x=rand(1000)) # 94.179 μs @btime c \* x setup=(x=rand(1000)) # 110.325 μs …

---

## [Avoiding unnecessary mallocs while building then solving a linear system inside a loop can only be achieved by routines that modify in-place?](https://discourse.julialang.org/t/avoiding-unnecessary-mallocs-while-building-then-solving-a-linear-system-inside-a-loop-can-only-be-achieved-by-routines-that-modify-in-place/29210)

<div class="topic-metadata">

**Author:** [@pedrohnv](https://discourse.julialang.org/u/pedrohnv)\
**Replies:** 2\
**Last updated:** [September 27, 2019, 2:50am UTC](https://discourse.julialang.org/t/avoiding-unnecessary-mallocs-while-building-then-solving-a-linear-system-inside-a-loop-can-only-be-achieved-by-routines-that-modify-in-place/29210 "2019-09-27T02:50:19Z")

</div>

Hello, I have some functions that build a linear system. I then want to build and solve the system in a loop, while modifying a parameter. My first, straightforward, approach resulted in many allocations being done unne…

---

## [Array by reference](https://discourse.julialang.org/t/array-by-reference/29187)

<div class="topic-metadata">

**Author:** [@alequa](https://discourse.julialang.org/u/alequa)\
**Replies:** 2\
**Last updated:** [September 26, 2019, 12:14pm UTC](https://discourse.julialang.org/t/array-by-reference/29187 "2019-09-26T12:14:30Z")

</div>

Assigning a new type out of function prevents the compiler to assign the returned-type properly. In the example I show it just ends up returning ::Any. In my broader example it messes up within the function itself and t…

---

## [Passing parameters and performances](https://discourse.julialang.org/t/passing-parameters-and-performances/29175)

<div class="topic-metadata">

**Author:** [@alequa](https://discourse.julialang.org/u/alequa)\
**Replies:** 3\
**Last updated:** [September 26, 2019, 12:11pm UTC](https://discourse.julialang.org/t/passing-parameters-and-performances/29175 "2019-09-26T12:11:00Z")

</div>

Hi, I am writing a simulator for spiking neural network. In the simulator I would like to use a loop like the one in the code Params = Dict{String,Union{Int,Bool}} function sim\_loop!(synapse\_params::Dict{String,Floa…

---

## [@code\_warntype but for allocations?](https://discourse.julialang.org/t/code-warntype-but-for-allocations/29190)

<div class="topic-metadata">

**Author:** [@cshenton](https://discourse.julialang.org/u/cshenton)\
**Replies:** 1\
**Last updated:** [September 26, 2019, 11:27am UTC](https://discourse.julialang.org/t/code-warntype-but-for-allocations/29190 "2019-09-26T11:27:36Z")

</div>

Is there a similar macro to @code\_warntype for allocations? As in, given a function call (or function and tuple of input types), highlights any calls in the function that allocate, just as code\_warntype highlights sub ex…

---

## [Float64 comparison operator performance](https://discourse.julialang.org/t/float64-comparison-operator-performance/29179)

<div class="topic-metadata">

**Author:** [@milesf](https://discourse.julialang.org/u/milesf)\
**Replies:** 8\
**Last updated:** [September 26, 2019, 8:39am UTC](https://discourse.julialang.org/t/float64-comparison-operator-performance/29179 "2019-09-26T08:39:38Z")

</div>

I expect the performance of a \< b to be the same as Base.lt(Base.Forward, a, b) if all type information is known at compile time, but I’m observing a 2.5x difference with Float64. using BenchmarkTools using Random Rand…

---

## [Shared-memory parallelization with large matrix](https://discourse.julialang.org/t/shared-memory-parallelization-with-large-matrix/29076)

<div class="topic-metadata">

**Author:** [@Sam](https://discourse.julialang.org/u/Sam)\
**Replies:** 9\
**Last updated:** [September 24, 2019, 6:33pm UTC](https://discourse.julialang.org/t/shared-memory-parallelization-with-large-matrix/29076 "2019-09-24T18:33:03Z")

</div>

Hi! I am currently writing a program that looks something like this Threads.@threads for i = 1:m a\[m\] = f(args, matrix\[:,:,m\]) end Where f is a function that runs some calculations, matrix is a large (e.g. 3000x…

---

## [Basic question about different type annotations in function declarations](https://discourse.julialang.org/t/basic-question-about-different-type-annotations-in-function-declarations/29086)

<div class="topic-metadata">

**Author:** [@SEA](https://discourse.julialang.org/u/SEA)\
**Replies:** 5\
**Last updated:** [September 23, 2019, 9:25pm UTC](https://discourse.julialang.org/t/basic-question-about-different-type-annotations-in-function-declarations/29086 "2019-09-23T21:25:18Z")

</div>

I wanted to clarify my understanding of the following ways of defining a function. f(x) = … f(x::T) where {T} = … f(x::Any) = … Is it true that 1. and 2. are equivalent if there are no type restrictions in …

---

## [Potential performance regression wrt 0.6: Products involving diagonal matrices MUCH slower than with general sparse matrices](https://discourse.julialang.org/t/potential-performance-regression-wrt-0-6-products-involving-diagonal-matrices-much-slower-than-with-general-sparse-matrices/29005)

<div class="topic-metadata">

**Author:** [@FHulsemann](https://discourse.julialang.org/u/FHulsemann)\
**Replies:** 7\
**Last updated:** [September 21, 2019, 5:09pm UTC](https://discourse.julialang.org/t/potential-performance-regression-wrt-0-6-products-involving-diagonal-matrices-much-slower-than-with-general-sparse-matrices/29005 "2019-09-21T17:09:20Z")

</div>

Hello. It so happens that I need to normalize sparse (real) matrices from time to time. Moving to v0.7 (and later), I have come across some surprising behaviour involving Diagonal (sparse) matrices. This example illustr…

---

## [Bad performance for dispatch-heavy code](https://discourse.julialang.org/t/bad-performance-for-dispatch-heavy-code/28989)

<div class="topic-metadata">

**Author:** [@erezsh](https://discourse.julialang.org/u/erezsh)\
**Replies:** 12\
**Last updated:** [September 20, 2019, 11:49am UTC](https://discourse.julialang.org/t/bad-performance-for-dispatch-heavy-code/28989 "2019-09-20T11:49:17Z")

</div>

I’m trying to write a compiler in Julia, and I’m getting very bad performance. Because it’s a multi-stage compiler, most of the code is just the same function for different types of ast. I made sure most of the structs …

---

## [Minimizing long compile time/Precompiling](https://discourse.julialang.org/t/minimizing-long-compile-time-precompiling/28861)

<div class="topic-metadata">

**Author:** [@JTomlinson](https://discourse.julialang.org/u/JTomlinson)\
**Replies:** 3\
**Last updated:** [September 19, 2019, 7:23am UTC](https://discourse.julialang.org/t/minimizing-long-compile-time-precompiling/28861 "2019-09-19T07:23:02Z")

</div>

I have some code for a research project of mine that takes quite a long time to compile. Here is a recent example @time generateMnli(Pk, bd22, 0.0) @time generateMnli(Pk, bd22, 0.0) 434.282438 seconds (502.49 M allocat…

---

## [Benchmarking with interpolated variable faster than hardcoded literal value](https://discourse.julialang.org/t/benchmarking-with-interpolated-variable-faster-than-hardcoded-literal-value/28927)

<div class="topic-metadata">

**Author:** [@milesf](https://discourse.julialang.org/u/milesf)\
**Replies:** 1\
**Last updated:** [September 18, 2019, 11:04pm UTC](https://discourse.julialang.org/t/benchmarking-with-interpolated-variable-faster-than-hardcoded-literal-value/28927 "2019-09-18T23:04:29Z")

</div>

Consistently observing that using an interpolated variable to iterate over for i = 1:n is faster than using a literal for i = 1:10. It’s about 7.5 ns vs 6 ns, so not much absolute difference, but somewhat significant rel…

---

## [Call macro created function/types from generated function. world age problem](https://discourse.julialang.org/t/call-macro-created-function-types-from-generated-function-world-age-problem/28859)

<div class="topic-metadata">

**Author:** [@Orbots](https://discourse.julialang.org/u/Orbots)\
**Replies:** 2\
**Last updated:** [September 17, 2019, 8:19pm UTC](https://discourse.julialang.org/t/call-macro-created-function-types-from-generated-function-world-age-problem/28859 "2019-09-17T20:19:36Z")

</div>

I want to allow a user of my module to generate some types and functions via a macro which are then supported by generated functions. For reasons, I am able to deduce constant scalar numbers from type information for a …

---

## [Ways to speed up this code](https://discourse.julialang.org/t/ways-to-speed-up-this-code/28841)

<div class="topic-metadata">

**Author:** [@IljaK91](https://discourse.julialang.org/u/IljaK91)\
**Replies:** 4\
**Last updated:** [September 17, 2019, 3:57pm UTC](https://discourse.julialang.org/t/ways-to-speed-up-this-code/28841 "2019-09-17T15:57:55Z")

</div>

Hey everybody, I want to run this code on a relatively large dataset consisting of daily firm-level, industry-level and market-level data. This code takes long to run, because I run a simple regression for every firm-mo…

---

## [Implementation for matrix multiplication with \`adjoint\`](https://discourse.julialang.org/t/implementation-for-matrix-multiplication-with-adjoint/28828)

<div class="topic-metadata">

**Author:** [@tomohiro\_soejima](https://discourse.julialang.org/u/tomohiro_soejima)\
**Replies:** 4\
**Last updated:** [September 17, 2019, 1:54am UTC](https://discourse.julialang.org/t/implementation-for-matrix-multiplication-with-adjoint/28828 "2019-09-17T01:54:11Z")

</div>

Hi, As I understand it, adjoint creates a lazy wrapper for an adjoint of an array, and therefore does not create a copy. I’m wondering how multiplication is implemented in this case i.e. what kind of LAPACK functionalit…

---

## [When to use sizehint! for Dict?](https://discourse.julialang.org/t/when-to-use-sizehint-for-dict/28833)

<div class="topic-metadata">

**Author:** [@milesf](https://discourse.julialang.org/u/milesf)\
**Replies:** 0\
**Last updated:** [September 16, 2019, 11:17pm UTC](https://discourse.julialang.org/t/when-to-use-sizehint-for-dict/28833 "2019-09-16T23:17:01Z")

</div>

Benchmarking shows that using sizehint! to match the expected number of Dict elements is best in almost all cases, except when the number of elements is at or near 10^5. Both 10^4 and 10^6 prefer sizehint!, but 10^5 stra…

---

## [How to make Julia slow?](https://discourse.julialang.org/t/how-to-make-julia-slow/28742)

<div class="topic-metadata">

**Author:** [@Carol](https://discourse.julialang.org/u/Carol)\
**Replies:** 11\
**Last updated:** [September 16, 2019, 6:55pm UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742 "2019-09-16T18:55:09Z")

</div>

Hi, I want to test the speed of dot product dot()(speeded up by Julia) V.S. dot product without any parallel. I want to see how fast does Julia speed up the dot product. For non-parallel dot product, I write a for-loop…

---

## [Performance of Dates.Time equality and comparison](https://discourse.julialang.org/t/performance-of-dates-time-equality-and-comparison/28738)

<div class="topic-metadata">

**Author:** [@artemsolod](https://discourse.julialang.org/u/artemsolod)\
**Replies:** 3\
**Last updated:** [September 14, 2019, 10:09am UTC](https://discourse.julialang.org/t/performance-of-dates-time-equality-and-comparison/28738 "2019-09-14T10:09:45Z")

</div>

I am noticing large performance costs when doing operations with Time (as compared to DateTime). One example would be using Dates n = now(); arr\_dt = \[n for \_ in 1:10^7\]; arr\_ts = Time.(arr\_dt); all(arr\_dt .== arr\_dt);…

---

## [Speeding Up a Backward Induction Code](https://discourse.julialang.org/t/speeding-up-a-backward-induction-code/27762)

<div class="topic-metadata">

**Author:** [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Replies:** 30\
**Last updated:** [September 11, 2019, 5:56pm UTC](https://discourse.julialang.org/t/speeding-up-a-backward-induction-code/27762 "2019-09-11T17:56:41Z")

</div>

Hi all! I am solving a model and after Profiling the code I realized that the function myfun2 is the big bottleneck of my code. I created a MWE that preserves the computational cost of doing this function and I wanted to…

---

## [Little parallel speedup on binary tree structure in Julia 1.3.0-rc1](https://discourse.julialang.org/t/little-parallel-speedup-on-binary-tree-structure-in-julia-1-3-0-rc1/28594)

<div class="topic-metadata">

**Author:** [@nmatzke](https://discourse.julialang.org/u/nmatzke)\
**Replies:** 0\
**Last updated:** [September 10, 2019, 9:18am UTC](https://discourse.julialang.org/t/little-parallel-speedup-on-binary-tree-structure-in-julia-1-3-0-rc1/28594 "2019-09-10T09:18:23Z")

</div>

Hi all, I am trying to use @spawn in Julia 1.3.0-rc1 to parallelize some slow calculations. My data is in a binary tree structure, where the calculations have to first be done at the tips, then the nodes ancestral to t…

---

## [Reading repr() string to object?](https://discourse.julialang.org/t/reading-repr-string-to-object/28548)

<div class="topic-metadata">

**Author:** [@nmatzke](https://discourse.julialang.org/u/nmatzke)\
**Replies:** 2\
**Last updated:** [September 9, 2019, 2:34am UTC](https://discourse.julialang.org/t/reading-repr-string-to-object/28548 "2019-09-09T02:34:14Z")

</div>

Hi all, In R, the functions dput() and dget() let you output an object to a string representation, and read it back in. This is handy for quickly reproducing objects for e.g. reproducible tests or for help. In Julia, …

---

## [CUDAnative , performance drop after several timesteps](https://discourse.julialang.org/t/cudanative-performance-drop-after-several-timesteps/28495)

<div class="topic-metadata">

**Author:** [@YJC](https://discourse.julialang.org/u/YJC)\
**Replies:** 5\
**Last updated:** [September 8, 2019, 7:43am UTC](https://discourse.julialang.org/t/cudanative-performance-drop-after-several-timesteps/28495 "2019-09-08T07:43:33Z")

</div>

Hi all, I am building up a time marching simulation via using CUDAnative, I found that after several time steps , the performance drop significantly. If I “synchronize” all the thread at some point, the performance was…

---

## [Very large compilation time (and space)](https://discourse.julialang.org/t/very-large-compilation-time-and-space/28342)

<div class="topic-metadata">

**Author:** [@aml](https://discourse.julialang.org/u/aml)\
**Replies:** 11\
**Last updated:** [September 6, 2019, 3:47pm UTC](https://discourse.julialang.org/t/very-large-compilation-time-and-space/28342 "2019-09-06T15:47:45Z")

</div>

In a previous post, I mentioned a small interpreter that I wrote both in direct style and in continuation-passing style. In the first case, Julia very quickly compiles the interpreter methods as they are being used. In t…

---

## [Something(a, b) not shortcutting](https://discourse.julialang.org/t/something-a-b-not-shortcutting/27746)

<div class="topic-metadata">

**Author:** [@Charlie\_He](https://discourse.julialang.org/u/Charlie_He)\
**Replies:** 4\
**Last updated:** [September 6, 2019, 9:18am UTC](https://discourse.julialang.org/t/something-a-b-not-shortcutting/27746 "2019-09-06T09:18:56Z")

</div>

Assuming we have: function do\_work(x) sleep(2) x end It turns out something(Some(2), do\_work(3)) still invoke do\_work, which returns 2 seconds later. It would be better to define it as a macro, which retains …

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

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