bmad-sim / GTPSA.jl

Julia interface to the Generalised Truncated Power Series Algebra (GTPSA) library

Home Page:https://bmad-sim.github.io/GTPSA.jl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change underlying `TPS` struct

mattsignorelli opened this issue · comments

This will be a lot of work, but I think is worth it
#121

I think by putting the ctors in Julia and using jl_malloc INSIDE Julia, there could be a massive speedup (simple testing shows so).

This requires removing the flexible array members from the tpsa structs in C and replacing them with pointers. There is a bit of a slowdown here but I think using everything inside Julia will make up for it

The time for operations is of course unchanged, but the allocations are now significantly faster:

julia> @btime NewTPS{Float64}($d.desc, GTPSA.MAD_TPSA_SAME)
  47.208 ns (2 allocations: 62.62 KiB)
NewTPS{Float64}(Ptr{GTPSA.Desc} @0x0000600001f14000, 0x01, 0x00, 0x0a, 0x0a, 0, (0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), Ptr{Float64} @0x00000001330f8010)

julia> @btime TPS(use=$d)
  769.939 ns (1 allocation: 16 bytes)
TPS:
 Coefficient                Order   Exponent
  0.0000000000000000e+00      0      0   0   0   0   0   0

Speed differences for the benchmark without @FastGTPSA appears negligible, including not using the flexible array members. However Julia memory usage now stays completely sane. Also, I tested using Vectors of these new structs and feeding that straight into the C (instead of creating temporary array of pointers as I was) and that appears to be working too.

Fixed in #123