# \#speed-optimization

**URL:** https://discourse.julialang.org/tag/speed-optimization/1015.md

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

---

## [Nerd Sniping: How can I improve the read in of a human-readable file?](https://discourse.julialang.org/t/nerd-sniping-how-can-i-improve-the-read-in-of-a-human-readable-file/134517)

<div class="topic-metadata">

**Author:** [@jwtkeeble](https://discourse.julialang.org/u/jwtkeeble)\
**Replies:** 17\
**Last updated:** [December 14, 2025, 7:30pm UTC](https://discourse.julialang.org/t/nerd-sniping-how-can-i-improve-the-read-in-of-a-human-readable-file/134517 "2025-12-14T19:30:52Z")

</div>

Hi All, I’m currently trying to read in a huge human-readable file, which can take up to 50% of my total walltime when running a job. I was wondering if there’s a more efficient way to read in such a file? Naturally, I…

---

## [Optimisation over grid of parameters with \`Optimization.jl\`](https://discourse.julialang.org/t/optimisation-over-grid-of-parameters-with-optimization-jl/131571)

<div class="topic-metadata">

**Author:** [@NoFishLikeIan](https://discourse.julialang.org/u/NoFishLikeIan)\
**Replies:** 7\
**Last updated:** [August 18, 2025, 10:28pm UTC](https://discourse.julialang.org/t/optimisation-over-grid-of-parameters-with-optimization-jl/131571 "2025-08-18T22:28:49Z")

</div>

I am trying to solve a low dimensional (box-)constrained optimisation problem over a large grid of parameters. Both the optimisation problem and the constraints depend on the parameters. I can assume that the optimisatio…

---

## [Loading 60k images from a folder. Python code is way faster than Julia](https://discourse.julialang.org/t/loading-60k-images-from-a-folder-python-code-is-way-faster-than-julia/129867)

<div class="topic-metadata">

**Author:** [@AI\_hayasaka](https://discourse.julialang.org/u/AI_hayasaka)\
**Replies:** 11\
**Last updated:** [June 14, 2025, 1:31am UTC](https://discourse.julialang.org/t/loading-60k-images-from-a-folder-python-code-is-way-faster-than-julia/129867 "2025-06-14T01:31:25Z")

</div>

This is the code i have currently: using Images function createDataset(path) X = \[\] y = \[\] for label in readdir(path) for file in readdir("$path/$label") img = load("$path/$label/$file") …

---

## [Julia vs C++ for computational mechanics - Implicit Material Point Method](https://discourse.julialang.org/t/julia-vs-c-for-computational-mechanics-implicit-material-point-method/129180)

<div class="topic-metadata">

**Author:** [@jowsky](https://discourse.julialang.org/u/jowsky)\
**Replies:** 13\
**Last updated:** [May 24, 2025, 5:20am UTC](https://discourse.julialang.org/t/julia-vs-c-for-computational-mechanics-implicit-material-point-method/129180 "2025-05-24T05:20:30Z")

</div>

TL;DR : Writing an implicit Material Point Method solver. Would it be that much slower in Julia than C++ for a similar time-effort ? Hello, I am PhD student working on simulating creeping snow. I am currently planning …

---

## [LU factorisation of a block tridiagonal square matrix](https://discourse.julialang.org/t/lu-factorisation-of-a-block-tridiagonal-square-matrix/124852)

<div class="topic-metadata">

**Author:** [@eveningsilverfox](https://discourse.julialang.org/u/eveningsilverfox)\
**Replies:** 3\
**Last updated:** [January 17, 2025, 8:55pm UTC](https://discourse.julialang.org/t/lu-factorisation-of-a-block-tridiagonal-square-matrix/124852 "2025-01-17T20:55:56Z")

</div>

Following up on Fastest way to perform A \* B \* A’ Given a block tridiagonal matrix X with size NxN, having blocks of size MxM (M\<N and N%M=0), I define A = inv(I-X). I also define B having the same size as A, and it is …

---

## [Help with reducing allocations when indexing into custom Array](https://discourse.julialang.org/t/help-with-reducing-allocations-when-indexing-into-custom-array/124732)

<div class="topic-metadata">

**Author:** [@thomasc791](https://discourse.julialang.org/u/thomasc791)\
**Replies:** 10\
**Last updated:** [January 14, 2025, 10:21pm UTC](https://discourse.julialang.org/t/help-with-reducing-allocations-when-indexing-into-custom-array/124732 "2025-01-14T22:21:09Z")

</div>

Hi everyone, I am quite new to the language, and was wondering if people could help me optimising my piece of code. The idea for this array type is to reduce the total Base.summarysize for a vector of vector as much as …

---

## [How to speedup setindex! and getindex?](https://discourse.julialang.org/t/how-to-speedup-setindex-and-getindex/124413)

<div class="topic-metadata">

**Author:** [@Thomas\_Van\_Giel](https://discourse.julialang.org/u/Thomas_Van_Giel)\
**Replies:** 3\
**Last updated:** [January 3, 2025, 8:50pm UTC](https://discourse.julialang.org/t/how-to-speedup-setindex-and-getindex/124413 "2025-01-03T20:50:58Z")

</div>

I have a piece of code where the setindex! and getindex function take a lot of time to execute. Quite simplified, the code looks a bit like this: using Random function main() A = rand(0:0.1:100000, 200,200) for s…

---

## [MATLAB is faster for my large system of ODEs?](https://discourse.julialang.org/t/matlab-is-faster-for-my-large-system-of-odes/122610)

<div class="topic-metadata">

**Author:** [@martru](https://discourse.julialang.org/u/martru)\
**Replies:** 21\
**Last updated:** [November 15, 2024, 6:12pm UTC](https://discourse.julialang.org/t/matlab-is-faster-for-my-large-system-of-odes/122610 "2024-11-15T18:12:50Z")

</div>

Excuse the deliberately provocative title :slight\_smile: I have a very large system of ODEs of the form: dot{x} = Ax + Bu A is a sparse matrix 5505x5505. B\*u is a 5505 element vector. Using ode45 in matlab, it solves …

---

## [Vectorise summation over index in nested for loop](https://discourse.julialang.org/t/vectorise-summation-over-index-in-nested-for-loop/121158)

<div class="topic-metadata">

**Author:** [@eveningsilverfox](https://discourse.julialang.org/u/eveningsilverfox)\
**Replies:** 7\
**Last updated:** [October 10, 2024, 11:33pm UTC](https://discourse.julialang.org/t/vectorise-summation-over-index-in-nested-for-loop/121158 "2024-10-10T23:33:32Z")

</div>

Given a function using LinearAlgebra function test(arr1, arr2, arr3, g) return 1 ./ (arr1 .+ arr2 .+ arr3 .+ im\*g) end N1 = 100000; arr1 = range(0,10,N1); N2 = 5000; arr2 = range(0,10,N2); N3 = 5000; arr3 = range…

---

## [Help with for-loops optimization / Translation from Matlab](https://discourse.julialang.org/t/help-with-for-loops-optimization-translation-from-matlab/118204)

<div class="topic-metadata">

**Author:** [@Benjamin7](https://discourse.julialang.org/u/Benjamin7)\
**Replies:** 7\
**Last updated:** [August 15, 2024, 7:42am UTC](https://discourse.julialang.org/t/help-with-for-loops-optimization-translation-from-matlab/118204 "2024-08-15T07:42:59Z")

</div>

Hi, I have been asked to translate a matlab code to Julia to gain speed, what I have done is to put each for loop with the @inbound, put each array and all important code in a function, I have defined the type of almost …

---

## [\[Turing.jl\] Understanding running times in Turing.jl? Beyond @time](https://discourse.julialang.org/t/turing-jl-understanding-running-times-in-turing-jl-beyond-time/118154)

<div class="topic-metadata">

**Author:** [@FJRubio](https://discourse.julialang.org/u/FJRubio)\
**Replies:** 1\
**Last updated:** [August 13, 2024, 6:29pm UTC](https://discourse.julialang.org/t/turing-jl-understanding-running-times-in-turing-jl-beyond-time/118154 "2024-08-13T18:29:16Z")

</div>

This is a general question about understanding running times in sample() from Turing.jl when I know how long it takes to evaluate a custom log-likelihood function. I have a custom log-likelihood function, my\_loglik(), f…

---

## [Matrices inside a or outside a Function](https://discourse.julialang.org/t/matrices-inside-a-or-outside-a-function/117775)

<div class="topic-metadata">

**Author:** [@Benjamin7](https://discourse.julialang.org/u/Benjamin7)\
**Replies:** 12\
**Last updated:** [August 4, 2024, 8:11am UTC](https://discourse.julialang.org/t/matrices-inside-a-or-outside-a-function/117775 "2024-08-04T08:11:16Z")

</div>

Hello community! As I understand from what I have read in Julia’s optimization section, “Performance critical code should be inside a function”. My code has several for loops that fill the created arrays, my question i…

---

## [Fast read operations from a large array of low-dimensional SVectors](https://discourse.julialang.org/t/fast-read-operations-from-a-large-array-of-low-dimensional-svectors/117264)

<div class="topic-metadata">

**Author:** [@dchatter](https://discourse.julialang.org/u/dchatter)\
**Replies:** 6\
**Last updated:** [July 20, 2024, 2:39pm UTC](https://discourse.julialang.org/t/fast-read-operations-from-a-large-array-of-low-dimensional-svectors/117264 "2024-07-20T14:39:18Z")

</div>

I am looking for a suitable data structure to store the graph of a real-valued function on a rectangular grid in d dimensions; the purpose is given below. The dimension d is at most 5, and SVectors are quite suitable. Ho…

---

## [Variable sized windows for moving average](https://discourse.julialang.org/t/variable-sized-windows-for-moving-average/115078)

<div class="topic-metadata">

**Author:** [@feanor12](https://discourse.julialang.org/u/feanor12)\
**Replies:** 8\
**Last updated:** [June 4, 2024, 6:19am UTC](https://discourse.julialang.org/t/variable-sized-windows-for-moving-average/115078 "2024-06-04T06:19:56Z")

</div>

Hi, I saw some libraries for moving averages (RollingFunctions.jl), but I did not find one with the option to make the window size variable. My specific case would be a moving average over a “time series”, averaging the…

---

## [The Problem with Julia that makes me want to leave - First run Times](https://discourse.julialang.org/t/the-problem-with-julia-that-makes-me-want-to-leave-first-run-times/114316)

<div class="topic-metadata">

**Author:** [@Maddy](https://discourse.julialang.org/u/Maddy)\
**Replies:** 52\
**Last updated:** [May 18, 2024, 6:05pm UTC](https://discourse.julialang.org/t/the-problem-with-julia-that-makes-me-want-to-leave-first-run-times/114316 "2024-05-18T18:05:01Z")

</div>

I started my programming journey in Python. A year ago, to create a real-time simulation, I came to know about Julia with its great speed. I used Julia for the first time and I remember the spark of joy I had while mess…

---

## [Is there a quicker way to obtain normalized multivariate random normal draws?](https://discourse.julialang.org/t/is-there-a-quicker-way-to-obtain-normalized-multivariate-random-normal-draws/114411)

<div class="topic-metadata">

**Author:** [@schwob](https://discourse.julialang.org/u/schwob)\
**Replies:** 15\
**Last updated:** [May 18, 2024, 3:33pm UTC](https://discourse.julialang.org/t/is-there-a-quicker-way-to-obtain-normalized-multivariate-random-normal-draws/114411 "2024-05-18T15:33:39Z")

</div>

I want to make n random draws from a Multivariate Normal distribution, then divide each element in each of the random draws by the norm of the random draw. Mathematically, I want to obtain \\mathbf{y}\_i=\\mathbf{x}\_i/||\\ma…

---

## [How to encourage compiler optimizations?](https://discourse.julialang.org/t/how-to-encourage-compiler-optimizations/113325)

<div class="topic-metadata">

**Author:** [@DanDoe](https://discourse.julialang.org/u/DanDoe)\
**Replies:** 12\
**Last updated:** [April 23, 2024, 1:32pm UTC](https://discourse.julialang.org/t/how-to-encourage-compiler-optimizations/113325 "2024-04-23T13:32:18Z")

</div>

I have two functions which contain an identical block of code foo followed by different blocks of code bar1, bar2. I time these functions using our timing tool which is essentially a derivate of \_timer\_expr from TimerOut…

---

## [Chairmarks.jl](https://discourse.julialang.org/t/chairmarks-jl/111096)

<div class="topic-metadata">

**Author:** [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Replies:** 82\
**Last updated:** [March 12, 2024, 7:45pm UTC](https://discourse.julialang.org/t/chairmarks-jl/111096 "2024-03-12T19:45:39Z")

</div>

Hello folks! I’m announcing Chairmarks.jl, version 1.0 (docs). It’s a benchmarking package that aims to be hundreds of times faster than BenchmarkTools without compromising on precision. Usage is pretty similar to Ben…

---

## [CUDA.jl for particle tracking simulation](https://discourse.julialang.org/t/cuda-jl-for-particle-tracking-simulation/110906)

<div class="topic-metadata">

**Author:** [@VitorSouzaLNLS](https://discourse.julialang.org/u/VitorSouzaLNLS)\
**Replies:** 4\
**Last updated:** [February 29, 2024, 10:40am UTC](https://discourse.julialang.org/t/cuda-jl-for-particle-tracking-simulation/110906 "2024-02-29T10:40:35Z")

</div>

Im trying to implement some consolidated CPU functions for particle tracking simulations (models of synchrotron accelerators) in GPU using CUDA.jl. The goal is to be able to paralelize tracking routines. I had tried to …

---

## [Speeding up JuMP model creation with sets that depend on other indexes](https://discourse.julialang.org/t/speeding-up-jump-model-creation-with-sets-that-depend-on-other-indexes/107333)

<div class="topic-metadata">

**Author:** [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)\
**Replies:** 8\
**Last updated:** [December 15, 2023, 3:18pm UTC](https://discourse.julialang.org/t/speeding-up-jump-model-creation-with-sets-that-depend-on-other-indexes/107333 "2023-12-15T15:18:48Z")

</div>

I am looking for tips on building a model with variables, expressions, and constraints over sets that depends on indexes from other sets. For instance: @expression(model, \[i = 1:5, j = blah\[i\]\], ...) where blah is a di…

---

## [Most performant way to perform matrix and vector calculations in a function](https://discourse.julialang.org/t/most-performant-way-to-perform-matrix-and-vector-calculations-in-a-function/104672)

<div class="topic-metadata">

**Author:** [@eduardosalaz](https://discourse.julialang.org/u/eduardosalaz)\
**Replies:** 5\
**Last updated:** [October 9, 2023, 9:42pm UTC](https://discourse.julialang.org/t/most-performant-way-to-perform-matrix-and-vector-calculations-in-a-function/104672 "2023-10-09T21:42:50Z")

</div>

Hi there everone. Currently I have the following function: function start\_constraints(S, B, M, V, R, X, values\_matrix, risk\_vec) for i in 1:S for m in 1:M values\_matrix\[i, m\] = sum(X\[i, j\] \* V\[m\]…

---

## [Fastest way possible to find index of value equals 1 across a matrix column](https://discourse.julialang.org/t/fastest-way-possible-to-find-index-of-value-equals-1-across-a-matrix-column/104485)

<div class="topic-metadata">

**Author:** [@eduardosalaz](https://discourse.julialang.org/u/eduardosalaz)\
**Replies:** 7\
**Last updated:** [October 6, 2023, 4:32pm UTC](https://discourse.julialang.org/t/fastest-way-possible-to-find-index-of-value-equals-1-across-a-matrix-column/104485 "2023-10-06T16:32:06Z")

</div>

Hi there everyone. I am currently working on my thesis which involves an optimization problem in which I have an X decision matrix filled with 0s, each column must have a 1 value as it represents an allocation. In my lo…

---

## [Performant reading of .tar.xz files](https://discourse.julialang.org/t/performant-reading-of-tar-xz-files/103912)

<div class="topic-metadata">

**Author:** [@trace\_forms](https://discourse.julialang.org/u/trace_forms)\
**Replies:** 15\
**Last updated:** [September 18, 2023, 1:55pm UTC](https://discourse.julialang.org/t/performant-reading-of-tar-xz-files/103912 "2023-09-18T13:55:45Z")

</div>

Hi there, I am trying to rapidly load data that is stored within .tar.xz files. Specifically, I am working with the genomic sequences and associated metadata for SARS-CoV-2 from GISAID. These come as separate .tar.xz fi…

---

## [Trying to make multithreading to work on applying a function number of times](https://discourse.julialang.org/t/trying-to-make-multithreading-to-work-on-applying-a-function-number-of-times/103124)

<div class="topic-metadata">

**Author:** [@ahmed](https://discourse.julialang.org/u/ahmed)\
**Replies:** 11\
**Last updated:** [August 25, 2023, 7:51am UTC](https://discourse.julialang.org/t/trying-to-make-multithreading-to-work-on-applying-a-function-number-of-times/103124 "2023-08-25T07:51:37Z")

</div>

I have a function F that does some computations on its input arrays. First I’m trying to see if I can make this function as fast as possible as this function will be computed 50 times in one of possibly many iterations s…

---

## [Speed up solution of large system of equations](https://discourse.julialang.org/t/speed-up-solution-of-large-system-of-equations/102659)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 18\
**Last updated:** [August 19, 2023, 3:19pm UTC](https://discourse.julialang.org/t/speed-up-solution-of-large-system-of-equations/102659 "2023-08-19T15:19:48Z")

</div>

I have a system of equations: \\begin{aligned} & S^m\_{a\_m, e\_m}-\\mu^{0m}\_{a\_m, e\_m}=\\sum\_{a\_m=1}^{46} {\\Pi}\_{a\_m, e\_m, a\_f, e\_f}\\sqrt{S^m\_{a\_m, e\_m} S^f\_{a\_f, e\_f}} \\prod\_{k=0}^{T(a\_m, a\_f)-1}\\left(\\frac{\\mu^{0m}\_{a\_m+k…

---

## [Speeding up matrix exponential and matrix multiplication](https://discourse.julialang.org/t/speeding-up-matrix-exponential-and-matrix-multiplication/102272)

<div class="topic-metadata">

**Author:** [@eveningsilverfox](https://discourse.julialang.org/u/eveningsilverfox)\
**Replies:** 58\
**Last updated:** [August 1, 2023, 4:21pm UTC](https://discourse.julialang.org/t/speeding-up-matrix-exponential-and-matrix-multiplication/102272 "2023-08-01T16:21:04Z")

</div>

I am very new to Julia and trying to convert my python codes to Julia to speed up my work. However, the present Julia version, pasted below, still runs slower than my python version. I see two bottlenecks: (1) the matr…

---

## [Speed Comparison Python v Julia for custom layers](https://discourse.julialang.org/t/speed-comparison-python-v-julia-for-custom-layers/101922)

<div class="topic-metadata">

**Author:** [@willleeney](https://discourse.julialang.org/u/willleeney)\
**Replies:** 25\
**Last updated:** [July 28, 2023, 8:56am UTC](https://discourse.julialang.org/t/speed-comparison-python-v-julia-for-custom-layers/101922 "2023-07-28T08:56:36Z")

</div>

New to Julia and looking at comparisons of speed in forward pass with pytorch. I want to optimise performance of training a neural network that will contain custom layers. I have provide some code for an example. I want …

---

## [How to preallocate and reuse buffers for oft-repeated computation?](https://discourse.julialang.org/t/how-to-preallocate-and-reuse-buffers-for-oft-repeated-computation/100915)

<div class="topic-metadata">

**Author:** [@philip](https://discourse.julialang.org/u/philip)\
**Replies:** 15\
**Last updated:** [July 12, 2023, 10:15am UTC](https://discourse.julialang.org/t/how-to-preallocate-and-reuse-buffers-for-oft-repeated-computation/100915 "2023-07-12T10:15:48Z")

</div>

In How to optimise Julia code: A practical guide, Jakob Nissen suggests that one way to optimize code + reduce allocations is to Preallocate buffers once and reuse them multiple times I’m wondering if someone has a wa…

---

## [Creating tidytext's unnest\_tokens() in Julia and speed](https://discourse.julialang.org/t/creating-tidytexts-unnest-tokens-in-julia-and-speed/100579)

<div class="topic-metadata">

**Author:** [@Alex\_Tantos](https://discourse.julialang.org/u/Alex_Tantos)\
**Replies:** 5\
**Last updated:** [June 20, 2023, 7:58am UTC](https://discourse.julialang.org/t/creating-tidytexts-unnest-tokens-in-julia-and-speed/100579 "2023-06-20T07:58:14Z")

</div>

Hi. I am trying to create a function that replicates the unnest\_tokens() function in the tidytext R package. The version I came up with is the following: function unnest\_tokens3(df::DataFrame, input\_col::Symbol, output…

---

## [Speeding-up the construction of a second order cone JuMP model](https://discourse.julialang.org/t/speeding-up-the-construction-of-a-second-order-cone-jump-model/98311)

<div class="topic-metadata">

**Author:** [@cgois](https://discourse.julialang.org/u/cgois)\
**Replies:** 6\
**Last updated:** [May 15, 2023, 12:42pm UTC](https://discourse.julialang.org/t/speeding-up-the-construction-of-a-second-order-cone-jump-model/98311 "2023-05-15T12:42:16Z")

</div>

Hi everyone. I need to solve tens of thousands of second order cone problems, so I need my code to be as fast as possible. Currently, my main bottleneck is actually building the problem in JuMP and I would appreciate any…

[Next page](https://discourse.julialang.org/tag/speed-optimization/1015.md?match_all_tags=true&page=1&tags%5B%5D=speed-optimization)
