# Performance

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

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

**Page:** 116

---

## [Is it possible to force use Int32, instead of Int64](https://discourse.julialang.org/t/is-it-possible-to-force-use-int32-instead-of-int64/41179)

<div class="topic-metadata">

**Author:** [@BMval](https://discourse.julialang.org/u/BMval)\
**Replies:** 14\
**Last updated:** [June 11, 2020, 1:34pm UTC](https://discourse.julialang.org/t/is-it-possible-to-force-use-int32-instead-of-int64/41179 "2020-06-11T13:34:56Z")

</div>

Is there any command, that will force to use Int32 instead of Int64?

---

## [Using a DataFrame to calculate another column in a separate DataFrame](https://discourse.julialang.org/t/using-a-dataframe-to-calculate-another-column-in-a-separate-dataframe/40747)

<div class="topic-metadata">

**Author:** [@Derek\_Vetsch](https://discourse.julialang.org/u/Derek_Vetsch)\
**Replies:** 6\
**Last updated:** [June 10, 2020, 6:36pm UTC](https://discourse.julialang.org/t/using-a-dataframe-to-calculate-another-column-in-a-separate-dataframe/40747 "2020-06-10T18:36:00Z")

</div>

I am using a DataFrame invoices that looks like this: to count the number of invoices for a given contract on a given date that have happened. The functions I’m using to do this are: using DataFrames, DataFramesMeta,…

---

## [Why \`mean\` with \`dims\` argument is so slow?](https://discourse.julialang.org/t/why-mean-with-dims-argument-is-so-slow/41105)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 4\
**Last updated:** [June 10, 2020, 12:15pm UTC](https://discourse.julialang.org/t/why-mean-with-dims-argument-is-so-slow/41105 "2020-06-10T12:15:16Z")

</div>

Consider: using BenchmarkTools, Statistics A = randn(4,3,2); @btime mean($A; dims=1); # 90.184 ns (1 allocation: 128 bytes) @btime mean($A); # 9.891 ns (0 allocations: 0 bytes) That’s a 10x factor difference! Is ther…

---

## [Can't figure out why dynamic dispatch is occuring](https://discourse.julialang.org/t/cant-figure-out-why-dynamic-dispatch-is-occuring/41089)

<div class="topic-metadata">

**Author:** [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Replies:** 6\
**Last updated:** [June 9, 2020, 7:34pm UTC](https://discourse.julialang.org/t/cant-figure-out-why-dynamic-dispatch-is-occuring/41089 "2020-06-09T19:34:42Z")

</div>

I’m trying to figure out why the profiler and @code\_warntype are picking up dynamic dispatch in the following MWE. The basic function applies matrix multiplications to each column of a matrix array and accumulates the re…

---

## [Improving a Program Implementing findall Function](https://discourse.julialang.org/t/improving-a-program-implementing-findall-function/40938)

<div class="topic-metadata">

**Author:** [@johnrickmanz](https://discourse.julialang.org/u/johnrickmanz)\
**Replies:** 1\
**Last updated:** [June 7, 2020, 6:29pm UTC](https://discourse.julialang.org/t/improving-a-program-implementing-findall-function/40938 "2020-06-07T18:29:00Z")

</div>

I recently seen topics here that says the findall function is quite slow and I think so too most likely if I am dealing with large number of elements say hundreds of thousands or more. An example of what I want is as fol…

---

## [Parallel reductions on CPUs with different speeds](https://discourse.julialang.org/t/parallel-reductions-on-cpus-with-different-speeds/40722)

<div class="topic-metadata">

**Author:** [@hcarlsso](https://discourse.julialang.org/u/hcarlsso)\
**Replies:** 6\
**Last updated:** [June 5, 2020, 1:34pm UTC](https://discourse.julialang.org/t/parallel-reductions-on-cpus-with-different-speeds/40722 "2020-06-05T13:34:02Z")

</div>

I am looking for how to “load balance” parallel reduction on multiple CPUs that have different speeds. The following snippet illustrates the problem: using Distributed addprocs(3) res = @time @distributed (+) for (t, n…

---

## [Best performance using dictionaries, functions and modules](https://discourse.julialang.org/t/best-performance-using-dictionaries-functions-and-modules/40673)

<div class="topic-metadata">

**Author:** [@Joey](https://discourse.julialang.org/u/Joey)\
**Replies:** 8\
**Last updated:** [June 5, 2020, 3:39am UTC](https://discourse.julialang.org/t/best-performance-using-dictionaries-functions-and-modules/40673 "2020-06-05T03:39:20Z")

</div>

Hi everyone, I’m currently working on a program and need some help for better performance. As I switched from MATLAB to Julia, I don’t know if I am writting in a good way. I tried to write it similarly to MATLAB’s fashi…

---

## [10x slowdown when passing function as argument](https://discourse.julialang.org/t/10x-slowdown-when-passing-function-as-argument/40382)

<div class="topic-metadata">

**Author:** [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Replies:** 15\
**Last updated:** [June 4, 2020, 6:04pm UTC](https://discourse.julialang.org/t/10x-slowdown-when-passing-function-as-argument/40382 "2020-06-04T18:04:41Z")

</div>

I’m trying to understand why passing a function as an argument is sometimes 10x slower than inheriting it via closure. Here’s a contrived MWE: function outer1(f) out = zeros(1000) for i = 1:1000 function…

---

## [Efficient merging of large dictionaries](https://discourse.julialang.org/t/efficient-merging-of-large-dictionaries/40687)

<div class="topic-metadata">

**Author:** [@racinmat](https://discourse.julialang.org/u/racinmat)\
**Replies:** 4\
**Last updated:** [June 4, 2020, 10:39am UTC](https://discourse.julialang.org/t/efficient-merging-of-large-dictionaries/40687 "2020-06-04T10:39:03Z")

</div>

Hi, I have few (tens, max. hundreds) Dict{String, Int} dictionaries which I want to merge together using merge(+, dicts…). The dictionaries are fairly large (up to 100k keys), and have lots of common keys. It’s working…

---

## [Coverage test is extremely slow on multiple threads](https://discourse.julialang.org/t/coverage-test-is-extremely-slow-on-multiple-threads/40682)

<div class="topic-metadata">

**Author:** [@erik-f](https://discourse.julialang.org/u/erik-f)\
**Replies:** 6\
**Last updated:** [June 4, 2020, 9:36am UTC](https://discourse.julialang.org/t/coverage-test-is-extremely-slow-on-multiple-threads/40682 "2020-06-04T09:36:43Z")

</div>

Running Pkg.test("MyModule", coverage=true) on more than one thread is extremely slow. I measured the time on my machine using 1, 2, 8 and 16 threads: 1 thread: 339 seconds 2 threads: 3106 seconds 8 threads: 6401 sec…

---

## [Performance issues - Comparison with Matlab](https://discourse.julialang.org/t/performance-issues-comparison-with-matlab/40592)

<div class="topic-metadata">

**Author:** [@axsano](https://discourse.julialang.org/u/axsano)\
**Replies:** 6\
**Last updated:** [June 2, 2020, 1:08pm UTC](https://discourse.julialang.org/t/performance-issues-comparison-with-matlab/40592 "2020-06-02T13:08:24Z")

</div>

I have the following example of Chebyshev polynomials differentiation matrix in Julia. function cheb(N) N==0 ? (return D=0.0; x=0.0) : (D=0.0; x=0.0) x = cos.(π\*(0:N)./N) c = \[2; ones(N-1); 2\].\*(-1).^(0:N) …

---

## [Speed of vectorized vs for-loops using Zygote](https://discourse.julialang.org/t/speed-of-vectorized-vs-for-loops-using-zygote/40556)

<div class="topic-metadata">

**Author:** [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Replies:** 20\
**Last updated:** [June 1, 2020, 9:27pm UTC](https://discourse.julialang.org/t/speed-of-vectorized-vs-for-loops-using-zygote/40556 "2020-06-01T21:27:50Z")

</div>

Hey, I’m using Zygote for a minimization problem. Actually, writing down the loss function in for-loops style is a factor of ~2 faster than using a vectorized function. I then need to take the derivative. Zygote fails …

---

## [Improving Performance of For-Loop and Matrix Multiplication for Time Integration Solver](https://discourse.julialang.org/t/improving-performance-of-for-loop-and-matrix-multiplication-for-time-integration-solver/40432)

<div class="topic-metadata">

**Author:** [@PJoynt](https://discourse.julialang.org/u/PJoynt)\
**Replies:** 8\
**Last updated:** [June 1, 2020, 12:19am UTC](https://discourse.julialang.org/t/improving-performance-of-for-loop-and-matrix-multiplication-for-time-integration-solver/40432 "2020-06-01T00:19:55Z")

</div>

I am writing some code that performs a simple time-history integration solver (Newmark method for structural dynamics) and I looking for some suggestions in how I can improve the performance of my code. The below snippet…

---

## [Function control flow](https://discourse.julialang.org/t/function-control-flow/39837)

<div class="topic-metadata">

**Author:** [@Joao\_Barata](https://discourse.julialang.org/u/Joao_Barata)\
**Replies:** 22\
**Last updated:** [May 31, 2020, 2:59pm UTC](https://discourse.julialang.org/t/function-control-flow/39837 "2020-05-31T14:59:11Z")

</div>

Hello guys, I am a very recent Julia programmer coming from matlab in search of performance. Right now, I am building an economics model which involves solving different problems for different agents in different circum…

---

## [Sum over BigInt better performance without generator](https://discourse.julialang.org/t/sum-over-bigint-better-performance-without-generator/40332)

<div class="topic-metadata">

**Author:** [@bernb](https://discourse.julialang.org/u/bernb)\
**Replies:** 3\
**Last updated:** [May 31, 2020, 10:54am UTC](https://discourse.julialang.org/t/sum-over-bigint-better-performance-without-generator/40332 "2020-05-31T10:54:39Z")

</div>

I use the following script: using BenchmarkTools total\_gen(k) = sum(BigInt(2)^(n-1) for n in 1:k) total\_arr(k) = sum(\[BigInt(2)^(n-1) for n in 1:k\]) display(@benchmark total\_gen(10\_000)) display(@benchmark total\_arr(1…

---

## [Tuple or immutable struct as function argument regarding speed and optimization](https://discourse.julialang.org/t/tuple-or-immutable-struct-as-function-argument-regarding-speed-and-optimization/23088)

<div class="topic-metadata">

**Author:** [@OvidiusCicero](https://discourse.julialang.org/u/OvidiusCicero)\
**Replies:** 10\
**Last updated:** [May 29, 2020, 3:44am UTC](https://discourse.julialang.org/t/tuple-or-immutable-struct-as-function-argument-regarding-speed-and-optimization/23088 "2020-05-29T03:44:08Z")

</div>

I have a function with many named arguments that should not depend on global variables for performance reasons In the following I will call the variables a,b,c, ... ,y,z I want to replace them with an immutable struct …

---

## [Need help with performance in a very large loop](https://discourse.julialang.org/t/need-help-with-performance-in-a-very-large-loop/40292)

<div class="topic-metadata">

**Author:** [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Replies:** 28\
**Last updated:** [May 28, 2020, 10:58pm UTC](https://discourse.julialang.org/t/need-help-with-performance-in-a-very-large-loop/40292 "2020-05-28T22:58:47Z")

</div>

Hello, I hope you guys are safe and healthy in these unprecedented times. I am trying to improve the performance of a loop, in terms of both time and memory usage, that attempts to find a maximum among a number of alter…

---

## [Help me make this O(n^2) function faster?](https://discourse.julialang.org/t/help-me-make-this-o-n-2-function-faster/24326)

<div class="topic-metadata">

**Author:** [@evanfields](https://discourse.julialang.org/u/evanfields)\
**Replies:** 8\
**Last updated:** [May 27, 2020, 1:12pm UTC](https://discourse.julialang.org/t/help-me-make-this-o-n-2-function-faster/24326 "2020-05-27T13:12:30Z")

</div>

I have a collection of interval events. Each interval has a (physical) location, a start time, and a stop time. There’s also a non-negative kernel function, e.g. kernel(dist) = ifelse(dist \<= 100, 1, 0). For each interv…

---

## [Integer parametric typed struct much slower than concrete struct](https://discourse.julialang.org/t/integer-parametric-typed-struct-much-slower-than-concrete-struct/40169)

<div class="topic-metadata">

**Author:** [@Lucas\_Liu](https://discourse.julialang.org/u/Lucas_Liu)\
**Replies:** 6\
**Last updated:** [May 26, 2020, 6:48pm UTC](https://discourse.julialang.org/t/integer-parametric-typed-struct-much-slower-than-concrete-struct/40169 "2020-05-26T18:48:33Z")

</div>

Need help on performance of struct with integer parametric-types. I have the following piece of code for an AD package I am developing. PGrad is a struct for tracking gradients w.r.t N\_v variables in N\_c cells. PVa…

---

## [Inverse of symmetric Matrix does not give proper output](https://discourse.julialang.org/t/inverse-of-symmetric-matrix-does-not-give-proper-output/40173)

<div class="topic-metadata">

**Author:** [@morkip](https://discourse.julialang.org/u/morkip)\
**Replies:** 3\
**Last updated:** [May 26, 2020, 10:47am UTC](https://discourse.julialang.org/t/inverse-of-symmetric-matrix-does-not-give-proper-output/40173 "2020-05-26T10:47:00Z")

</div>

I am trying to achieve better performance in my Matrix Inversion by tagging the Matrix as ‘symmetric’. The Matrix is medium sized (200x200) Parameters and complex valued (it is indeed symmetric and not hermitian). The n…

---

## [Out of order branch execution prediction slower?](https://discourse.julialang.org/t/out-of-order-branch-execution-prediction-slower/40092)

<div class="topic-metadata">

**Author:** [@angelv](https://discourse.julialang.org/u/angelv)\
**Replies:** 17\
**Last updated:** [May 26, 2020, 7:37am UTC](https://discourse.julialang.org/t/out-of-order-branch-execution-prediction-slower/40092 "2020-05-26T07:37:23Z")

</div>

Hi, following the Parallel Computing course in JuliaAcademy I wanted to try the hardware effects of branch prediction (Serial Performance | JuliaAcademy, time about 33:00). The idea is that in the second case the data …

---

## [Why isn't 10^6 evaluated at compile time?](https://discourse.julialang.org/t/why-isnt-10-6-evaluated-at-compile-time/40124)

<div class="topic-metadata">

**Author:** [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Replies:** 21\
**Last updated:** [May 25, 2020, 11:12pm UTC](https://discourse.julialang.org/t/why-isnt-10-6-evaluated-at-compile-time/40124 "2020-05-25T23:12:29Z")

</div>

I was optimizing some code in the hot path and was surprised to see that constants written as 10^6 were being evaluated at run-time. Isn’t evaluating constants like this one of the simplest optimizations? Why wouldn’t …

---

## [The best linear solver for sparse bandedblockbandedmatricies](https://discourse.julialang.org/t/the-best-linear-solver-for-sparse-bandedblockbandedmatricies/40052)

<div class="topic-metadata">

**Author:** [@RangeFu](https://discourse.julialang.org/u/RangeFu)\
**Replies:** 30\
**Last updated:** [May 24, 2020, 9:36pm UTC](https://discourse.julialang.org/t/the-best-linear-solver-for-sparse-bandedblockbandedmatricies/40052 "2020-05-24T21:36:07Z")

</div>

Hi Community, I’m working on a program that requires solving A\\B repeatedly, where A is a sparse matrix that looks like this (it’s from finite-difference of an 2d PDE). I was wondering is there any method that can u…

---

## [Large matrix with many updates](https://discourse.julialang.org/t/large-matrix-with-many-updates/39972)

<div class="topic-metadata">

**Author:** [@alperyilmaz](https://discourse.julialang.org/u/alperyilmaz)\
**Replies:** 7\
**Last updated:** [May 23, 2020, 12:11am UTC](https://discourse.julialang.org/t/large-matrix-with-many-updates/39972 "2020-05-23T00:11:20Z")

</div>

Hi, I would like to calculate a count matrix (expected to be 65,000x65,000) and then calculate PMI and then calculate SVD on it. Unfortunately many “large matrix” samples, tutorials start with rand(n,n) where the matri…

---

## [Getproperty optimization in struct](https://discourse.julialang.org/t/getproperty-optimization-in-struct/39990)

<div class="topic-metadata">

**Author:** [@kirtsar](https://discourse.julialang.org/u/kirtsar)\
**Replies:** 1\
**Last updated:** [May 22, 2020, 8:29pm UTC](https://discourse.julialang.org/t/getproperty-optimization-in-struct/39990 "2020-05-22T20:29:00Z")

</div>

I have the following code (example): struct Foo{N} t :: NTuple{N, Int} end foo = Foo((1,2,3)) Now if I try to get access to t field, I have some unnecessary allocations: using BenchmarkTools @benchmark getpropert…

---

## [Performance difference in Colab and Jupyter notebook](https://discourse.julialang.org/t/performance-difference-in-colab-and-jupyter-notebook/39931)

<div class="topic-metadata">

**Author:** [@SambitMishra98](https://discourse.julialang.org/u/SambitMishra98)\
**Replies:** 2\
**Last updated:** [May 22, 2020, 12:09pm UTC](https://discourse.julialang.org/t/performance-difference-in-colab-and-jupyter-notebook/39931 "2020-05-22T12:09:21Z")

</div>

I set up Julia in Google Colab using Gordan MacMillan’s Github code. I executed the following few lines to compare the performance of Julia in Google Colab and Jupyter Notebook in Ubuntu 20.04 WSL. using BenchmarkTools …

---

## [Best way to optimize code](https://discourse.julialang.org/t/best-way-to-optimize-code/37980)

<div class="topic-metadata">

**Author:** [@jmaths](https://discourse.julialang.org/u/jmaths)\
**Replies:** 29\
**Last updated:** [May 21, 2020, 11:04pm UTC](https://discourse.julialang.org/t/best-way-to-optimize-code/37980 "2020-05-21T23:04:35Z")

</div>

I’m making my first effort to move from Matlab to Julia and have found my code to improve by ~3x but still think there is more to come, I’m not using any global variables in the function and have preallocated all the arr…

---

## [Mathematical precision in julia](https://discourse.julialang.org/t/mathematical-precision-in-julia/39895)

<div class="topic-metadata">

**Author:** [@Marques](https://discourse.julialang.org/u/Marques)\
**Replies:** 1\
**Last updated:** [May 21, 2020, 5:41pm UTC](https://discourse.julialang.org/t/mathematical-precision-in-julia/39895 "2020-05-21T17:41:50Z")

</div>

Hi guys, I’m still a beginner in Julia and I would like tips on how I can get greater precision in extensive mathematical calculations performed in Julia. Thanks :slight\_smile:

---

## [Why is broadcasting allocating so much memory?](https://discourse.julialang.org/t/why-is-broadcasting-allocating-so-much-memory/39874)

<div class="topic-metadata">

**Author:** [@torrance](https://discourse.julialang.org/u/torrance)\
**Replies:** 8\
**Last updated:** [May 21, 2020, 10:18am UTC](https://discourse.julialang.org/t/why-is-broadcasting-allocating-so-much-memory/39874 "2020-05-21T10:18:49Z")

</div>

In the below dummy code I show that doing the sum over the 4-vectors using broadcasting is an order of magnitude slower than iteration of the 4-vector manually. However, I don’t understand why - and whether I can keep us…

---

## ["vectorized" QuadGK?](https://discourse.julialang.org/t/vectorized-quadgk/39853)

<div class="topic-metadata">

**Author:** [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Replies:** 3\
**Last updated:** [May 20, 2020, 9:17pm UTC](https://discourse.julialang.org/t/vectorized-quadgk/39853 "2020-05-20T21:17:46Z")

</div>

I’ll start off by saying that QuadGK is really fast. But I want to know how to make it faster for what I think is a relatively common usecase, which is its vectorized form. Broadcasting the quadgk call itself performs as…

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

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