# Performance

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

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

**Page:** 141

---

## [The cost of size() in for-loops](https://discourse.julialang.org/t/the-cost-of-size-in-for-loops/12491)

<div class="topic-metadata">

**Author:** [@ckoe-bccms](https://discourse.julialang.org/u/ckoe-bccms)\
**Replies:** 11\
**Last updated:** [July 20, 2018, 8:28am UTC](https://discourse.julialang.org/t/the-cost-of-size-in-for-loops/12491 "2018-07-20T08:28:58Z")

</div>

Hello everybody, I have a performance question which I hope has not been asked to death before. I will provide a minimal working example below. First, let me give some context. The type of code shown below gets called …

---

## [Save memory of a translational symmetric matrix](https://discourse.julialang.org/t/save-memory-of-a-translational-symmetric-matrix/12433)

<div class="topic-metadata">

**Author:** [@shipengcheng1230](https://discourse.julialang.org/u/shipengcheng1230)\
**Replies:** 4\
**Last updated:** [July 20, 2018, 4:57am UTC](https://discourse.julialang.org/t/save-memory-of-a-translational-symmetric-matrix/12433 "2018-07-20T04:57:36Z")

</div>

I have a mult-dimension matrix (or perhaps tensor more appropriately), for example: a = rand(5, 5, 5, 5). It satisfies translational symmetry, i.e. a\[i, j, k, l\] = a\[i - k, j, l\]. In such case, how could I save the mem…

---

## [When is it safe to use Base.OneTo?](https://discourse.julialang.org/t/when-is-it-safe-to-use-base-oneto/12512)

<div class="topic-metadata">

**Author:** [@favba](https://discourse.julialang.org/u/favba)\
**Replies:** 0\
**Last updated:** [July 19, 2018, 8:45pm UTC](https://discourse.julialang.org/t/when-is-it-safe-to-use-base-oneto/12512 "2018-07-19T20:45:46Z")

</div>

Since Base.OneTo is not exported I am suspicious that there might be some gotchas with it. I implemented a padded array interface to perform in-place r2c and c2r fft transformations. For that I have to create views tha…

---

## [Type stability and array of matrices](https://discourse.julialang.org/t/type-stability-and-array-of-matrices/12483)

<div class="topic-metadata">

**Author:** [@jarl](https://discourse.julialang.org/u/jarl)\
**Replies:** 5\
**Last updated:** [July 19, 2018, 9:45am UTC](https://discourse.julialang.org/t/type-stability-and-array-of-matrices/12483 "2018-07-19T09:45:53Z")

</div>

I am having some trouble getting a deeper understanding of inference / type stability. I have a struct with an array of matrices and a function. I want to extract something from a matrix in the array, say the size of the…

---

## [Allocations in construction of composite type with StaticArray field](https://discourse.julialang.org/t/allocations-in-construction-of-composite-type-with-staticarray-field/12461)

<div class="topic-metadata">

**Author:** [@vlc](https://discourse.julialang.org/u/vlc)\
**Replies:** 2\
**Last updated:** [July 18, 2018, 2:13pm UTC](https://discourse.julialang.org/t/allocations-in-construction-of-composite-type-with-staticarray-field/12461 "2018-07-18T14:13:40Z")

</div>

Hello, I’m tracking down allocations in a performance critical part of a code, where I use composite types with StaticArrays fields. I’ve noticed that initializing instances of such types triggers some allocations that …

---

## [Performance regression with indexing a \`reinterpret\`ed array in v0.7](https://discourse.julialang.org/t/performance-regression-with-indexing-a-reinterpret-ed-array-in-v0-7/12443)

<div class="topic-metadata">

**Author:** [@gasagna](https://discourse.julialang.org/u/gasagna)\
**Replies:** 2\
**Last updated:** [July 17, 2018, 9:37pm UTC](https://discourse.julialang.org/t/performance-regression-with-indexing-a-reinterpret-ed-array-in-v0-7/12443 "2018-07-17T21:37:35Z")

</div>

Hi, while updating a package of mine I stumbled into what I think is a regression associated to indexing a reinterpreted array. Basically I have a custom array-like type as struct MyArray{T\<:Real, V1\<:AbstractArray{Com…

---

## [Binary data reader 200x+ slower on 0.7 ](https://discourse.julialang.org/t/binary-data-reader-200x-slower-on-0-7/12424)

<div class="topic-metadata">

**Author:** [@mgcth](https://discourse.julialang.org/u/mgcth)\
**Replies:** 8\
**Last updated:** [July 17, 2018, 11:04am UTC](https://discourse.julialang.org/t/binary-data-reader-200x-slower-on-0-7/12424 "2018-07-17T11:04:06Z")

</div>

I read binary data into a sparse matrix. Basically I populate a row and data vector with append! and put them into a sparse matrix using SparseMatrixCSC. It was very fast on 0.6, but is 200x+ slower on 0.7. I haven’t cha…

---

## [@inbounds: is the compiler now so smart that this is no longer necessary?](https://discourse.julialang.org/t/inbounds-is-the-compiler-now-so-smart-that-this-is-no-longer-necessary/12357)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 33\
**Last updated:** [July 16, 2018, 2:49pm UTC](https://discourse.julialang.org/t/inbounds-is-the-compiler-now-so-smart-that-this-is-no-longer-necessary/12357 "2018-07-16T14:49:55Z")

</div>

In tests of FinEtools, the code with ALL @inbounds removed is faster than with.

---

## [Generate functions inside a function from string](https://discourse.julialang.org/t/generate-functions-inside-a-function-from-string/12331)

<div class="topic-metadata">

**Author:** [@wuhuagumu](https://discourse.julialang.org/u/wuhuagumu)\
**Replies:** 35\
**Last updated:** [July 13, 2018, 4:48pm UTC](https://discourse.julialang.org/t/generate-functions-inside-a-function-from-string/12331 "2018-07-13T16:48:59Z")

</div>

Hi, I noticed that the function generated by eval is always a global function, making the code silly if I would like to generate some function defined in string. Are there any other ways to do something like this while …

---

## [Default sin / cos functions do not scale on multithreading](https://discourse.julialang.org/t/default-sin-cos-functions-do-not-scale-on-multithreading/12313)

<div class="topic-metadata">

**Author:** [@DavidBerghaus](https://discourse.julialang.org/u/DavidBerghaus)\
**Replies:** 19\
**Last updated:** [July 13, 2018, 11:16am UTC](https://discourse.julialang.org/t/default-sin-cos-functions-do-not-scale-on-multithreading/12313 "2018-07-13T11:16:54Z")

</div>

I previously created a post where I described issues of my algorithm running on multi threading. I think I finally found the issue: I am using the default sin / cos functions and this post: https://github.com/JuliaLan…

---

## [Poor performance on cluster multithreading](https://discourse.julialang.org/t/poor-performance-on-cluster-multithreading/12248)

<div class="topic-metadata">

**Author:** [@DavidBerghaus](https://discourse.julialang.org/u/DavidBerghaus)\
**Replies:** 40\
**Last updated:** [July 11, 2018, 2:18pm UTC](https://discourse.julialang.org/t/poor-performance-on-cluster-multithreading/12248 "2018-07-11T14:18:36Z")

</div>

I am currently running Julia on a computing cluster with 56 threads. To test the multithreading capacity, I am generating random numbers: function test() tic() Threads.@threads for i=1:100000 rand(1000000) end toc…

---

## [Slowdown of Distributions.jl on 0.7?](https://discourse.julialang.org/t/slowdown-of-distributions-jl-on-0-7/12243)

<div class="topic-metadata">

**Author:** [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Replies:** 7\
**Last updated:** [July 9, 2018, 2:30pm UTC](https://discourse.julialang.org/t/slowdown-of-distributions-jl-on-0-7/12243 "2018-07-09T14:30:52Z")

</div>

I’m seeing a big slowdown in some code that uses Distributions.jl on 0.7 (built from master this morning), compared to 0.6.3. A MWE is using Distributions function main() a = zeros(100) y = rand(30) for i …

---

## [Getting data directly from a website](https://discourse.julialang.org/t/getting-data-directly-from-a-website/12241)

<div class="topic-metadata">

**Author:** [@mvcavalcanti](https://discourse.julialang.org/u/mvcavalcanti)\
**Replies:** 9\
**Last updated:** [July 9, 2018, 12:09am UTC](https://discourse.julialang.org/t/getting-data-directly-from-a-website/12241 "2018-07-09T00:09:04Z")

</div>

Hi. I’m working on a script in which I do some analysis about energy prices. The first step to process these values is to get them. They are available on a public web site, through a table of five columns with historical…

---

## [optimising for loop performance](https://discourse.julialang.org/t/optimising-for-loop-performance/12230)

<div class="topic-metadata">

**Author:** [@learnjulia](https://discourse.julialang.org/u/learnjulia)\
**Replies:** 14\
**Last updated:** [July 8, 2018, 3:24am UTC](https://discourse.julialang.org/t/optimising-for-loop-performance/12230 "2018-07-08T03:24:42Z")

</div>

The following code (molecular dynamics simulation) was ported more or less directly from Fortran, but being new to Julia programming the performance isn’t as good. I followed the performance tips as much as I could, but …

---

## [How to change date format and keep the type of variable?](https://discourse.julialang.org/t/how-to-change-date-format-and-keep-the-type-of-variable/12194)

<div class="topic-metadata">

**Author:** [@mvcavalcanti](https://discourse.julialang.org/u/mvcavalcanti)\
**Replies:** 6\
**Last updated:** [July 8, 2018, 2:31am UTC](https://discourse.julialang.org/t/how-to-change-date-format-and-keep-the-type-of-variable/12194 "2018-07-08T02:31:43Z")

</div>

Hi. I have an array of dates that I want to use on a xaxis of a plot. These dates I need to present as an abbreviated month/ abbreviated year way (For example: “Jan-18”, “Feb-18”, and so on). The problem shows up when I…

---

## [Optimising function with const instead of struct?](https://discourse.julialang.org/t/optimising-function-with-const-instead-of-struct/12233)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 9\
**Last updated:** [July 7, 2018, 10:44am UTC](https://discourse.julialang.org/t/optimising-function-with-const-instead-of-struct/12233 "2018-07-07T10:44:12Z")

</div>

Hi, I have a function that I used for modelling purposes (kinda using an ODE). Hence, I defined a mutable struct to encapsulate all parameters. I thought the compiler would optimised out the values of the const inside t…

---

## [How to set gap between multiple scatter plot - Plotly](https://discourse.julialang.org/t/how-to-set-gap-between-multiple-scatter-plot-plotly/12145)

<div class="topic-metadata">

**Author:** [@mvcavalcanti](https://discourse.julialang.org/u/mvcavalcanti)\
**Replies:** 2\
**Last updated:** [July 5, 2018, 8:30pm UTC](https://discourse.julialang.org/t/how-to-set-gap-between-multiple-scatter-plot-plotly/12145 "2018-07-05T20:30:18Z")

</div>

Hi. I’d like to compare values of two different cases through scatter plots and basically this is what I have now: As you can see, each correspondent variable of my cases are above the another. What I would like to …

---

## [Why isn't pmap faster than map in this example?](https://discourse.julialang.org/t/why-isnt-pmap-faster-than-map-in-this-example/12091)

<div class="topic-metadata">

**Author:** [@matthieu](https://discourse.julialang.org/u/matthieu)\
**Replies:** 8\
**Last updated:** [July 1, 2018, 7:36pm UTC](https://discourse.julialang.org/t/why-isnt-pmap-faster-than-map-in-this-example/12091 "2018-07-01T19:36:51Z")

</div>

I have a function that computes the mean of each column of a matrix 100 times. However, the serial version is as fast as the parallel version on my machine (3.5 GHz Intel Core i5 with 4 cores) addprocs(3) @everywhere fu…

---

## [Question about Multi-threading Performance](https://discourse.julialang.org/t/question-about-multi-threading-performance/12075)

<div class="topic-metadata">

**Author:** [@Juser](https://discourse.julialang.org/u/Juser)\
**Replies:** 3\
**Last updated:** [June 30, 2018, 2:45pm UTC](https://discourse.julialang.org/t/question-about-multi-threading-performance/12075 "2018-06-30T14:45:01Z")

</div>

I was testing out some simple multithreaded code and noticed that in some instances the multithreaded version performs much more poorly than the single-threaded version. I’ve posted a minimum working example below. Does …

---

## [Looping over different types with common behavior](https://discourse.julialang.org/t/looping-over-different-types-with-common-behavior/12068)

<div class="topic-metadata">

**Author:** [@IssamT](https://discourse.julialang.org/u/IssamT)\
**Replies:** 9\
**Last updated:** [June 30, 2018, 4:14pm UTC](https://discourse.julialang.org/t/looping-over-different-types-with-common-behavior/12068 "2018-06-30T16:14:28Z")

</div>

I consider two methods presented in the example below. As expected, the second one is better since it uses only concrete types. ABSTRACT COLLECTION 34.190 ms (999490 allocations: 15.25 MiB) CONCRETE COLLECTION 1.307…

---

## [Parallel computing on a subset of an array](https://discourse.julialang.org/t/parallel-computing-on-a-subset-of-an-array/11881)

<div class="topic-metadata">

**Author:** [@Balinus](https://discourse.julialang.org/u/Balinus)\
**Replies:** 12\
**Last updated:** [June 29, 2018, 12:50pm UTC](https://discourse.julialang.org/t/parallel-computing-on-a-subset-of-an-array/11881 "2018-06-29T12:50:15Z")

</div>

Hello! I’m trying to do some parallel computation on the 2 first dimensions of a 3D array A\[j,k, t\]. To put things in context, the data are timeseries, where j and k are spatial grid points and t is the time dimension. …

---

## [Performance discrepancy in sparse matrix product](https://discourse.julialang.org/t/performance-discrepancy-in-sparse-matrix-product/12048)

<div class="topic-metadata">

**Author:** [@Sean\_McBane](https://discourse.julialang.org/u/Sean_McBane)\
**Replies:** 4\
**Last updated:** [June 29, 2018, 9:37am UTC](https://discourse.julialang.org/t/performance-discrepancy-in-sparse-matrix-product/12048 "2018-06-29T09:37:26Z")

</div>

Hi all, I noticed the following performance discrepancy: julia\> using BenchmarkTools julia\> const A = sprand(500, 500, 0.01); julia\> const B = sprand(500, 500, 0.01); julia\> const C = full(A\*B); julia\> @benchmark A\*…

---

## [Saving values from GPU during Euler stepping in ODE](https://discourse.julialang.org/t/saving-values-from-gpu-during-euler-stepping-in-ode/7406)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 23\
**Last updated:** [June 27, 2018, 4:53pm UTC](https://discourse.julialang.org/t/saving-values-from-gpu-during-euler-stepping-in-ode/7406 "2018-06-27T16:53:40Z")

</div>

Dear all, I have written a simple Euler stepping algorithm for a particular problem which runs on GPU. The vector y\_current is big (~200\_000) and it is updated like y\_current .= y\_current .+ dt \* RHS. A working example…

---

## [dot syntax in pyjulia](https://discourse.julialang.org/t/dot-syntax-in-pyjulia/11974)

<div class="topic-metadata">

**Author:** [@atombear](https://discourse.julialang.org/u/atombear)\
**Replies:** 4\
**Last updated:** [June 26, 2018, 6:45pm UTC](https://discourse.julialang.org/t/dot-syntax-in-pyjulia/11974 "2018-06-26T18:45:39Z")

</div>

Hello, I have a question about using dot syntax in python. In trying to write a broadcast-able function in julia that I can call from python, i have found it convenient to do the following: export func function func(x:…

---

## [This should be documented in performance tips if not a temporary bug](https://discourse.julialang.org/t/this-should-be-documented-in-performance-tips-if-not-a-temporary-bug/11894)

<div class="topic-metadata">

**Author:** [@Jean\_Michel](https://discourse.julialang.org/u/Jean_Michel)\
**Replies:** 19\
**Last updated:** [June 26, 2018, 4:42pm UTC](https://discourse.julialang.org/t/this-should-be-documented-in-performance-tips-if-not-a-temporary-bug/11894 "2018-06-26T16:42:38Z")

</div>

Here is a drastically simplified and self-contained fragment of code dealing with permutation groups. The point of my post is that without the line let s=s, i=i, e=i^s the compiler cannot infer the type of either s, i or…

---

## [@fastmath switched off in Julia 0.7-Dev, deliberately?](https://discourse.julialang.org/t/fastmath-switched-off-in-julia-0-7-dev-deliberately/11898)

<div class="topic-metadata">

**Author:** [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Replies:** 7\
**Last updated:** [June 24, 2018, 9:41am UTC](https://discourse.julialang.org/t/fastmath-switched-off-in-julia-0-7-dev-deliberately/11898 "2018-06-24T09:41:03Z")

</div>

I noticed that the @fastmath macro is no longer effective in version 0.7-Dev. Has it been switched off deliberately, or something wrong with my installation is preventing it from taking off? I tested on both Windows 10 a…

---

## [Findmax on ranges](https://discourse.julialang.org/t/findmax-on-ranges/11870)

<div class="topic-metadata">

**Author:** [@DNF](https://discourse.julialang.org/u/DNF)\
**Replies:** 3\
**Last updated:** [June 22, 2018, 3:28pm UTC](https://discourse.julialang.org/t/findmax-on-ranges/11870 "2018-06-22T15:28:45Z")

</div>

This had me surprised: julia\> @btime findmax($(2:10^9)) 1.191 s (0 allocations: 0 bytes) (1000000000, 999999999) julia\> @btime maximum($(2:10^9)) 4.441 ns (0 allocations: 0 bytes) 1000000000 Apparently, findmax / a…

---

## [Type instability with SubArray on custom Array type](https://discourse.julialang.org/t/type-instability-with-subarray-on-custom-array-type/11775)

<div class="topic-metadata">

**Author:** [@jinliangwei](https://discourse.julialang.org/u/jinliangwei)\
**Replies:** 2\
**Last updated:** [June 20, 2018, 5:44pm UTC](https://discourse.julialang.org/t/type-instability-with-subarray-on-custom-array-type/11775 "2018-06-20T17:44:16Z")

</div>

I have a program that requires me to use my own array type. However, my own array definition seems to cause a type instability problem, leaving lots of performance on the table (potentially 2~3x improvements). The issue…

---

## [Why is changing type of variable problematic?](https://discourse.julialang.org/t/why-is-changing-type-of-variable-problematic/11722)

<div class="topic-metadata">

**Author:** [@nickeubank](https://discourse.julialang.org/u/nickeubank)\
**Replies:** 19\
**Last updated:** [June 18, 2018, 2:06pm UTC](https://discourse.julialang.org/t/why-is-changing-type-of-variable-problematic/11722 "2018-06-18T14:06:03Z")

</div>

I was wondering if anyone could explain why changing the type of a variable is problematic in Julia. I (think) I understand the reason type-instabilities are a problem when they arise conditional on the value (rather th…

---

## [Potential small inefficiency in \`triu!\` and \`tril!\`?](https://discourse.julialang.org/t/potential-small-inefficiency-in-triu-and-tril/11725)

<div class="topic-metadata">

**Author:** [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Replies:** 0\
**Last updated:** [June 16, 2018, 9:20pm UTC](https://discourse.julialang.org/t/potential-small-inefficiency-in-triu-and-tril/11725 "2018-06-16T21:20:58Z")

</div>

The definition of triu! in dense.jl of LinearAlgebra is copy-pasted below. Observing line 181, we see that zero(M\[i\]) is calculated at each iteration of the inner loop. Obviously, this can be moved out of the loop and re…

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

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