I was looking at SpecialFunctions.jl which contains a bunch of functions which are fairly independent and thinking: if I just want to only use one or two specific functions, what’s the overhead vs just copy-pasting that code in mine.
julia> @time import SpecialFunctions: sinint, cosint 0.315543 seconds (399.21 k allocations: 22.219 MiB, 1.29% gc time)
vs (in a fresh session)
julia> @time include("sincosint.jl") 0.087249 seconds (260.80 k allocations: 14.275 MiB)
(which is not the best way to do it but you get the idea).
Of course the former is slower because it doesn’t just load
cosint even though only those two are brought in and no other function from SF are available at this point; if you import other functions subsequently, it’s instantaneous
julia> @time import SpecialFunctions: ellipk 0.001191 seconds (433 allocations: 22.875 KiB)
but… say I don’t care about
What if I only really need a handful of functions from a package?
I imagine other people have thought about this before so I was hoping people could point me in the right direction. While I understand that in general it would be difficult and annoying to track down all the code that would need to be loaded and so that the current situation makes sense, I was wondering whether, in some cases, it might be possible to offer a way to do it.
Maybe more specifically: whether it would be imaginable to signal from within a package chunks of the code that can be loaded independently of the whole. (ideally independent functions or maybe small groups of functions if they share a util or a const). That might only make sense for a few packages like SpecialFunctions but it could still be useful.
The reasoning stems from a discussion here a week or two ago about the sigmoid and logsigmoid functions which I believe at least half a dozen packages implement in their own way. It seems to me that it would make sense to have banks of optimised functions (like SpecialFunctions.jl) to re-use but without it incurring a significant load time overhead (a reason why, I think, many people try to slim down their dependencies as much as possible) and just load exactly as much code as required. Of course some cases might still warrant customised implementations.
- I imagine people have thought about this, are there pointers to past discussion I could look at? I had a brief poke around but didn’t find anything
- How hard would it be to signal from within a package chunks of code that could be loaded independently and make it possible to only just load such chunks
- Is it worthwhile to try to investigate this or are there good reasons not to try (e.g. people have tried and it didn’t work etc)