# Performance

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

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

**Page:** 101

---

## [Surprising @fastmath behavior](https://discourse.julialang.org/t/surprising-fastmath-behavior/54600)

<div class="topic-metadata">

**Author:** [@Christian\_Rorvik](https://discourse.julialang.org/u/Christian_Rorvik)\
**Replies:** 3\
**Last updated:** [February 4, 2021, 10:45am UTC](https://discourse.julialang.org/t/surprising-fastmath-behavior/54600 "2021-02-04T10:45:54Z")

</div>

Here’s something that caught me off guard. Example is reduced to trivial code, but I caught this in a much more complex context. function foo(a, b, c) @fastmath x = a \* b + c isnan(x) ? 0.0 : x end code\_native(f…

---

## [Performance of structs with incompletely parameterized fields](https://discourse.julialang.org/t/performance-of-structs-with-incompletely-parameterized-fields/54580)

<div class="topic-metadata">

**Author:** [@Deduction42](https://discourse.julialang.org/u/Deduction42)\
**Replies:** 3\
**Last updated:** [February 4, 2021, 9:29am UTC](https://discourse.julialang.org/t/performance-of-structs-with-incompletely-parameterized-fields/54580 "2021-02-04T09:29:08Z")

</div>

Hello, I the performance section, it was stated that we should avoid fields with abstract types struct MyAmbiguousStruct val::AbstractFloat end But what about incompletely parameterized types? How bad is something …

---

## [Unexpected type instability with getproperty but not setproperty!](https://discourse.julialang.org/t/unexpected-type-instability-with-getproperty-but-not-setproperty/26975)

<div class="topic-metadata">

**Author:** [@cshenton](https://discourse.julialang.org/u/cshenton)\
**Replies:** 17\
**Last updated:** [February 4, 2021, 6:34am UTC](https://discourse.julialang.org/t/unexpected-type-instability-with-getproperty-but-not-setproperty/26975 "2021-02-04T06:34:02Z")

</div>

Julia 1.1.0 on macOS mojave In the following example, I’d expect branch elimination to make both of the following type stable, however getproperty isn’t type stable and is allocating. Could someone shed some light on wh…

---

## [CUDA sum kernels, threads and blocks, complex values](https://discourse.julialang.org/t/cuda-sum-kernels-threads-and-blocks-complex-values/54490)

<div class="topic-metadata">

**Author:** [@ozmaden](https://discourse.julialang.org/u/ozmaden)\
**Replies:** 2\
**Last updated:** [February 3, 2021, 12:32am UTC](https://discourse.julialang.org/t/cuda-sum-kernels-threads-and-blocks-complex-values/54490 "2021-02-03T00:32:43Z")

</div>

Hi there, I was trying to implement a custom sum-dot-product-thingy using CUDA.jl kernels when I stumbled upon this documentation PR. It stems from a discussion had not too long ago here. I probably do not understand so…

---

## [Writing a fast nlp tokenizer in Julia](https://discourse.julialang.org/t/writing-a-fast-nlp-tokenizer-in-julia/54176)

<div class="topic-metadata">

**Author:** [@merckxiaan](https://discourse.julialang.org/u/merckxiaan)\
**Replies:** 12\
**Last updated:** [February 2, 2021, 4:23pm UTC](https://discourse.julialang.org/t/writing-a-fast-nlp-tokenizer-in-julia/54176 "2021-02-02T16:23:46Z")

</div>

Hello everyone, As a learning exercise, I’m interested in writing a byte-pair-encoding (BPE) tokenizer in Julia. The meat of this tokenizer would be to find the most occuring pairs of tokens (initially these are just t…

---

## [StructArrays creating a lot of allocations compared to arrays](https://discourse.julialang.org/t/structarrays-creating-a-lot-of-allocations-compared-to-arrays/54377)

<div class="topic-metadata">

**Author:** [@MrRobot](https://discourse.julialang.org/u/MrRobot)\
**Replies:** 2\
**Last updated:** [February 1, 2021, 3:28pm UTC](https://discourse.julialang.org/t/structarrays-creating-a-lot-of-allocations-compared-to-arrays/54377 "2021-02-01T15:28:21Z")

</div>

I am converting a molecular dynamics code from passing arrays, to instead holding information in StructArray’s. Unfortunately, the code is now 20 times slower. Below I have two identical MWE, one doing the force calcula…

---

## [Is it worth it to check if a collection is empty before iterating?](https://discourse.julialang.org/t/is-it-worth-it-to-check-if-a-collection-is-empty-before-iterating/54360)

<div class="topic-metadata">

**Author:** [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Replies:** 5\
**Last updated:** [February 1, 2021, 9:23am UTC](https://discourse.julialang.org/t/is-it-worth-it-to-check-if-a-collection-is-empty-before-iterating/54360 "2021-02-01T09:23:22Z")

</div>

Is it worth checking if a collection is empty before iterating? That is, is there any argument for preferring option 2 in the following example? # Collection that may or may not be empty data = filter(x -\> x \> 0.75, ran…

---

## [Splitting Int8s?](https://discourse.julialang.org/t/splitting-int8s/54290)

<div class="topic-metadata">

**Author:** [@Ian\_Slagle](https://discourse.julialang.org/u/Ian_Slagle)\
**Replies:** 12\
**Last updated:** [January 31, 2021, 4:31am UTC](https://discourse.julialang.org/t/splitting-int8s/54290 "2021-01-31T04:31:00Z")

</div>

I have a struct that is copied a lot in my program, so reducing the size of this struct has very noticeable impacts on performance. Of the variables I have, some are an integer (currently represented as Int8) that are bo…

---

## [Rebinding local variable inside function and type stability: does it matter?](https://discourse.julialang.org/t/rebinding-local-variable-inside-function-and-type-stability-does-it-matter/54159)

<div class="topic-metadata">

**Author:** [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Replies:** 8\
**Last updated:** [January 30, 2021, 4:08pm UTC](https://discourse.julialang.org/t/rebinding-local-variable-inside-function-and-type-stability-does-it-matter/54159 "2021-01-30T16:08:50Z")

</div>

Based on my limited understanding of the documentation here, type stability mainly pertains to the return type. However, if I change the type of a local variable (essentially rebinding) inside a function as follows: g(x…

---

## [For-loop in function is faster than global scope?](https://discourse.julialang.org/t/for-loop-in-function-is-faster-than-global-scope/54279)

<div class="topic-metadata">

**Author:** [@anon74562486](https://discourse.julialang.org/u/anon74562486)\
**Replies:** 3\
**Last updated:** [January 30, 2021, 2:37pm UTC](https://discourse.julialang.org/t/for-loop-in-function-is-faster-than-global-scope/54279 "2021-01-30T14:37:27Z")

</div>

Why are loops faster in functions? This: a = \[1:10\_000\_000;\] b = zeros(Int64, length(a)) function double!(x, y) L = length(x) for i in 1:L @inbounds y\[i\] = 2x\[i\] end nothing end @time double!(…

---

## [Compiling specialized functions for large set of user-passed options](https://discourse.julialang.org/t/compiling-specialized-functions-for-large-set-of-user-passed-options/54255)

<div class="topic-metadata">

**Author:** [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Replies:** 4\
**Last updated:** [January 30, 2021, 1:27pm UTC](https://discourse.julialang.org/t/compiling-specialized-functions-for-large-set-of-user-passed-options/54255 "2021-01-30T13:27:02Z")

</div>

Hi, I’m optimizing my package SymbolicRegression.jl, the backend for PySR, a GA-based gradient-free symbolic regression code. The normal workflow for this package is to configure the options—such as choice of operators…

---

## [Invalidating sysimages?](https://discourse.julialang.org/t/invalidating-sysimages/53922)

<div class="topic-metadata">

**Author:** [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Replies:** 7\
**Last updated:** [January 29, 2021, 9:46pm UTC](https://discourse.julialang.org/t/invalidating-sysimages/53922 "2021-01-29T21:46:09Z")

</div>

If I’m not mistaken if you use a custom sysimage and then make any changes to any of the packages included in said sysimage, then these won’t be reflected in any Julia sessions where you use that sysimage. What I’m wonde…

---

## [Overloading \`Base.getproperty\` performance](https://discourse.julialang.org/t/overloading-base-getproperty-performance/54178)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 2\
**Last updated:** [January 29, 2021, 12:23pm UTC](https://discourse.julialang.org/t/overloading-base-getproperty-performance/54178 "2021-01-29T12:23:05Z")

</div>

Inspired by this post I wanted to add extra properties to my type, but noted a significant performance hit: julia\> using BenchmarkTools julia\> struct AType{T} data::T end julia\> struct BType{T} …

---

## [When can a single-call optimization be used?](https://discourse.julialang.org/t/when-can-a-single-call-optimization-be-used/54089)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 3\
**Last updated:** [January 28, 2021, 12:35am UTC](https://discourse.julialang.org/t/when-can-a-single-call-optimization-be-used/54089 "2021-01-28T00:35:46Z")

</div>

function func(x) sum(x) / sum(x) end xs = rand(0:.1:1, 1000) @code\_typed func(xs) julia\> @code\_typed func(xs) CodeInfo( 1 ── %1 = Base.identity::typeof(identity) │ %2 = Base.add\_sum::typeof(Base.add\_sum) │ …

---

## [Filling non-contiguous slices of an array with the real and imaginary part of another](https://discourse.julialang.org/t/filling-non-contiguous-slices-of-an-array-with-the-real-and-imaginary-part-of-another/54033)

<div class="topic-metadata">

**Author:** [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Replies:** 3\
**Last updated:** [January 27, 2021, 5:07pm UTC](https://discourse.julialang.org/t/filling-non-contiguous-slices-of-an-array-with-the-real-and-imaginary-part-of-another/54033 "2021-01-27T17:07:53Z")

</div>

Hello, I would like to get your feedback on the fastest way to fill the 1 modulo 3 entries with the real part of an array and the 2 modul0 3 entries with the imaginary part of the same array. using BenchmarkTools A = r…

---

## [Does eigen( ) get stuck in processing of the results?](https://discourse.julialang.org/t/does-eigen-get-stuck-in-processing-of-the-results/53917)

<div class="topic-metadata">

**Author:** [@Erik](https://discourse.julialang.org/u/Erik)\
**Replies:** 10\
**Last updated:** [January 27, 2021, 3:56pm UTC](https://discourse.julialang.org/t/does-eigen-get-stuck-in-processing-of-the-results/53917 "2021-01-27T15:56:16Z")

</div>

I wrote the below code (originally in MATLAB, ported to Julia). Unfortunately, the code runs at pretty much the same speed as the MATLAB original. using LinearAlgebra using StaticArrays using DelimitedFiles using Benchm…

---

## [Creating a matrix as Symmetric causes excessive allocations in multithreaded loop](https://discourse.julialang.org/t/creating-a-matrix-as-symmetric-causes-excessive-allocations-in-multithreaded-loop/54059)

<div class="topic-metadata">

**Author:** [@pedrohnv](https://discourse.julialang.org/u/pedrohnv)\
**Replies:** 2\
**Last updated:** [January 27, 2021, 3:36pm UTC](https://discourse.julialang.org/t/creating-a-matrix-as-symmetric-causes-excessive-allocations-in-multithreaded-loop/54059 "2021-01-27T15:36:37Z")

</div>

In the following code snippet, I use a symmetric matrix to calculate another. If I assign the matrix as Symmetric, it leads to excessive allocations if the loop is multi-threaded. using BenchmarkTools function foo() …

---

## [Sum(log.(p \* C)) is 2 to 4 times slower than in NumPy](https://discourse.julialang.org/t/sum-log-p-c-is-2-to-4-times-slower-than-in-numpy/53960)

<div class="topic-metadata">

**Author:** [@ForceBru](https://discourse.julialang.org/u/ForceBru)\
**Replies:** 19\
**Last updated:** [January 26, 2021, 11:39pm UTC](https://discourse.julialang.org/t/sum-log-p-c-is-2-to-4-times-slower-than-in-numpy/53960 "2021-01-26T23:39:03Z")

</div>

I’m coming from Python and trying to port my Python code to Julia to gain more performance. I want to compute a lot of log-likelihoods in a loop, so I need a fast function that computes the log-likelihood. The computati…

---

## [Performance issue with QRCompactWYQ](https://discourse.julialang.org/t/performance-issue-with-qrcompactwyq/53732)

<div class="topic-metadata">

**Author:** [@theogf](https://discourse.julialang.org/u/theogf)\
**Replies:** 1\
**Last updated:** [January 26, 2021, 8:46am UTC](https://discourse.julialang.org/t/performance-issue-with-qrcompactwyq/53732 "2021-01-26T08:46:19Z")

</div>

Hey, since it’s not a bug specifically but a performance issue I post it here instead on Github. In the attempt of generating random positive definite matrices I realized there was a huge performance issue with the QRCo…

---

## [Hashing for big structs is slow - any alternative?](https://discourse.julialang.org/t/hashing-for-big-structs-is-slow-any-alternative/53815)

<div class="topic-metadata">

**Author:** [@bsuwal](https://discourse.julialang.org/u/bsuwal)\
**Replies:** 12\
**Last updated:** [January 25, 2021, 7:36pm UTC](https://discourse.julialang.org/t/hashing-for-big-structs-is-slow-any-alternative/53815 "2021-01-25T19:36:06Z")

</div>

I have three structs, one mutable and two immutable, defined as: mutable struct Node label::NodeEdge comp::Vector{UInt8} comp\_weights::Vector{UInt8} cc::UInt8 fps::Vector{F…

---

## [How to avoid ForwardDiff.jl generating a second-order derivative that wastes flops by eventually multiplying by zero](https://discourse.julialang.org/t/how-to-avoid-forwarddiff-jl-generating-a-second-order-derivative-that-wastes-flops-by-eventually-multiplying-by-zero/53845)

<div class="topic-metadata">

**Author:** [@schneiderfelipe](https://discourse.julialang.org/u/schneiderfelipe)\
**Replies:** 10\
**Last updated:** [January 25, 2021, 2:28am UTC](https://discourse.julialang.org/t/how-to-avoid-forwarddiff-jl-generating-a-second-order-derivative-that-wastes-flops-by-eventually-multiplying-by-zero/53845 "2021-01-25T02:28:23Z")

</div>

I played around with second derivatives and ForwardDiff.jl and found something unexpected, so I would like to ask about it. Basically, the generated LLVM representation is multiplying a whole code branch by zero before r…

---

## [Very slow loop](https://discourse.julialang.org/t/very-slow-loop/53608)

<div class="topic-metadata">

**Author:** [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Replies:** 33\
**Last updated:** [January 24, 2021, 7:26pm UTC](https://discourse.julialang.org/t/very-slow-loop/53608 "2021-01-24T19:26:26Z")

</div>

Hi all, I am trying to speed up this loop. I am providing a MWE and I wanted to know if any of you could spot any obvious performance improvementes. using LinearAlgebra, Statistics, Random C=rand(\[0,1\],120,13,8000) D…

---

## [Why is broadcast faster than the dot syntax? (Performance differences between @., ., broadcast and broadcast!)](https://discourse.julialang.org/t/why-is-broadcast-faster-than-the-dot-syntax-performance-differences-between-broadcast-and-broadcast/53814)

<div class="topic-metadata">

**Author:** [@schneiderfelipe](https://discourse.julialang.org/u/schneiderfelipe)\
**Replies:** 5\
**Last updated:** [January 23, 2021, 11:08am UTC](https://discourse.julialang.org/t/why-is-broadcast-faster-than-the-dot-syntax-performance-differences-between-broadcast-and-broadcast/53814 "2021-01-23T11:08:14Z")

</div>

From the manual, I expected both cases below to perform equally well, but that seems not to be the case: julia\> using BenchmarkTools julia\> a = \[2, 3, 4, 5\]; julia\> b = \[6 7 8 9\]; julia\> @benchmark a .+ b BenchmarkTo…

---

## [Is varinfo() designed to not report size of an array of sparse matrices?](https://discourse.julialang.org/t/is-varinfo-designed-to-not-report-size-of-an-array-of-sparse-matrices/53786)

<div class="topic-metadata">

**Author:** [@brownlight](https://discourse.julialang.org/u/brownlight)\
**Replies:** 2\
**Last updated:** [January 22, 2021, 4:05pm UTC](https://discourse.julialang.org/t/is-varinfo-designed-to-not-report-size-of-an-array-of-sparse-matrices/53786 "2021-01-22T16:05:13Z")

</div>

Memory usage shoots up after computing two variable/references, D & Rj\_mats. For these two, varinfo() reports: D 6.000 MiB 262144×262144 SparseMatrixCSC{Int64,Int64} Rj\_mats 10.039 KiB 256-element Array{SparseMatrixCSC{…

---

## [Julia and C or just standalone C++](https://discourse.julialang.org/t/julia-and-c-or-just-standalone-c/53774)

<div class="topic-metadata">

**Author:** [@anbtta](https://discourse.julialang.org/u/anbtta)\
**Replies:** 6\
**Last updated:** [January 22, 2021, 3:07pm UTC](https://discourse.julialang.org/t/julia-and-c-or-just-standalone-c/53774 "2021-01-22T15:07:44Z")

</div>

Hello, I was wondering if in production the pair Julia and C was a better option to C++ only. In terms of performance, and for code management in a large scale project. Thank you.

---

## [I cannot get close to full speed up in parallel](https://discourse.julialang.org/t/i-cannot-get-close-to-full-speed-up-in-parallel/53751)

<div class="topic-metadata">

**Author:** [@Noel\_Araujo](https://discourse.julialang.org/u/Noel_Araujo)\
**Replies:** 4\
**Last updated:** [January 22, 2021, 3:37am UTC](https://discourse.julialang.org/t/i-cannot-get-close-to-full-speed-up-in-parallel/53751 "2021-01-22T03:37:29Z")

</div>

I have a code that is embarrassingly parallel, but I cannot get full its speed up. The dummy code is here: function points\_on\_sphere\_surface(num\_pts=100, R=2) indices = 1:num\_pts .+ 0.5 ϕ = acos.(1 .- 2\*indic…

---

## [Help with increasing performance of specific function](https://discourse.julialang.org/t/help-with-increasing-performance-of-specific-function/53737)

<div class="topic-metadata">

**Author:** [@claudio20497](https://discourse.julialang.org/u/claudio20497)\
**Replies:** 8\
**Last updated:** [January 21, 2021, 10:44pm UTC](https://discourse.julialang.org/t/help-with-increasing-performance-of-specific-function/53737 "2021-01-21T22:44:39Z")

</div>

Hello, I’m trying to translate in Julia the doubleCenter function from this article. The function takes a matrix as an argument, and doubly centers it, meaning that it subtracts to each element the mean of its row and t…

---

## [Iteration/getindex performance of AbstractArray wrapper-types](https://discourse.julialang.org/t/iteration-getindex-performance-of-abstractarray-wrapper-types/53729)

<div class="topic-metadata">

**Author:** [@tchr](https://discourse.julialang.org/u/tchr)\
**Replies:** 2\
**Last updated:** [January 21, 2021, 7:07pm UTC](https://discourse.julialang.org/t/iteration-getindex-performance-of-abstractarray-wrapper-types/53729 "2021-01-21T19:07:03Z")

</div>

I hit what I think is a surprising performance-snag for custom array-wrapper types that subtype AbstractArray. The issue is best illustrated by example: suppose I define a thin wrapper over a vector, like so: import Ba…

---

## [Why does my program's performance vary so much from run to run? Can it be fixed?](https://discourse.julialang.org/t/why-does-my-programs-performance-vary-so-much-from-run-to-run-can-it-be-fixed/53678)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 11\
**Last updated:** [January 20, 2021, 11:02pm UTC](https://discourse.julialang.org/t/why-does-my-programs-performance-vary-so-much-from-run-to-run-can-it-be-fixed/53678 "2021-01-20T23:02:01Z")

</div>

While I was looking into optimizing my pure Julia program, I noticed something very unpleasant: its run time varies a great deal between some runs even though its input and code stay the same, and even though the system …

---

## [Solving ode takes too long compared to python](https://discourse.julialang.org/t/solving-ode-takes-too-long-compared-to-python/53719)

<div class="topic-metadata">

**Author:** [@arif](https://discourse.julialang.org/u/arif)\
**Replies:** 7\
**Last updated:** [January 21, 2021, 1:08pm UTC](https://discourse.julialang.org/t/solving-ode-takes-too-long-compared-to-python/53719 "2021-01-21T13:08:04Z")

</div>

Hi, I have tried Julia on and off for the last 5 years. Recently I thought of using Julia exclusively for a course on Astrophysics and my first task was to solve a set of four ordinary differential equations. I am using …

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

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