# Performance

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

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

**Page:** 34

---

## [Optimizing counting number of occurrences of a given number in an array](https://discourse.julialang.org/t/optimizing-counting-number-of-occurrences-of-a-given-number-in-an-array/106418)

<div class="topic-metadata">

**Author:** [@vkv](https://discourse.julialang.org/u/vkv)\
**Replies:** 10\
**Last updated:** [November 19, 2023, 6:47pm UTC](https://discourse.julialang.org/t/optimizing-counting-number-of-occurrences-of-a-given-number-in-an-array/106418 "2023-11-19T18:47:09Z")

</div>

Is there a way to optimize the counter function? I’ve tried using LoopVectorization it complained saying ERROR: LoadError: Don't know how to handle expression. …

---

## [Speeding up \`fit(Histogram)\`](https://discourse.julialang.org/t/speeding-up-fit-histogram/106355)

<div class="topic-metadata">

**Author:** [@Dan](https://discourse.julialang.org/u/Dan)\
**Replies:** 10\
**Last updated:** [November 17, 2023, 4:48pm UTC](https://discourse.julialang.org/t/speeding-up-fit-histogram/106355 "2023-11-17T16:48:19Z")

</div>

As an offshoot of a thread about Makie histograms, I’ve tried to benchmark StatsBase fit(Histogtam) like so: julia\> using StatsBase julia\> @btime fit(Histogram, v, 0.0:0.1:1.0) setup=(Random.seed!(1234); v = rand(1\_000…

---

## [Performance Report: Effect of Reading CSV file on Mergeing two DataFrames](https://discourse.julialang.org/t/performance-report-effect-of-reading-csv-file-on-mergeing-two-dataframes/106304)

<div class="topic-metadata">

**Author:** [@Sourish](https://discourse.julialang.org/u/Sourish)\
**Replies:** 18\
**Last updated:** [November 17, 2023, 4:37pm UTC](https://discourse.julialang.org/t/performance-report-effect-of-reading-csv-file-on-mergeing-two-dataframes/106304 "2023-11-17T16:37:33Z")

</div>

Hi I was trying to merge two data frames - but I realised how we read the csv files - that is going to have a bearing on the same merge function. using DataFrames, CSV, FileIO, CSVFiles, PyCall, BenchmarkTools diamonds…

---

## [Sum of tuples are slow](https://discourse.julialang.org/t/sum-of-tuples-are-slow/38541)

<div class="topic-metadata">

**Author:** [@tfr](https://discourse.julialang.org/u/tfr)\
**Replies:** 12\
**Last updated:** [November 17, 2023, 2:45pm UTC](https://discourse.julialang.org/t/sum-of-tuples-are-slow/38541 "2023-11-17T14:45:39Z")

</div>

I did the following tests using BenchmarkTools a = collect(1: 100) a\_tuple = Tuple(a) @benchmark sum($a) @benchmark sum($a\_tuple) For the array a the output is BenchmarkTools.Trial: memory estimate: 0 bytes allo…

---

## [Improve speed of vector-jacobian product](https://discourse.julialang.org/t/improve-speed-of-vector-jacobian-product/106312)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 2\
**Last updated:** [November 16, 2023, 6:31pm UTC](https://discourse.julialang.org/t/improve-speed-of-vector-jacobian-product/106312 "2023-11-16T18:31:59Z")

</div>

Hi, I would like to improve some part of a code which relies on vector-jacobian product (vjp), ie computing the action of the adjoint of an operator. On my computer, the computation of vjp is ~100x slower than the evalu…

---

## [Why does b \*= A\[r\] allocate memory?](https://discourse.julialang.org/t/why-does-b-a-r-allocate-memory/106279)

<div class="topic-metadata">

**Author:** [@Christopher\_White](https://discourse.julialang.org/u/Christopher_White)\
**Replies:** 6\
**Last updated:** [November 15, 2023, 9:29pm UTC](https://discourse.julialang.org/t/why-does-b-a-r-allocate-memory/106279 "2023-11-15T21:29:32Z")

</div>

The following code does a whole bunch of allocations: N = 10000000 A = randn(Float64, N) b = 1.0 @show typeof(b) @time for r = 1:N b \*= A\[r\] end Why is that? How can I write this in a way that doesn’t allocate ~ a…

---

## [Translation of traditional ML models to neural network framework for acceleration?](https://discourse.julialang.org/t/translation-of-traditional-ml-models-to-neural-network-framework-for-acceleration/105986)

<div class="topic-metadata">

**Author:** [@FredrikKarlssonSpeec](https://discourse.julialang.org/u/FredrikKarlssonSpeec)\
**Replies:** 5\
**Last updated:** [November 14, 2023, 10:52am UTC](https://discourse.julialang.org/t/translation-of-traditional-ml-models-to-neural-network-framework-for-acceleration/105986 "2023-11-14T10:52:53Z")

</div>

Hi, This is maybe a stupid question for which the answer is already in the docs of one of the ML / NN frameworks, but are there efforts within the Julia community to do what the Hummingbird python package is attempting …

---

## [Performance issue with multithreaded computation with matrix operations at its heart (Threads.@threads vs. BLAS threads)](https://discourse.julialang.org/t/performance-issue-with-multithreaded-computation-with-matrix-operations-at-its-heart-threads-threads-vs-blas-threads/106043)

<div class="topic-metadata">

**Author:** [@HanD](https://discourse.julialang.org/u/HanD)\
**Replies:** 7\
**Last updated:** [November 13, 2023, 5:00pm UTC](https://discourse.julialang.org/t/performance-issue-with-multithreaded-computation-with-matrix-operations-at-its-heart-threads-threads-vs-blas-threads/106043 "2023-11-13T17:00:05Z")

</div>

While trying to speed up a long computation with chunking more threads on it, I ran into an interesting problem. I found several related threads here, but I couldn’t find a convincing answer, nor a solution to my issue. …

---

## [Optimizing dynamical system in a network](https://discourse.julialang.org/t/optimizing-dynamical-system-in-a-network/106034)

<div class="topic-metadata">

**Author:** [@VictorSeven](https://discourse.julialang.org/u/VictorSeven)\
**Replies:** 15\
**Last updated:** [November 13, 2023, 1:35pm UTC](https://discourse.julialang.org/t/optimizing-dynamical-system-in-a-network/106034 "2023-11-13T13:35:02Z")

</div>

Hi, I am trying to integrate a simple dynamical system on a network, which is represented by an adjacency matrix. Note that the network in this case is dense and hence I am using the full matrix for it. Initially I wrot…

---

## [Static Arrays Memory & Allocations](https://discourse.julialang.org/t/static-arrays-memory-allocations/106110)

<div class="topic-metadata">

**Author:** [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Replies:** 15\
**Last updated:** [November 12, 2023, 6:56pm UTC](https://discourse.julialang.org/t/static-arrays-memory-allocations/106110 "2023-11-12T18:56:15Z")

</div>

Below two functions function generateLocalMatrixWorks(element::Element) h = element.area Iloc = SVector(element.e1, element.e1, element.e2, element.e2) Jloc = SVector(element.e1, element.e2, element.e1, elemen…

---

## [Broadcasting call to a vector-valued function](https://discourse.julialang.org/t/broadcasting-call-to-a-vector-valued-function/106056)

<div class="topic-metadata">

**Author:** [@elenev](https://discourse.julialang.org/u/elenev)\
**Replies:** 4\
**Last updated:** [November 11, 2023, 1:55am UTC](https://discourse.julialang.org/t/broadcasting-call-to-a-vector-valued-function/106056 "2023-11-11T01:55:38Z")

</div>

What is the most julian way to broadcast a call to a vector-valued function? For example, take the following function. function return\_vec(x) return \[x, x^2\] end I would like to collect outputs for each x in 1:15 …

---

## [Taking advantage of Apple M1?](https://discourse.julialang.org/t/taking-advantage-of-apple-m1/93310)

<div class="topic-metadata">

**Author:** [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Replies:** 27\
**Last updated:** [November 10, 2023, 8:45pm UTC](https://discourse.julialang.org/t/taking-advantage-of-apple-m1/93310 "2023-11-10T20:45:31Z")

</div>

Hi all. So, I got my new laptop with a Apple M1 chip. I have heard is great. I wonder how are you guys taking advange of it and its cores/GPU. How do you start Julia, use Metal.jl, and other tips to speed up processes. …

---

## [Why does \`mul!(u, A, v)\` allocate when \`A\` is sparse and \`u, v\` are views?](https://discourse.julialang.org/t/why-does-mul-u-a-v-allocate-when-a-is-sparse-and-u-v-are-views/105995)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 9\
**Last updated:** [November 10, 2023, 12:04pm UTC](https://discourse.julialang.org/t/why-does-mul-u-a-v-allocate-when-a-is-sparse-and-u-v-are-views/105995 "2023-11-10T12:04:42Z")

</div>

I’m wondering if there is a way to avoid allocations in the following scenario: julia\> using BenchmarkTools, LinearAlgebra, SparseArrays julia\> A = sprand(2, 3, 0.5); julia\> u, v = rand(2), rand(3); julia\> @btime mul…

---

## [Reduce memory allocated in array view and in place sum](https://discourse.julialang.org/t/reduce-memory-allocated-in-array-view-and-in-place-sum/105974)

<div class="topic-metadata">

**Author:** [@ian](https://discourse.julialang.org/u/ian)\
**Replies:** 12\
**Last updated:** [November 10, 2023, 3:01am UTC](https://discourse.julialang.org/t/reduce-memory-allocated-in-array-view-and-in-place-sum/105974 "2023-11-10T03:01:18Z")

</div>

Hi all. New Julia user here. I want to significantly increase performance/reduce the amount of memory allocated in a function similar to the MWE below. Basically I need to access the elements of an array (sliced using a …

---

## [Type Inference Issues in IterativeSolvers with LinearMaps](https://discourse.julialang.org/t/type-inference-issues-in-iterativesolvers-with-linearmaps/106007)

<div class="topic-metadata">

**Author:** [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Replies:** 2\
**Last updated:** [November 9, 2023, 8:07pm UTC](https://discourse.julialang.org/t/type-inference-issues-in-iterativesolvers-with-linearmaps/106007 "2023-11-09T20:07:53Z")

</div>

I was trying to improve the performance of a program I use that makes heavy use of implicit time stepping, which results in me solving linear systems of equations ‘Ax=b’. Because of things that have to do with my specifi…

---

## [Mutable ProtoStruct beats Base Mutable Struct in microbenchmark...and then it is much slower in real program](https://discourse.julialang.org/t/mutable-protostruct-beats-base-mutable-struct-in-microbenchmark-and-then-it-is-much-slower-in-real-program/105982)

<div class="topic-metadata">

**Author:** [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Replies:** 9\
**Last updated:** [November 9, 2023, 5:21pm UTC](https://discourse.julialang.org/t/mutable-protostruct-beats-base-mutable-struct-in-microbenchmark-and-then-it-is-much-slower-in-real-program/105982 "2023-11-09T17:21:12Z")

</div>

I developed a bit the ProtoStructs.jl package recently and I managed to improve the performance of the implementation, but there is something I don’t understand why is happening: microbenchmarks seems to lie with julia\>…

---

## [Setting the display order of entries in (unordered) Dict](https://discourse.julialang.org/t/setting-the-display-order-of-entries-in-unordered-dict/105954)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 2\
**Last updated:** [November 8, 2023, 6:46pm UTC](https://discourse.julialang.org/t/setting-the-display-order-of-entries-in-unordered-dict/105954 "2023-11-08T18:46:48Z")

</div>

Is there a way to designate what order the pairs of a Julai dictionary are displayed in (without using OrderedDict)? Elaboration: StructuralIdentifiability.jl takes a model, and assesses the identifiability of each para…

---

## [Help fixing a huge amount of rerecompilation time when using ODBC.jl](https://discourse.julialang.org/t/help-fixing-a-huge-amount-of-rerecompilation-time-when-using-odbc-jl/105946)

<div class="topic-metadata">

**Author:** [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Replies:** 6\
**Last updated:** [November 8, 2023, 6:06pm UTC](https://discourse.julialang.org/t/help-fixing-a-huge-amount-of-rerecompilation-time-when-using-odbc-jl/105946 "2023-11-08T18:06:17Z")

</div>

Hi! We use everyday the ODBC.jl package to fetch satellite telemetries from our database and perform some automatic analysis. However, since Julia v1.9, we are experiencing a huge precompilation time. The first SQL exec…

---

## [GC occurs at the worst time in tight loop (Garbage Collection)](https://discourse.julialang.org/t/gc-occurs-at-the-worst-time-in-tight-loop-garbage-collection/104934)

<div class="topic-metadata">

**Author:** [@Allan\_Baker](https://discourse.julialang.org/u/Allan_Baker)\
**Replies:** 93\
**Last updated:** [November 7, 2023, 4:36pm UTC](https://discourse.julialang.org/t/gc-occurs-at-the-worst-time-in-tight-loop-garbage-collection/104934 "2023-11-07T16:36:34Z")

</div>

I have julia code which I’ve compiled into a C-library. We intend to run this on a real-time system to test some hardware. When I run a test on the function call in julia using the BenchmarkTools. The @benchmarks look…

---

## [SIMD struggles, seeking solutions (with KangarooTwelve.jl)](https://discourse.julialang.org/t/simd-struggles-seeking-solutions-with-kangarootwelve-jl/105800)

<div class="topic-metadata">

**Author:** [@tecosaur](https://discourse.julialang.org/u/tecosaur)\
**Replies:** 23\
**Last updated:** [November 7, 2023, 11:38am UTC](https://discourse.julialang.org/t/simd-struggles-seeking-solutions-with-kangarootwelve-jl/105800 "2023-11-07T11:38:11Z")

</div>

A bit ago I mentioned a new hashing library I have been working on: After a huge amount of effort, I’ve just managed to make the “simple” single-threaded version (k12\_singlethreaded) zero-alloc and only off the C perf…

---

## [\[Documenter\] docstrings not included in the manual](https://discourse.julialang.org/t/documenter-docstrings-not-included-in-the-manual/70299)

<div class="topic-metadata">

**Author:** [@sami1](https://discourse.julialang.org/u/sami1)\
**Replies:** 1\
**Last updated:** [November 5, 2023, 8:55am UTC](https://discourse.julialang.org/t/documenter-docstrings-not-included-in-the-manual/70299 "2023-11-05T08:55:10Z")

</div>

Hi, I’m developing a bridge sampling package and I’m struggling with automatizing the documentation. When I run make.jl, the docstrings are actually detected but I get this warning : 1 docstring not included in the manu…

---

## [Funny Benchmark with Julia (no longer) at the bottom](https://discourse.julialang.org/t/funny-benchmark-with-julia-no-longer-at-the-bottom/104611)

<div class="topic-metadata">

**Author:** [@algunion](https://discourse.julialang.org/u/algunion)\
**Replies:** 149\
**Last updated:** [November 4, 2023, 1:32pm UTC](https://discourse.julialang.org/t/funny-benchmark-with-julia-no-longer-at-the-bottom/104611 "2023-11-04T13:32:17Z")

</div>

A. S. To prevent any confusion: at the time when this was originally posted, Julia’s run was about 600ms and was ~20x slower than Rust. This is not longer the case. Resuming the original post… … → I stumbled upon thi…

---

## [Code optimization using SIMD or LoopVectorization](https://discourse.julialang.org/t/code-optimization-using-simd-or-loopvectorization/105782)

<div class="topic-metadata">

**Author:** [@Lian\_Yunlong](https://discourse.julialang.org/u/Lian_Yunlong)\
**Replies:** 7\
**Last updated:** [November 4, 2023, 7:13am UTC](https://discourse.julialang.org/t/code-optimization-using-simd-or-loopvectorization/105782 "2023-11-04T07:13:21Z")

</div>

Dear Julia experts, I have implemented the probability density function for the Pearson-IV distribution. This implementation is based on the R-package “PearsonDS”. Here is the code: import SpecialFunctions: lgamma, gam…

---

## [What is happening with the nightly precompile cache?](https://discourse.julialang.org/t/what-is-happening-with-the-nightly-precompile-cache/105736)

<div class="topic-metadata">

**Author:** [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Replies:** 1\
**Last updated:** [November 3, 2023, 3:39pm UTC](https://discourse.julialang.org/t/what-is-happening-with-the-nightly-precompile-cache/105736 "2023-11-03T15:39:18Z")

</div>

In every update I do I see the pre-compile cache file increase size. Just did now and the cache file grew 14 MB from what it was from a version with 5 days. For GMT (with a reduced number of pre-compile cases than last r…

---

## [Avoid Dynamic Dispatch](https://discourse.julialang.org/t/avoid-dynamic-dispatch/105685)

<div class="topic-metadata">

**Author:** [@AlexanderNenninger](https://discourse.julialang.org/u/AlexanderNenninger)\
**Replies:** 2\
**Last updated:** [November 2, 2023, 11:05am UTC](https://discourse.julialang.org/t/avoid-dynamic-dispatch/105685 "2023-11-02T11:05:09Z")

</div>

For some tensor operations I need to keep track of partial indices and call out to user supplied functions. In principle the type of all arguments can be inferred statically, but Julia doesn’t seem to do that, leading to…

---

## [Good Julia function / algorithm idea to find the nearest node to a given point location based on some given road network (for example, open street map data)?](https://discourse.julialang.org/t/good-julia-function-algorithm-idea-to-find-the-nearest-node-to-a-given-point-location-based-on-some-given-road-network-for-example-open-street-map-data/22787)

<div class="topic-metadata">

**Author:** [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Replies:** 12\
**Last updated:** [October 31, 2023, 4:55pm UTC](https://discourse.julialang.org/t/good-julia-function-algorithm-idea-to-find-the-nearest-node-to-a-given-point-location-based-on-some-given-road-network-for-example-open-street-map-data/22787 "2023-10-31T16:55:16Z")

</div>

Hello. In python, we have the nice function to get the nearest node to a given point location using the osmnx package as the following. import osmnx as ox ox.config(log\_console=True, use\_cache=True) G = ox.graph\_from…

---

## [Any package or provision to suggest alternative/fast code](https://discourse.julialang.org/t/any-package-or-provision-to-suggest-alternative-fast-code/105610)

<div class="topic-metadata">

**Author:** [@VinodV](https://discourse.julialang.org/u/VinodV)\
**Replies:** 4\
**Last updated:** [October 31, 2023, 3:56pm UTC](https://discourse.julialang.org/t/any-package-or-provision-to-suggest-alternative-fast-code/105610 "2023-10-31T15:56:38Z")

</div>

Suppose I have written a piece of code to check whether a string say “malayalam” is a palindrome. s = "malayalam" s == reverse(a) . An alternative is s == s\[end:-1:1\]. Is there a package or provision to suggest alter…

---

## [Why do these allocate?!](https://discourse.julialang.org/t/why-do-these-allocate/105497)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 4\
**Last updated:** [October 28, 2023, 12:58pm UTC](https://discourse.julialang.org/t/why-do-these-allocate/105497 "2023-10-28T12:58:36Z")

</div>

The functions shuf1 and shuf2 are two different implementations of a Fisher-Yates shuffle for tuples. Why do both allocate, even in trivial cases? The recursion depth should be small and a compile-time constant and all t…

---

## [Speeding up the calculation of Liouville function](https://discourse.julialang.org/t/speeding-up-the-calculation-of-liouville-function/105447)

<div class="topic-metadata">

**Author:** [@HMegh](https://discourse.julialang.org/u/HMegh)\
**Replies:** 4\
**Last updated:** [October 27, 2023, 5:15pm UTC](https://discourse.julialang.org/t/speeding-up-the-calculation-of-liouville-function/105447 "2023-10-27T17:15:20Z")

</div>

Hi! In my journey to learn Julia, I was trying to find the smallest counter example of Polya’s conjecture which is a little less than 10^9, while using as little memory as possible. Any tips on how to optimize the algo…

---

## [Stdout appears as type instable](https://discourse.julialang.org/t/stdout-appears-as-type-instable/105481)

<div class="topic-metadata">

**Author:** [@Shayan](https://discourse.julialang.org/u/Shayan)\
**Replies:** 6\
**Last updated:** [October 27, 2023, 2:28pm UTC](https://discourse.julialang.org/t/stdout-appears-as-type-instable/105481 "2023-10-27T14:28:59Z")

</div>

I made the following progress bar, but according to @code\_warntype it is somewhat type instable. How can I make it type stable? function progressbar(ntimes::S, current::S) where S\<:Int val = current/ntimes val\_round…

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

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