JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.43k stars 5.45k forks source link

BitSet() is perhaps slow #51287

Open algorithmx opened 1 year ago

algorithmx commented 1 year ago

https://github.com/JuliaLang/julia/blob/4af6be80f238fce9cd124925d488a4c7171cf74a/base/bitset.jl#L18

Dear Julia developers,

I work in a company and we build TCAD simulators using Julia.

I have been optimising my code and realised that creating empty BitSet() takes significant amount of time. Below are the prof and memprof results. Please help me to get over of this overhead, if it is possible. Thank you!

Screenshot from 2023-09-13 11-05-00 Screenshot from 2023-09-13 11-03-21

Keno commented 1 year ago

You're not seeing BitSet() itself, but rather you're seeing the cost of GC. I'd recommend taking a look at your allocations with the allocation profiler and seeing if there's anything you can improve there.

oscardssmith commented 1 year ago

that said, BitSet() is about 2x slower than it could be. It's a known issue that array creation is slower than it should be, https://github.com/JuliaLang/julia/issues/45160, and the resize! is also slower than it should be because it is calling out to C and has to recompute all the information about the array even though we just created it and therefore know everything about it.

LilithHafner commented 12 months ago

See also: https://github.com/JuliaLang/julia/issues/50326