# Performance

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

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

**Page:** 27

---

## [What the differences of the 6 solutions please](https://discourse.julialang.org/t/what-the-differences-of-the-6-solutions-please/112300)

<div class="topic-metadata">

**Author:** [@ajsagit](https://discourse.julialang.org/u/ajsagit)\
**Replies:** 6\
**Last updated:** [March 31, 2024, 5:51pm UTC](https://discourse.julialang.org/t/what-the-differences-of-the-6-solutions-please/112300 "2024-03-31T17:51:41Z")

</div>

using BenchmarkTools datasize = 10000000 data = randn(Float32, datasize) #recip\_vector = similar(data, Float32) recip\_vector = similar(data) # 1）0.007099 seconds (1 allocation: 32 bytes) @timev recip\_vector .= 1 ./ dat…

---

## [Possible to speed up this function for calculating cartesian indices?](https://discourse.julialang.org/t/possible-to-speed-up-this-function-for-calculating-cartesian-indices/112333)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 19\
**Last updated:** [March 31, 2024, 5:08pm UTC](https://discourse.julialang.org/t/possible-to-speed-up-this-function-for-calculating-cartesian-indices/112333 "2024-03-31T17:08:23Z")

</div>

Hello! I have a small function which I call a lot: function BatchExtractCells!(Cells, Points, CutOff) @batch per=thread for i ∈ eachindex(Cells) ci = CartesianIndex(@. Int(fld(Points\[i\], CutOff))...) …

---

## [Slow and Memory intensive For Loop](https://discourse.julialang.org/t/slow-and-memory-intensive-for-loop/112304)

<div class="topic-metadata">

**Author:** [@soumen261](https://discourse.julialang.org/u/soumen261)\
**Replies:** 6\
**Last updated:** [March 30, 2024, 10:44pm UTC](https://discourse.julialang.org/t/slow-and-memory-intensive-for-loop/112304 "2024-03-30T22:44:51Z")

</div>

Hi Julians, I am still a novice in Julia. I am writing a code to import/read a total 16 data (.txt) files each having 504\*1025 matrix. Essentially trying to make a 3D data cube from the 2D datasets using a For loop. But…

---

## [Type stability and heterogeneous collections](https://discourse.julialang.org/t/type-stability-and-heterogeneous-collections/112293)

<div class="topic-metadata">

**Author:** [@andreapasquale94](https://discourse.julialang.org/u/andreapasquale94)\
**Replies:** 5\
**Last updated:** [March 29, 2024, 5:36pm UTC](https://discourse.julialang.org/t/type-stability-and-heterogeneous-collections/112293 "2024-03-29T17:36:09Z")

</div>

I am working on a library where I cannot avoid heterogeneous collections, and I want type-stable code. I’m trying to improve my understanding of how the compiler behaves in those cases (and in general). There are alrea…

---

## [How to speed up dense-sparse matrix multiplication where the sparse matrix is in CSC?](https://discourse.julialang.org/t/how-to-speed-up-dense-sparse-matrix-multiplication-where-the-sparse-matrix-is-in-csc/112260)

<div class="topic-metadata">

**Author:** [@yhuang](https://discourse.julialang.org/u/yhuang)\
**Replies:** 0\
**Last updated:** [March 28, 2024, 11:32pm UTC](https://discourse.julialang.org/t/how-to-speed-up-dense-sparse-matrix-multiplication-where-the-sparse-matrix-is-in-csc/112260 "2024-03-28T23:32:14Z")

</div>

For a sparse matrix stored in CSC format, without using MKLSparse, left multiplying it by a dense matrix is faster than right multiplying it by a dense matrix. This is quite intuitive because the sparse matrix is in CSC,…

---

## [More allocation in for loop than broadcast](https://discourse.julialang.org/t/more-allocation-in-for-loop-than-broadcast/112257)

<div class="topic-metadata">

**Author:** [@yuehao](https://discourse.julialang.org/u/yuehao)\
**Replies:** 4\
**Last updated:** [March 28, 2024, 11:09pm UTC](https://discourse.julialang.org/t/more-allocation-in-for-loop-than-broadcast/112257 "2024-03-28T23:09:12Z")

</div>

I am new to Julia and writing a simulation code to track the particle motion. Here is a simplified version of my code: using BenchmarkTools using StructArrays using StaticArrays struct ps3d # 6D phase space x::Flo…

---

## [What is the fastest way to find if a real nonsquare matrix is injective?](https://discourse.julialang.org/t/what-is-the-fastest-way-to-find-if-a-real-nonsquare-matrix-is-injective/112176)

<div class="topic-metadata">

**Author:** [@marcsgil](https://discourse.julialang.org/u/marcsgil)\
**Replies:** 8\
**Last updated:** [March 27, 2024, 4:57pm UTC](https://discourse.julialang.org/t/what-is-the-fastest-way-to-find-if-a-real-nonsquare-matrix-is-injective/112176 "2024-03-27T16:57:00Z")

</div>

Hello guys! The title says all. I have a certain M\\times N real valued matrix A and I would like to know if it is injective. What would be the fastest way to accomplish that? I know that I could calculate the determinan…

---

## [Is it possible to define a type-stable function that returns a Plots.Plot object?](https://discourse.julialang.org/t/is-it-possible-to-define-a-type-stable-function-that-returns-a-plots-plot-object/112172)

<div class="topic-metadata">

**Author:** [@Shayan](https://discourse.julialang.org/u/Shayan)\
**Replies:** 3\
**Last updated:** [March 27, 2024, 1:24pm UTC](https://discourse.julialang.org/t/is-it-possible-to-define-a-type-stable-function-that-returns-a-plots-plot-object/112172 "2024-03-27T13:24:54Z")

</div>

Is it possible to define a type stable function that returns a Plots.plot object? Minimal reproducible example: using Plots function mplot(vec::AbstractVector) plot(vec) end @code\_warntype mplot(rand(10)) returns …

---

## [Peculiar Issue: The same function when defined in a package is 10x slower](https://discourse.julialang.org/t/peculiar-issue-the-same-function-when-defined-in-a-package-is-10x-slower/112110)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 1\
**Last updated:** [March 26, 2024, 12:19am UTC](https://discourse.julialang.org/t/peculiar-issue-the-same-function-when-defined-in-a-package-is-10x-slower/112110 "2024-03-26T00:19:57Z")

</div>

Hello! I do not have a MWE since it is something I have spotted in developing a nested package. What I noticed is that if I have a function such as; function SPHExample.ComputeInteractions!(Position, Kernel, KernelGrad…

---

## [How to speed up this Kronecker Multiplication?](https://discourse.julialang.org/t/how-to-speed-up-this-kronecker-multiplication/112063)

<div class="topic-metadata">

**Author:** [@vikram\_backup](https://discourse.julialang.org/u/vikram_backup)\
**Replies:** 7\
**Last updated:** [March 25, 2024, 7:21am UTC](https://discourse.julialang.org/t/how-to-speed-up-this-kronecker-multiplication/112063 "2024-03-25T07:21:06Z")

</div>

I am writing a code that gives me tensor product of the required Pauli matrices, and I am doing this using kron function. using StaticArrays #%% We are definig the Pauli matrices here. σˣ=SA\[0 1.0; 1 0\] #\\sigma^x σᶻ=…

---

## [Performance of persistent variables](https://discourse.julialang.org/t/performance-of-persistent-variables/112044)

<div class="topic-metadata">

**Author:** [@c\_sell](https://discourse.julialang.org/u/c_sell)\
**Replies:** 0\
**Last updated:** [March 24, 2024, 4:33pm UTC](https://discourse.julialang.org/t/performance-of-persistent-variables/112044 "2024-03-24T16:33:09Z")

</div>

Hello, I have a simple toy example in which I compare two methods of creating persistent variables. In my case, both methods exhibit identical performance. Are there any differences to consider regarding safety, compil…

---

## [Why does sortperm! allocate here?](https://discourse.julialang.org/t/why-does-sortperm-allocate-here/112028)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 4\
**Last updated:** [March 24, 2024, 1:47pm UTC](https://discourse.julialang.org/t/why-does-sortperm-allocate-here/112028 "2024-03-24T13:47:39Z")

</div>

Hello! I think I am missing something really simple, I just don’t get why allocations occur, when I have preallocated index array. function main() Cartesians = Vector{CartesianIndex{2}}(undef, 100) SortedInd…

---

## [Modeling deformation in Julia](https://discourse.julialang.org/t/modeling-deformation-in-julia/111941)

<div class="topic-metadata">

**Author:** [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Replies:** 4\
**Last updated:** [March 23, 2024, 11:58pm UTC](https://discourse.julialang.org/t/modeling-deformation-in-julia/111941 "2024-03-23T23:58:50Z")

</div>

Hi everyone, a general question here about Finite elements in Julia. I am trying to do something rather “simple”. Imaging a large body (3D), fully constrained. In side there is a fault/fracture/weak zone inside. There …

---

## [Deepcopy() of Dict has same mallocs as deepcopy() of Vector inside mutable Struct](https://discourse.julialang.org/t/deepcopy-of-dict-has-same-mallocs-as-deepcopy-of-vector-inside-mutable-struct/53420)

<div class="topic-metadata">

**Author:** [@bsuwal](https://discourse.julialang.org/u/bsuwal)\
**Replies:** 1\
**Last updated:** [March 23, 2024, 11:03pm UTC](https://discourse.julialang.org/t/deepcopy-of-dict-has-same-mallocs-as-deepcopy-of-vector-inside-mutable-struct/53420 "2024-03-23T23:03:22Z")

</div>

I had a struct that had a Dict as one of its fields. I deepcopy the struct objects a lot, and that was the bottleneck in the program. I then realized that I could replace the Dict with a Vector, which I know has a smalle…

---

## [Does calling a function with no memory allocations create an allocation?](https://discourse.julialang.org/t/does-calling-a-function-with-no-memory-allocations-create-an-allocation/111987)

<div class="topic-metadata">

**Author:** [@OmerPaz](https://discourse.julialang.org/u/OmerPaz)\
**Replies:** 5\
**Last updated:** [March 22, 2024, 7:54pm UTC](https://discourse.julialang.org/t/does-calling-a-function-with-no-memory-allocations-create-an-allocation/111987 "2024-03-22T19:54:47Z")

</div>

Hi all, I am running a numerical simulation in which I document my results in a pre-allocated structure, Obs: mutable struct Obs{T} name::String data::Array{T} num\_of\_measure::Int64 c\_num\_of\_measure::In…

---

## [Help understand boxing](https://discourse.julialang.org/t/help-understand-boxing/111829)

<div class="topic-metadata">

**Author:** [@jlamb](https://discourse.julialang.org/u/jlamb)\
**Replies:** 17\
**Last updated:** [March 22, 2024, 10:21am UTC](https://discourse.julialang.org/t/help-understand-boxing/111829 "2024-03-22T10:21:37Z")

</div>

I am trying to resolve a type stability problem in a function where some local variables are showing up as the type Core.Box when I run @code\_warntype. I’ve narrowed the cause to where I use a comprehension or generator …

---

## [How to return a non-allocating view from a function?](https://discourse.julialang.org/t/how-to-return-a-non-allocating-view-from-a-function/111946)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 3\
**Last updated:** [March 21, 2024, 8:11pm UTC](https://discourse.julialang.org/t/how-to-return-a-non-allocating-view-from-a-function/111946 "2024-03-21T20:11:39Z")

</div>

Hello! I have a function in which I do a small amount of operations, before returning a view of the final result as such: # some operations .. ParticleRanges = view(ParticleSplitterLinearIndices, ParticleSplitt…

---

## [Memory allocation in recursion](https://discourse.julialang.org/t/memory-allocation-in-recursion/111929)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 11\
**Last updated:** [March 21, 2024, 8:08pm UTC](https://discourse.julialang.org/t/memory-allocation-in-recursion/111929 "2024-03-21T20:08:27Z")

</div>

Does Julia allocate memory when recursing? I see a ton of memory allocation in a recursive quicksort…

---

## [Recursion in Julia — bad idea?](https://discourse.julialang.org/t/recursion-in-julia-bad-idea/99304)

<div class="topic-metadata">

**Author:** [@rgu](https://discourse.julialang.org/u/rgu)\
**Replies:** 13\
**Last updated:** [May 24, 2023, 1:26pm UTC](https://discourse.julialang.org/t/recursion-in-julia-bad-idea/99304 "2023-05-24T13:26:22Z")

</div>

I’m trying to learn Julia on examples. For now I’m trying to solve some problem with DFS as a core algorithm in my solution. This recursive DFS is running on a max 1000×1000 grid and I’ve got StackOverFlow (I’m pretty s…

---

## [JSON3 to struct, how to improve deserialization performance?](https://discourse.julialang.org/t/json3-to-struct-how-to-improve-deserialization-performance/111667)

<div class="topic-metadata">

**Author:** [@Babiole](https://discourse.julialang.org/u/Babiole)\
**Replies:** 6\
**Last updated:** [March 20, 2024, 8:39am UTC](https://discourse.julialang.org/t/json3-to-struct-how-to-improve-deserialization-performance/111667 "2024-03-20T08:39:55Z")

</div>

Hi, I’m trying to create an application to distribute, this application is loading a JSON configuration file. Since I wanted a one to one binding between the application data and the JSON I’m using the JSON3 package. H…

---

## [Weird fluctuation in running time](https://discourse.julialang.org/t/weird-fluctuation-in-running-time/111818)

<div class="topic-metadata">

**Author:** [@grero](https://discourse.julialang.org/u/grero)\
**Replies:** 2\
**Last updated:** [March 20, 2024, 1:00am UTC](https://discourse.julialang.org/t/weird-fluctuation-in-running-time/111818 "2024-03-20T01:00:08Z")

</div>

I’ve been observing a weird behaviour with a piece of code I’ve been working on. The running time, as returned by BenchmarkTools, will suddenly jump from around 60ms to over a minute. Once that happens, the running time …

---

## [Threading behavior on multiple-cpu systems](https://discourse.julialang.org/t/threading-behavior-on-multiple-cpu-systems/111780)

<div class="topic-metadata">

**Author:** [@astro-kevin](https://discourse.julialang.org/u/astro-kevin)\
**Replies:** 1\
**Last updated:** [March 18, 2024, 4:53pm UTC](https://discourse.julialang.org/t/threading-behavior-on-multiple-cpu-systems/111780 "2024-03-18T16:53:09Z")

</div>

I have written some code which runs faster on a system with 2x16 core intel chip than a system with a 4x16 core AMD cpu. The AMD cpu is of a slightly slower clockspeed, and I have ensured my Threading.@threads loop has m…

---

## [Abstract - Programming Parallel Computers with Julia](https://discourse.julialang.org/t/abstract-programming-parallel-computers-with-julia/111326)

<div class="topic-metadata">

**Author:** [@benslinux](https://discourse.julialang.org/u/benslinux)\
**Replies:** 1\
**Last updated:** [March 17, 2024, 4:04pm UTC](https://discourse.julialang.org/t/abstract-programming-parallel-computers-with-julia/111326 "2024-03-17T16:04:28Z")

</div>

Came upon this abstract while investigating whether the Julia language had ever been applied in attempting to solve the ‘Three Body Problem’ - though this paper doesn’t address that, it’s interesting in that it really pu…

---

## [Discussion about DateTime from POSIX timestamp. Was (incorrect assumption): Dates in Windows - error in datetime from posix](https://discourse.julialang.org/t/discussion-about-datetime-from-posix-timestamp-was-incorrect-assumption-dates-in-windows-error-in-datetime-from-posix/111691)

<div class="topic-metadata">

**Author:** [@kodintent](https://discourse.julialang.org/u/kodintent)\
**Replies:** 9\
**Last updated:** [March 16, 2024, 5:21pm UTC](https://discourse.julialang.org/t/discussion-about-datetime-from-posix-timestamp-was-incorrect-assumption-dates-in-windows-error-in-datetime-from-posix/111691 "2024-03-16T17:21:51Z")

</div>

Hi. I didnt copy old known-working code, i did something else. here is how to get the correct value, provided by an answer below. datetime\_utc\_from\_posix = unix2datetime(posix\_int) \[ below is NOT how to get the corre…

---

## [Julia speed](https://discourse.julialang.org/t/julia-speed/111511)

<div class="topic-metadata">

**Author:** [@peDurand](https://discourse.julialang.org/u/peDurand)\
**Replies:** 28\
**Last updated:** [March 14, 2024, 8:17pm UTC](https://discourse.julialang.org/t/julia-speed/111511 "2024-03-14T20:17:00Z")

</div>

Hello ! I teach computational Physics in a french university. I learn to my students to code in Modern Fortran and Python. I know that many people claim that Julia may be as fast as C or Fortran. So, I try a little test…

---

## [Dictionarys on the GPU for Agents.jl](https://discourse.julialang.org/t/dictionarys-on-the-gpu-for-agents-jl/111233)

<div class="topic-metadata">

**Author:** [@Kemper](https://discourse.julialang.org/u/Kemper)\
**Replies:** 4\
**Last updated:** [March 13, 2024, 3:37pm UTC](https://discourse.julialang.org/t/dictionarys-on-the-gpu-for-agents-jl/111233 "2024-03-13T15:37:23Z")

</div>

Hello! I am working on an Agent Based Model with the Agents.jl framework and I am having performance problems. I am working with dictonarys to save positions and values. Is there a way to work with dictonaries on the G…

---

## [Reorder dictionary keys](https://discourse.julialang.org/t/reorder-dictionary-keys/111547)

<div class="topic-metadata">

**Author:** [@Sandy45](https://discourse.julialang.org/u/Sandy45)\
**Replies:** 8\
**Last updated:** [March 13, 2024, 6:58am UTC](https://discourse.julialang.org/t/reorder-dictionary-keys/111547 "2024-03-13T06:58:43Z")

</div>

I have dictionary in below format and would like to check if we have any existing methos that can reorder dictionary if we provide the array with the key names in desired order? I would like to see my final dictionary i…

---

## [Problem changing value of a fixed variable in a function](https://discourse.julialang.org/t/problem-changing-value-of-a-fixed-variable-in-a-function/111325)

<div class="topic-metadata">

**Author:** [@clopen](https://discourse.julialang.org/u/clopen)\
**Replies:** 12\
**Last updated:** [March 12, 2024, 7:04pm UTC](https://discourse.julialang.org/t/problem-changing-value-of-a-fixed-variable-in-a-function/111325 "2024-03-12T19:04:11Z")

</div>

Hello, I am new to programming in Julia and currently working on transitioning code from Fortran to Julia. In a file called codeA.jl, I have declared several variables, some of which are utilized as parameters within a …

---

## [Integrating network of particles+springs with varying number of particles](https://discourse.julialang.org/t/integrating-network-of-particles-springs-with-varying-number-of-particles/111482)

<div class="topic-metadata">

**Author:** [@70Gage70](https://discourse.julialang.org/u/70Gage70)\
**Replies:** 7\
**Last updated:** [March 12, 2024, 4:06pm UTC](https://discourse.julialang.org/t/integrating-network-of-particles-springs-with-varying-number-of-particles/111482 "2024-03-12T16:06:57Z")

</div>

This is a mwe of code which integrates a network of ~100 - ~1000 interacting particles that can grow and die. In general, the connections are arbitrary and growth/death has logic but here I just connect every particle an…

---

## [Failed to remove pidfile on close](https://discourse.julialang.org/t/failed-to-remove-pidfile-on-close/111497)

<div class="topic-metadata">

**Author:** [@math\_opt](https://discourse.julialang.org/u/math_opt)\
**Replies:** 0\
**Last updated:** [March 12, 2024, 1:38am UTC](https://discourse.julialang.org/t/failed-to-remove-pidfile-on-close/111497 "2024-03-12T01:38:53Z")

</div>

I am trying to run a Julia script on a Linux cluster, and I see the following warning/error. I use Distributed.jl package to addprocs. It would be helpful if someone could point at the exact cause and help resolve it! …

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

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