# Performance

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

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

**Page:** 16

---

## [Why/where does this allocate?](https://discourse.julialang.org/t/why-where-does-this-allocate/122607)

<div class="topic-metadata">

**Author:** [@Palli](https://discourse.julialang.org/u/Palli)\
**Replies:** 10\
**Last updated:** [November 15, 2024, 2:50am UTC](https://discourse.julialang.org/t/why-where-does-this-allocate/122607 "2024-11-15T02:50:10Z")

</div>

I think this function in Julia allocates once, 16 bytes, at poptask (can’t easily run it alone): julia\> function wait() GC.safepoint() W = Base.workqueue\_for(Threads.threadid()) Base.pop…

---

## [Improving parallel loop performance by using \`numpy\` for allocations](https://discourse.julialang.org/t/improving-parallel-loop-performance-by-using-numpy-for-allocations/122420)

<div class="topic-metadata">

**Author:** [@artemsolod](https://discourse.julialang.org/u/artemsolod)\
**Replies:** 11\
**Last updated:** [November 14, 2024, 2:58pm UTC](https://discourse.julialang.org/t/improving-parallel-loop-performance-by-using-numpy-for-allocations/122420 "2024-11-14T14:58:24Z")

</div>

This example might be interesting to help understand what performance improvement still can be made in multi-threaded worklfows. There was a related discussion on memory management in numpy not long ago Why is Julia's pe…

---

## [Why the compiler can't optimize this simple code?](https://discourse.julialang.org/t/why-the-compiler-cant-optimize-this-simple-code/122504)

<div class="topic-metadata">

**Author:** [@guoyongzhi](https://discourse.julialang.org/u/guoyongzhi)\
**Replies:** 20\
**Last updated:** [November 14, 2024, 9:07am UTC](https://discourse.julialang.org/t/why-the-compiler-cant-optimize-this-simple-code/122504 "2024-11-14T09:07:33Z")

</div>

In the following minimum example, the function f1 is optimized, but the function f2 is not. Is there any essential difficulty that hinders the compiler to do so? Can I make the setfield!(a, a.i, v) pattern faster? And h…

---

## [Push! and insert! very slow? (julia 1.11) (EDIT: No; just one-time allocations.)](https://discourse.julialang.org/t/push-and-insert-very-slow-julia-1-11-edit-no-just-one-time-allocations/122502)

<div class="topic-metadata">

**Author:** [@mlanghinrichs](https://discourse.julialang.org/u/mlanghinrichs)\
**Replies:** 21\
**Last updated:** [November 12, 2024, 5:01pm UTC](https://discourse.julialang.org/t/push-and-insert-very-slow-julia-1-11-edit-no-just-one-time-allocations/122502 "2024-11-12T17:01:46Z")

</div>

Hi all, I felt that part of my code ran slowly, and then noticed runtimes of push! and insert! on the order of µs. In contrast, other in-place methods such as deleteat! or setindex! are on the order of ns. Are these run…

---

## [How to (efficiently) filter a file/stream on-the-fly?](https://discourse.julialang.org/t/how-to-efficiently-filter-a-file-stream-on-the-fly/122457)

<div class="topic-metadata">

**Author:** [@Abhro](https://discourse.julialang.org/u/Abhro)\
**Replies:** 6\
**Last updated:** [November 12, 2024, 12:12pm UTC](https://discourse.julialang.org/t/how-to-efficiently-filter-a-file-stream-on-the-fly/122457 "2024-11-12T12:12:53Z")

</div>

I have a fixed-width output file from a Fortran program, in a well-defined matrix format, except for the occasional lines which I can regard as comments. I would like to pass the file to something like DelimitedFiles.rea…

---

## [Huge RAM usage with JumpProcesses.jl](https://discourse.julialang.org/t/huge-ram-usage-with-jumpprocesses-jl/122428)

<div class="topic-metadata">

**Author:** [@hhindley](https://discourse.julialang.org/u/hhindley)\
**Replies:** 13\
**Last updated:** [November 11, 2024, 8:18pm UTC](https://discourse.julialang.org/t/huge-ram-usage-with-jumpprocesses-jl/122428 "2024-11-11T20:18:22Z")

</div>

I am running a stochastic model using JumpProcesses.jl. The lowest consistent memory usage I can achieve is between 8-16GB with simulations that take 10-20seconds. I would assume for such an time efficient simulation the…

---

## [Efficiency of Multiple Dispatch](https://discourse.julialang.org/t/efficiency-of-multiple-dispatch/122466)

<div class="topic-metadata">

**Author:** [@hssn15](https://discourse.julialang.org/u/hssn15)\
**Replies:** 3\
**Last updated:** [November 10, 2024, 3:40pm UTC](https://discourse.julialang.org/t/efficiency-of-multiple-dispatch/122466 "2024-11-10T15:40:18Z")

</div>

Hi, I have been curious about the working principle of Multiple Dispatch since I started to Julia. So, I would like to know that, is there some kind of conditional statements in lower level of Multiple Dispatch. For exa…

---

## [Slicing array on julia 4000ms vs c++ 400ms](https://discourse.julialang.org/t/slicing-array-on-julia-4000ms-vs-c-400ms/122389)

<div class="topic-metadata">

**Author:** [@tradingtsm](https://discourse.julialang.org/u/tradingtsm)\
**Replies:** 24\
**Last updated:** [November 10, 2024, 2:17am UTC](https://discourse.julialang.org/t/slicing-array-on-julia-4000ms-vs-c-400ms/122389 "2024-11-10T02:17:04Z")

</div>

Hi everyone, I’ve trying to compare a function, on slicing an array on cpp vs julia, I get different results as I wrote on the title and I don’t understand why, would appreaciate your help. I’m using custom data for th…

---

## [LinearAlgebra.mul! for complex vectors very slow on Apple Silicon](https://discourse.julialang.org/t/linearalgebra-mul-for-complex-vectors-very-slow-on-apple-silicon/122404)

<div class="topic-metadata">

**Author:** [@goerz](https://discourse.julialang.org/u/goerz)\
**Replies:** 5\
**Last updated:** [November 8, 2024, 4:00pm UTC](https://discourse.julialang.org/t/linearalgebra-mul-for-complex-vectors-very-slow-on-apple-silicon/122404 "2024-11-08T16:00:06Z")

</div>

I usually run my computations on a Linux workstation via SSH from my MacBook. However, the specs of the recent M4 Macbook Pro would seem to promise rather extreme performance. But, just testing out basic matrix-vector m…

---

## [Is it possible to avoid these excess allocations when using @batch or @threads?](https://discourse.julialang.org/t/is-it-possible-to-avoid-these-excess-allocations-when-using-batch-or-threads/122208)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 4\
**Last updated:** [November 8, 2024, 10:37am UTC](https://discourse.julialang.org/t/is-it-possible-to-avoid-these-excess-allocations-when-using-batch-or-threads/122208 "2024-11-08T10:37:37Z")

</div>

It took some effort to come up with a short MWE for this issue. The goal is to avoid a few small allocations when mutating (an argument of an inner function) in parallel: MWEusing BenchmarkTools, Parameters, Polyester, …

---

## [How to know when objects are stack or heap allocated](https://discourse.julialang.org/t/how-to-know-when-objects-are-stack-or-heap-allocated/103056)

<div class="topic-metadata">

**Author:** [@opiateblush](https://discourse.julialang.org/u/opiateblush)\
**Replies:** 7\
**Last updated:** [November 8, 2024, 1:12am UTC](https://discourse.julialang.org/t/how-to-know-when-objects-are-stack-or-heap-allocated/103056 "2024-11-08T01:12:20Z")

</div>

I’m currently writing some performance critical code and got a bit confused about stack and heap allocation in Julia. I thought that immutables are usually stack allocated but apparently that is not the case. I’ve made a…

---

## [Spooky allocations - linked to Varargs?](https://discourse.julialang.org/t/spooky-allocations-linked-to-varargs/122373)

<div class="topic-metadata">

**Author:** [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Replies:** 8\
**Last updated:** [November 7, 2024, 4:31pm UTC](https://discourse.julialang.org/t/spooky-allocations-linked-to-varargs/122373 "2024-11-07T16:31:24Z")

</div>

Hi folks, today I found a strange behavior that eludes my understanding. Would someone please tell me where the allocations are coming from in this example? I am probably overlooking something but I have been staring at…

---

## [Implementation of Periodic Boundary Conditions](https://discourse.julialang.org/t/implementation-of-periodic-boundary-conditions/122318)

<div class="topic-metadata">

**Author:** [@priyanshuFSI](https://discourse.julialang.org/u/priyanshuFSI)\
**Replies:** 10\
**Last updated:** [November 7, 2024, 1:51pm UTC](https://discourse.julialang.org/t/implementation-of-periodic-boundary-conditions/122318 "2024-11-07T13:51:39Z")

</div>

Hi, I am writing my Finite Element Solver for CFD simulations. I encounter a what should be like an easy problem but I cant figure out how to do it. In my code, I want to account for periodic boundary conditions. For th…

---

## [Is \`empty!\` O(1)?](https://discourse.julialang.org/t/is-empty-o-1/122367)

<div class="topic-metadata">

**Author:** [@guoyongzhi](https://discourse.julialang.org/u/guoyongzhi)\
**Replies:** 4\
**Last updated:** [November 7, 2024, 12:35pm UTC](https://discourse.julialang.org/t/is-empty-o-1/122367 "2024-11-07T12:35:49Z")

</div>

The doc page says that empty! is nearly costless (and O(1)) for types that support this kind of preallocation. But the code of empty! and \_deleteend! show that it’s in O(n) complexity. The \_unsetindex! in iteration b…

---

## [A chainrule for multi-threaded map](https://discourse.julialang.org/t/a-chainrule-for-multi-threaded-map/122357)

<div class="topic-metadata">

**Author:** [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Replies:** 3\
**Last updated:** [November 7, 2024, 12:32pm UTC](https://discourse.julialang.org/t/a-chainrule-for-multi-threaded-map/122357 "2024-11-07T12:32:13Z")

</div>

Hi All, does anyone has a a chainrule for multi-threaded map? It should be “relatively” easy to implement by adapting ChainRules.jl/src/rulesets/Base/base.jl at 955941ec31aab80942658f517a2e024b3e7c812b · JuliaDiff/Chain…

---

## [Why does \`A .= sign.(view(A, diagind(A))) .\* A\` allocate?](https://discourse.julialang.org/t/why-does-a-sign-view-a-diagind-a-a-allocate/122332)

<div class="topic-metadata">

**Author:** [@zsoerenm](https://discourse.julialang.org/u/zsoerenm)\
**Replies:** 9\
**Last updated:** [November 6, 2024, 5:23pm UTC](https://discourse.julialang.org/t/why-does-a-sign-view-a-diagind-a-a-allocate/122332 "2024-11-06T17:23:47Z")

</div>

Hey, consider this function: using LinearAlgebra function correct\_sign(A) A .= sign.(view(A, diagind(A))) .\* A end Why would that allocate? Am I missing something? using BenchmarkTools B = randn(3,3) @btime correct…

---

## [Documenter.jl is not documenting any changes](https://discourse.julialang.org/t/documenter-jl-is-not-documenting-any-changes/94781)

<div class="topic-metadata">

**Author:** [@mdogan](https://discourse.julialang.org/u/mdogan)\
**Replies:** 17\
**Last updated:** [November 6, 2024, 10:41am UTC](https://discourse.julialang.org/t/documenter-jl-is-not-documenting-any-changes/94781 "2024-11-06T10:41:57Z")

</div>

I don’t know what I am doing wrong. I download the project Example.jl from GitHub. JuliaLang/Example.jl: Example Julia package repo. (github.com) I only changed the content of the Example.jl under src folder; just remo…

---

## [Are there any plans to improve the composability of @batch and/or reduce overhead of @threads?](https://discourse.julialang.org/t/are-there-any-plans-to-improve-the-composability-of-batch-and-or-reduce-overhead-of-threads/122213)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 2\
**Last updated:** [November 5, 2024, 6:09pm UTC](https://discourse.julialang.org/t/are-there-any-plans-to-improve-the-composability-of-batch-and-or-reduce-overhead-of-threads/122213 "2024-11-05T18:09:06Z")

</div>

Does it only require a lot of work? Would it require julia 2.0? Etc. This would definitely be useful info when planning projects. Related to what I learned here:

---

## [Faster conversion from boolean \`SparseMatrixCSC\` to \`BitMatrix\`](https://discourse.julialang.org/t/faster-conversion-from-boolean-sparsematrixcsc-to-bitmatrix/122016)

<div class="topic-metadata">

**Author:** [@JaredSchwartz](https://discourse.julialang.org/u/JaredSchwartz)\
**Replies:** 11\
**Last updated:** [November 5, 2024, 11:33am UTC](https://discourse.julialang.org/t/faster-conversion-from-boolean-sparsematrixcsc-to-bitmatrix/122016 "2024-11-05T11:33:04Z")

</div>

I’m running into a bottleneck in the conversion of boolean SparseMatrixCSC objects into BitMatrix objects. I’m using a view of the matrix to select the columns that need to be converted into a BitMatrix, so all rows will…

---

## [Fragile type inference in custom getproperty()](https://discourse.julialang.org/t/fragile-type-inference-in-custom-getproperty/122268)

<div class="topic-metadata">

**Author:** [@bclyons12](https://discourse.julialang.org/u/bclyons12)\
**Replies:** 1\
**Last updated:** [November 5, 2024, 2:53am UTC](https://discourse.julialang.org/t/fragile-type-inference-in-custom-getproperty/122268 "2024-11-05T02:53:02Z")

</div>

In a much larger code, we’re having some issues with type inference in a custom getproperty() function. Here’s a minimal example demonstrating at least part of the problem: mutable struct MyElement{T} name :: String…

---

## [Array of Structs vs Structs of Arrays](https://discourse.julialang.org/t/array-of-structs-vs-structs-of-arrays/122227)

<div class="topic-metadata">

**Author:** [@hssn15](https://discourse.julialang.org/u/hssn15)\
**Replies:** 1\
**Last updated:** [November 4, 2024, 3:16pm UTC](https://discourse.julialang.org/t/array-of-structs-vs-structs-of-arrays/122227 "2024-11-04T15:16:58Z")

</div>

Hi, I have a question about data storing. I am developing numerical simulator and need to store variables (temporarily) for each iterations. Those variables change in each iterations. But I am not sure what kind of sto…

---

## [Using @fastmath](https://discourse.julialang.org/t/using-fastmath/122203)

<div class="topic-metadata">

**Author:** [@hssn15](https://discourse.julialang.org/u/hssn15)\
**Replies:** 1\
**Last updated:** [November 3, 2024, 7:09pm UTC](https://discourse.julialang.org/t/using-fastmath/122203 "2024-11-03T19:09:24Z")

</div>

Hi, I have started to use @fastmath to have fast computations for polynomials. It was great when I pass Float64. But when i pass dual number (e.g. ForwardDiff.Dual(1., 1.)), i noticed that there is no any speed up. Do y…

---

## [Passing Constants into Functions as local variables vs default parameters or global constants](https://discourse.julialang.org/t/passing-constants-into-functions-as-local-variables-vs-default-parameters-or-global-constants/122177)

<div class="topic-metadata">

**Author:** [@hssn15](https://discourse.julialang.org/u/hssn15)\
**Replies:** 7\
**Last updated:** [November 3, 2024, 11:24am UTC](https://discourse.julialang.org/t/passing-constants-into-functions-as-local-variables-vs-default-parameters-or-global-constants/122177 "2024-11-03T11:24:33Z")

</div>

I am writing Module that calculates thermodynamic properties of water. Module consists of lots of functions and each function requires 34 constant values. Fortunately, those parameters are same for all functions. Curren…

---

## [\`minimum()\` 3x - 6x slower than \`numpy.min()\`](https://discourse.julialang.org/t/minimum-3x-6x-slower-than-numpy-min/121889)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 16\
**Last updated:** [November 2, 2024, 5:15pm UTC](https://discourse.julialang.org/t/minimum-3x-6x-slower-than-numpy-min/121889 "2024-11-02T17:15:20Z")

</div>

I think there are enough issues on github and nothing is moving so I’m not gonna spam there, but putting here to see if people have a temporary solution: julia\> using Chairmarks julia\> @be rand(Float32, 512000) minimum…

---

## [What's recommended literature on high-performance Julia?](https://discourse.julialang.org/t/whats-recommended-literature-on-high-performance-julia/122145)

<div class="topic-metadata">

**Author:** [@Olegg](https://discourse.julialang.org/u/Olegg)\
**Replies:** 6\
**Last updated:** [November 2, 2024, 6:31am UTC](https://discourse.julialang.org/t/whats-recommended-literature-on-high-performance-julia/122145 "2024-11-02T06:31:14Z")

</div>

There’s the book Julia High Performance: Optimizations, distributed computing, multithreading, and GPU programming with Julia 1.0 and beyond. 2nd edition from 2019. (It’s probably by @avik) Would it be useful for Julia …

---

## [Why this function involving eachslice is type unstable?](https://discourse.julialang.org/t/why-this-function-involving-eachslice-is-type-unstable/122083)

<div class="topic-metadata">

**Author:** [@Oleg\_Soloviev](https://discourse.julialang.org/u/Oleg_Soloviev)\
**Replies:** 2\
**Last updated:** [November 1, 2024, 3:46pm UTC](https://discourse.julialang.org/t/why-this-function-involving-eachslice-is-type-unstable/122083 "2024-11-01T15:46:34Z")

</div>

I need to perform iteratively some operations slicewise in a multidimensional array, and I cannot make it type stable. Here is an MWE in follow-up to the examples from eachslice is type unstable · Issue #39639 · JuliaLa…

---

## [Performance benefits of writing getters for struct fields](https://discourse.julialang.org/t/performance-benefits-of-writing-getters-for-struct-fields/122076)

<div class="topic-metadata">

**Author:** [@danrib07](https://discourse.julialang.org/u/danrib07)\
**Replies:** 2\
**Last updated:** [October 31, 2024, 3:03pm UTC](https://discourse.julialang.org/t/performance-benefits-of-writing-getters-for-struct-fields/122076 "2024-10-31T15:03:45Z")

</div>

Is there a performance benefit of writing “getter” functions for structs in Julia? For example, let’s say I define a struct and a “get” function for its field: struct Foo bar end function get\_bar(foo::Foo) retu…

---

## [A function return type of \`::AbstractArray{AbstractString}\` causes a performance penalty?](https://discourse.julialang.org/t/a-function-return-type-of-abstractarray-abstractstring-causes-a-performance-penalty/122003)

<div class="topic-metadata">

**Author:** [@Vincent\_Picaud](https://discourse.julialang.org/u/Vincent_Picaud)\
**Replies:** 15\
**Last updated:** [October 31, 2024, 9:58am UTC](https://discourse.julialang.org/t/a-function-return-type-of-abstractarray-abstractstring-causes-a-performance-penalty/122003 "2024-10-31T09:58:00Z")

</div>

For clarity reason, I sometimes annotated return type. However, I stopped when I realized this : Given: foo()::AbstractVector{AbstractString} = \[“hello”\] foo2() = \[“hello”\] fii(v) = println(eltype(v)) fii2(v) = @i…

---

## [RFC: macro for checking that a struct is concretely typed](https://discourse.julialang.org/t/rfc-macro-for-checking-that-a-struct-is-concretely-typed/122017)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 10\
**Last updated:** [October 31, 2024, 6:20am UTC](https://discourse.julialang.org/t/rfc-macro-for-checking-that-a-struct-is-concretely-typed/122017 "2024-10-31T06:20:25Z")

</div>

This week I gave a tutorial on performance in Julia and helped a few beginners optimize their code. One of the most frequent mistakes was structs with abstractly-typed fields. As a pedagogical tool, @serenity4 and I wro…

---

## [Very Slow \`DBInterface.execute\` on large duckdb relative to R](https://discourse.julialang.org/t/very-slow-dbinterface-execute-on-large-duckdb-relative-to-r/121984)

<div class="topic-metadata">

**Author:** [@floswald](https://discourse.julialang.org/u/floswald)\
**Replies:** 4\
**Last updated:** [October 30, 2024, 9:11pm UTC](https://discourse.julialang.org/t/very-slow-dbinterface-execute-on-large-duckdb-relative-to-r/121984 "2024-10-30T21:11:59Z")

</div>

Hi all, I’ve made a clone of @grantmcdermott 's nice workshop on duckdb and polars - adding a chapter on julia and duckdb. He had pointed out some very slow julia timings in his slides, and actually created an issue on …

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

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