bmad-sim / AtomicAndPhysicalConstants.jl

Julia package for handling particle identification in simulations.
https://bmad-sim.github.io/AtomicAndPhysicalConstants.jl/dev
MIT License
0 stars 0 forks source link

Improve speed and type stability of `Species` (formerly `Particle`) #51

Open mattsignorelli opened 2 months ago

mattsignorelli commented 2 months ago

I will call it Species here per #45 . Generating a species is type-unstable, this should be improved

julia> using AtomicAndPhysicalConstants: AtomicAndPhysicalConstants

julia> using BenchmarkTools, JET

julia> const Species = AtomicAndPhysicalConstants.Particle; # temporary until fix in made in issue #45 

julia> @btime Species("electron");
  488.672 ns (13 allocations: 528 bytes)

julia> @report_opt Species("electron")
═════ 62 possible errors found ═════
...
rot4te commented 2 months ago

I've gotten it down to 60 possible errors, all of type "runtime dispatch detected" I'm not completely sure what to do about these, as all argument types in my structs and constructors are explicit. Do you have any experience with this?