# Performance

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

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

**Page:** 33

---

## [Write a table into SQLite and DuckDB in efficient manner](https://discourse.julialang.org/t/write-a-table-into-sqlite-and-duckdb-in-efficient-manner/93417)

<div class="topic-metadata">

**Author:** [@sairus7](https://discourse.julialang.org/u/sairus7)\
**Replies:** 24\
**Last updated:** [December 8, 2023, 3:25am UTC](https://discourse.julialang.org/t/write-a-table-into-sqlite-and-duckdb-in-efficient-manner/93417 "2023-12-08T03:25:25Z")

</div>

How can I efficiently populate DB table from very long tables (say, millions rows)? I try to compare SQlite vs DuckDB in this scenario, but I think I’m doing this very inefficiently: using SQLite, DuckDB, Tables con\_sq…

---

## [Automatic differentiation for Complex output w.r.t to Real inputs taking too long compared to the function evaluation](https://discourse.julialang.org/t/automatic-differentiation-for-complex-output-w-r-t-to-real-inputs-taking-too-long-compared-to-the-function-evaluation/107288)

<div class="topic-metadata">

**Author:** [@KapilKhanal](https://discourse.julialang.org/u/KapilKhanal)\
**Replies:** 3\
**Last updated:** [December 8, 2023, 1:53am UTC](https://discourse.julialang.org/t/automatic-differentiation-for-complex-output-w-r-t-to-real-inputs-taking-too-long-compared-to-the-function-evaluation/107288 "2023-12-08T01:53:16Z")

</div>

I am using Zygote for differentiating a complex output with respect to 3 real inputs. The function evaluation itself takes about 0.088371 seconds (146.12 k allocations: 10.071 MiB, 99.23% compilation time) but the grad…

---

## [Making sorting a tree represented by vector of any types faster](https://discourse.julialang.org/t/making-sorting-a-tree-represented-by-vector-of-any-types-faster/106998)

<div class="topic-metadata">

**Author:** [@dgsob](https://discourse.julialang.org/u/dgsob)\
**Replies:** 1\
**Last updated:** [December 7, 2023, 11:04pm UTC](https://discourse.julialang.org/t/making-sorting-a-tree-represented-by-vector-of-any-types-faster/106998 "2023-12-07T23:04:52Z")

</div>

I have an algorithm that generates a tree by multiplying two functions. It works, but my goal is to make it faster. With profiling I’ve found that a substantial amount of time is spend on sorting. I’m wondering if the s…

---

## [Boxing obvious cases where the type is clear](https://discourse.julialang.org/t/boxing-obvious-cases-where-the-type-is-clear/107192)

<div class="topic-metadata">

**Author:** [@feribg](https://discourse.julialang.org/u/feribg)\
**Replies:** 13\
**Last updated:** [December 7, 2023, 9:57am UTC](https://discourse.julialang.org/t/boxing-obvious-cases-where-the-type-is-clear/107192 "2023-12-07T09:57:47Z")

</div>

Im new to Julia but this whole world of dynamic and static typing is becoming very disconcerning. Take a look at this: Regardless what i do i get: Locals #15::var"#15#17"{String, Int64, Int64, Int64} n\_markets::C…

---

## [Performance and memory in large tensor: Julia vs Fortran](https://discourse.julialang.org/t/performance-and-memory-in-large-tensor-julia-vs-fortran/107218)

<div class="topic-metadata">

**Author:** [@fordonez](https://discourse.julialang.org/u/fordonez)\
**Replies:** 3\
**Last updated:** [December 6, 2023, 3:35pm UTC](https://discourse.julialang.org/t/performance-and-memory-in-large-tensor-julia-vs-fortran/107218 "2023-12-06T15:35:23Z")

</div>

I have a tensor with dimensions (I, J, K, L, M, N), which I am modifying through a loop. I am trying to reach Fortran’s speed in Julia (if (I, J, K, L, M, N) = (100, 100, 100, 100, 10, 10) the Julia/Fortran time ratio is…

---

## [Inplace axpy! but storing to a third arguement rather than y](https://discourse.julialang.org/t/inplace-axpy-but-storing-to-a-third-arguement-rather-than-y/107188)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 4\
**Last updated:** [December 6, 2023, 10:49am UTC](https://discourse.julialang.org/t/inplace-axpy-but-storing-to-a-third-arguement-rather-than-y/107188 "2023-12-06T10:49:32Z")

</div>

Hello, from the BLAS package, I know that axpy!(a,X,Y) computes Y += a X, where a is a scalar and X and Y are a matrix or a vector. Now I want instead something like Z = a X + Y So, something like axpyz!(a,X,Y,Z). I…

---

## [Removing type instability causes the code slower](https://discourse.julialang.org/t/removing-type-instability-causes-the-code-slower/107074)

<div class="topic-metadata">

**Author:** [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Replies:** 8\
**Last updated:** [December 3, 2023, 6:10pm UTC](https://discourse.julialang.org/t/removing-type-instability-causes-the-code-slower/107074 "2023-12-03T18:10:26Z")

</div>

I have to typed code: @code\_warntype get\_magnetic\_symmetry\_from\_database(1242, 434); MethodInstance for Spglib.get\_magnetic\_symmetry\_from\_database(::Int64, ::Int64) from get\_magnetic\_symmetry\_from\_database(uni\_number,…

---

## [Perplexing behavior when computing the matmul smoke test on GPU in Julia](https://discourse.julialang.org/t/perplexing-behavior-when-computing-the-matmul-smoke-test-on-gpu-in-julia/106994)

<div class="topic-metadata">

**Author:** [@Aakhash\_Sundaresan](https://discourse.julialang.org/u/Aakhash_Sundaresan)\
**Replies:** 5\
**Last updated:** [December 3, 2023, 3:33am UTC](https://discourse.julialang.org/t/perplexing-behavior-when-computing-the-matmul-smoke-test-on-gpu-in-julia/106994 "2023-12-03T03:33:51Z")

</div>

@avikpal , @ChrisRackauckas Why is that when I compute the matmul smoke test for the first time and time it, it takes long time than the CPU computation, and also the allocations are huge. When I again try to compute …

---

## [Performance difference depending on order of comparison in loop](https://discourse.julialang.org/t/performance-difference-depending-on-order-of-comparison-in-loop/107040)

<div class="topic-metadata">

**Author:** [@wheeheee](https://discourse.julialang.org/u/wheeheee)\
**Replies:** 3\
**Last updated:** [December 2, 2023, 1:05pm UTC](https://discourse.julialang.org/t/performance-difference-depending-on-order-of-comparison-in-loop/107040 "2023-12-02T13:05:14Z")

</div>

Unexpectedly, the following function has very different performance depending on the argument order of two matrices, which should be equivalent function f2(x, y; init=0) total = init for i in eachindex(x, y) …

---

## [Avoiding small strings and using IOBuffer](https://discourse.julialang.org/t/avoiding-small-strings-and-using-iobuffer/106980)

<div class="topic-metadata">

**Author:** [@grahamas](https://discourse.julialang.org/u/grahamas)\
**Replies:** 7\
**Last updated:** [December 1, 2023, 7:06pm UTC](https://discourse.julialang.org/t/avoiding-small-strings-and-using-iobuffer/106980 "2023-12-01T19:06:23Z")

</div>

Recently I’ve been using this bit of code to basically conditionally concatenate a bunch of lines in a file: buf = IOBuffer() open("input.txt", "r") do f for line in readlines(f) if line\[1\] != "#" …

---

## [Performance of streaming \`mean\`](https://discourse.julialang.org/t/performance-of-streaming-mean/106999)

<div class="topic-metadata">

**Author:** [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Replies:** 4\
**Last updated:** [December 1, 2023, 3:49pm UTC](https://discourse.julialang.org/t/performance-of-streaming-mean/106999 "2023-12-01T15:49:25Z")

</div>

Here’s a basic streaming mean function (called avg for convenience): function avg(itr) a = zero(eltype(x)) for (i, x) in enumerate(itr) a += (x - a) / i end return a end Why does it allocate so …

---

## [Fastest algorithm for (xi - xj) \* (yi - yj) for i in 1:n, j in 1:n](https://discourse.julialang.org/t/fastest-algorithm-for-xi-xj-yi-yj-for-i-in-1-n-j-in-1-n/106988)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 13\
**Last updated:** [December 1, 2023, 2:11pm UTC](https://discourse.julialang.org/t/fastest-algorithm-for-xi-xj-yi-yj-for-i-in-1-n-j-in-1-n/106988 "2023-12-01T14:11:33Z")

</div>

Suppose we are given two “big” vectors x and y of real numbers (e.g. Float64), both with the same length n. What is the fastest algorithm to compute \[(x\[i\] - x\[j\]) \* (y\[i\] - y\[j\]) for i in 1:n, j in 1:n\] ? Here is a b…

---

## [Sum an SVector skipping one element](https://discourse.julialang.org/t/sum-an-svector-skipping-one-element/106943)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 7\
**Last updated:** [November 30, 2023, 6:12pm UTC](https://discourse.julialang.org/t/sum-an-svector-skipping-one-element/106943 "2023-11-30T18:12:04Z")

</div>

I am optimizing a tight loop where one operation is summing an SVector except that it is required that an element is skipped. Its index is not known at compile time, it is obtained from a lookup table. Some attempts: u…

---

## [What’s your secret in your uncanny ability to optimize code?](https://discourse.julialang.org/t/what-s-your-secret-in-your-uncanny-ability-to-optimize-code/106942)

<div class="topic-metadata">

**Author:** [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Replies:** 3\
**Last updated:** [November 30, 2023, 2:00pm UTC](https://discourse.julialang.org/t/what-s-your-secret-in-your-uncanny-ability-to-optimize-code/106942 "2023-11-30T14:00:05Z")

</div>

From a faster differential equation solver to faster sorting algorithm, people working with Julia have uncanny ability to optimize things with deceptively simple optimizations that are, indeed, the work of Julian in brin…

---

## [Jl\_call - function call latency](https://discourse.julialang.org/t/jl-call-function-call-latency/106791)

<div class="topic-metadata">

**Author:** [@AntoineK](https://discourse.julialang.org/u/AntoineK)\
**Replies:** 5\
**Last updated:** [November 29, 2023, 3:59pm UTC](https://discourse.julialang.org/t/jl-call-function-call-latency/106791 "2023-11-29T15:59:06Z")

</div>

Hello, My first benchmarks show that calling the jl\_call function comes with a latency of 100 nanoseconds (measured by calling an empty Julia function) on a Xeon Gold processor. Is it expected ? In Julia, BenchmarksTo…

---

## [How to execute tasks in parallel in a for loop](https://discourse.julialang.org/t/how-to-execute-tasks-in-parallel-in-a-for-loop/106736)

<div class="topic-metadata">

**Author:** [@Chamika\_Kasun](https://discourse.julialang.org/u/Chamika_Kasun)\
**Replies:** 27\
**Last updated:** [November 29, 2023, 3:22am UTC](https://discourse.julialang.org/t/how-to-execute-tasks-in-parallel-in-a-for-loop/106736 "2023-11-29T03:22:42Z")

</div>

I’m quite new to Julia programming, and I’m looking for a better way to parallelize the execution of a for loop. Basically, the logic I have in the following code needs to be executed in parallel. data = \[\] …

---

## [Typeof on Any vs Typeof on Union?](https://discourse.julialang.org/t/typeof-on-any-vs-typeof-on-union/106806)

<div class="topic-metadata">

**Author:** [@hlbnet](https://discourse.julialang.org/u/hlbnet)\
**Replies:** 3\
**Last updated:** [November 27, 2023, 4:48pm UTC](https://discourse.julialang.org/t/typeof-on-any-vs-typeof-on-union/106806 "2023-11-27T16:48:10Z")

</div>

Hi everybody, Is there a general explanation of why typeof comparisons on Any is 20 times slower than on Union in the following example ? Especially, the huge memory allocation in one case but not in the other ? Here …

---

## [Speed of multiple dispatch](https://discourse.julialang.org/t/speed-of-multiple-dispatch/106717)

<div class="topic-metadata">

**Author:** [@hlbnet](https://discourse.julialang.org/u/hlbnet)\
**Replies:** 14\
**Last updated:** [November 27, 2023, 4:25pm UTC](https://discourse.julialang.org/t/speed-of-multiple-dispatch/106717 "2023-11-27T16:25:24Z")

</div>

Hello, In the following example, multiple dispatch is more that 10 times slower than typeof comparisons. Is it expected, or is there some issue in my code ? Ouput: Size=20000 If typeof 1006900000 1.576137 seconds…

---

## [Is there a possibility to prevent task switches in a block of code?](https://discourse.julialang.org/t/is-there-a-possibility-to-prevent-task-switches-in-a-block-of-code/106798)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 49\
**Last updated:** [November 27, 2023, 3:54pm UTC](https://discourse.julialang.org/t/is-there-a-possibility-to-prevent-task-switches-in-a-block-of-code/106798 "2023-11-27T15:54:16Z")

</div>

I would like to ensure that within a certain block of code no task switch can happen. A bit like an “atomic block” for async tasks

---

## [Is it possible to cut a vector into 2 pieces without allocations?](https://discourse.julialang.org/t/is-it-possible-to-cut-a-vector-into-2-pieces-without-allocations/106749)

<div class="topic-metadata">

**Author:** [@Leo\_I](https://discourse.julialang.org/u/Leo_I)\
**Replies:** 11\
**Last updated:** [November 27, 2023, 10:25am UTC](https://discourse.julialang.org/t/is-it-possible-to-cut-a-vector-into-2-pieces-without-allocations/106749 "2023-11-27T10:25:36Z")

</div>

Let’s say I have toy data m, n = 10^3, 10^6; x1 = \[rand(-1:0.001:1,s) for j=1:n for s in rand(1:m,1)\] len = \[rand(1:length(x)) for x in x1\] I wish to split each vector x1\[j\] into x1\[j\]\[1:len\[j\]\] and x1\[j\]\[len\[j\]:end…

---

## [How can I use TimerOutputs.jl to time a function and its internal function calls in a package?](https://discourse.julialang.org/t/how-can-i-use-timeroutputs-jl-to-time-a-function-and-its-internal-function-calls-in-a-package/106702)

<div class="topic-metadata">

**Author:** [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Replies:** 1\
**Last updated:** [November 25, 2023, 10:00am UTC](https://discourse.julialang.org/t/how-can-i-use-timeroutputs-jl-to-time-a-function-and-its-internal-function-calls-in-a-package/106702 "2023-11-25T10:00:23Z")

</div>

From the doc of the TimerOutputs.jl, it is not clear how to use it for timing a function and its internal function calls in my developing packages. Normally, I will create a new environment outside of my package and writ…

---

## [Accelerating linear algebra code and getting different results](https://discourse.julialang.org/t/accelerating-linear-algebra-code-and-getting-different-results/106634)

<div class="topic-metadata">

**Author:** [@Leticia-maria](https://discourse.julialang.org/u/Leticia-maria)\
**Replies:** 5\
**Last updated:** [November 24, 2023, 3:58pm UTC](https://discourse.julialang.org/t/accelerating-linear-algebra-code-and-getting-different-results/106634 "2023-11-24T15:58:55Z")

</div>

Hello, so, I have been trying accelerating this function called overlap by using broadcasting and dot notation instead of unpacking matrices elements using for loops. However, I am getting different results when I do tha…

---

## [JET \`report\_call\` error on array.jl for \`iterate(::DataType)\` using \`typeof\`](https://discourse.julialang.org/t/jet-report-call-error-on-array-jl-for-iterate-datatype-using-typeof/106670)

<div class="topic-metadata">

**Author:** [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Replies:** 0\
**Last updated:** [November 24, 2023, 9:55am UTC](https://discourse.julialang.org/t/jet-report-call-error-on-array-jl-for-iterate-datatype-using-typeof/106670 "2023-11-24T09:55:57Z")

</div>

I define the following function, which seems pretty robust to me myf(vs::Vector{N}) where {N\<:Number} = \[typeof(v) for v in vs\] But, using JET, I get a possible error julia\> JET.report\_call(myf) ═════ 1 possible erro…

---

## [Copying mutable structs without using deepcopy()](https://discourse.julialang.org/t/copying-mutable-structs-without-using-deepcopy/106648)

<div class="topic-metadata">

**Author:** [@rolim.gustavo](https://discourse.julialang.org/u/rolim.gustavo)\
**Replies:** 4\
**Last updated:** [November 24, 2023, 8:37am UTC](https://discourse.julialang.org/t/copying-mutable-structs-without-using-deepcopy/106648 "2023-11-24T08:37:30Z")

</div>

Dear colleagues, I am working on an optimization problem where I have to group a permutation of jobs, which have some characteristics. A solution to this problem can be easily represented as a vector of vectors of a typ…

---

## [Optimizing Direct 2D Convolution Code](https://discourse.julialang.org/t/optimizing-direct-2d-convolution-code/106598)

<div class="topic-metadata">

**Author:** [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Replies:** 14\
**Last updated:** [November 23, 2023, 8:48pm UTC](https://discourse.julialang.org/t/optimizing-direct-2d-convolution-code/106598 "2023-11-23T20:48:40Z")

</div>

I have implemented 2D convolution using direct calculation: using BenchmarkTools; function \_Conv2D!( mO :: Matrix{T}, mI :: Matrix{T}, mK :: Matrix{T} ) where {T \<: AbstractFloat} numRowsI, numColsI = size(mI); …

---

## [Run parrallel computing code](https://discourse.julialang.org/t/run-parrallel-computing-code/106645)

<div class="topic-metadata">

**Author:** [@Somali10](https://discourse.julialang.org/u/Somali10)\
**Replies:** 10\
**Last updated:** [November 23, 2023, 7:01pm UTC](https://discourse.julialang.org/t/run-parrallel-computing-code/106645 "2023-11-23T19:01:38Z")

</div>

I have met this issue when I need to run the Performance Overview code GitError(Code:ENOTFOUND, Class:Config, config value ‘safe.directory’ was not found) Stacktrace: \[1\] macro expansion @ \[C:\\Users\\profe\\AppData\\Local\\…

---

## [Speeding up a color transformation loop](https://discourse.julialang.org/t/speeding-up-a-color-transformation-loop/106445)

<div class="topic-metadata">

**Author:** [@mpeters2](https://discourse.julialang.org/u/mpeters2)\
**Replies:** 29\
**Last updated:** [November 23, 2023, 12:23am UTC](https://discourse.julialang.org/t/speeding-up-a-color-transformation-loop/106445 "2023-11-23T00:23:40Z")

</div>

First, a little background. I have an image \[2000 x 2000 pixels\] I am applying different illuminants to. Towards the end of this process I have to transform the CIE1931 X,Y, and Z coordinate to RGB. These are stored as…

---

## [Multi-threaded benchmarking is slow](https://discourse.julialang.org/t/multi-threaded-benchmarking-is-slow/106386)

<div class="topic-metadata">

**Author:** [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Replies:** 12\
**Last updated:** [November 21, 2023, 7:43pm UTC](https://discourse.julialang.org/t/multi-threaded-benchmarking-is-slow/106386 "2023-11-21T19:43:32Z")

</div>

Motivation Running many benchmarks can be slow. Since almost all of them are independent, they can theoretically run easily on parallel. Problem It turns out running the benchmarks in parallel takes more or less equal …

---

## [Hash Collision in Memoization](https://discourse.julialang.org/t/hash-collision-in-memoization/106479)

<div class="topic-metadata">

**Author:** [@marco\_menarini](https://discourse.julialang.org/u/marco_menarini)\
**Replies:** 10\
**Last updated:** [November 20, 2023, 9:02pm UTC](https://discourse.julialang.org/t/hash-collision-in-memoization/106479 "2023-11-20T21:02:44Z")

</div>

Using the Caching.jl and LRUCache.jl packages and reading Tom Kwong’s book on the memorization pattern, I noticed an edge case that is never considered. No matter how big, a hash can be repeated for different data. Gran…

---

## [Recommendation for CI benchmark to catch regression](https://discourse.julialang.org/t/recommendation-for-ci-benchmark-to-catch-regression/104698)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 6\
**Last updated:** [November 19, 2023, 9:33pm UTC](https://discourse.julialang.org/t/recommendation-for-ci-benchmark-to-catch-regression/104698 "2023-11-19T21:33:29Z")

</div>

It’s pretty common for Julia package developers to want to monitor key usage latency / performance to avoid regression in PRs. Julia itself has nanosoldier, and some big package such as Makie has their own bot: Hardcode …

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

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