Does this describe you or someone you know?
Do you often find yourself writing a bunch of composable functions that end up calling the same expensive function on the same single input several times? Does this slow your code down? Have you tried solving this problem by pre-computing the expensive function, but then wondered how to pass it to the function? Have you, in an attempt to solve this problem, then implemented your own wrapper where you put the pre-computed value? For example, does your code take a vector as an input, but internally calls sum(vector)
ten times in total, and so you implemented a wrapper struct where you overloaded Base.sum
and a bunch of other base functions to make your wrapper usable? Something like
struct VectorWithSum{T,S}
vector::Vector{T}
sum::S
end
Base.sum(v::VectorWithSum) = v.sum
Base.:+(v::VectorWithSum, x) = v.vector + x
Base.:*(v::VectorWithSum, x) = v.vector*x
...
Did you then find out that for one of your other inputs, your excessive number of calls to sqrt
followed by inv
was preventing your code from running as fast as it possibly could? Did you then implement a new wrapper, where you pre-computed sqrt
? Was it annoying? Was it time-consuming? Was it energy-draining?
It sounds like you need a purse!
With a purse you won’t ever have to store your cache in a make-shift wrapper again. Each purse is hand-crafted and tailored to your needs, and you can access your cached value at any time with no overhead whatsoever(†). We know exactly where your cache is stored, oftentimes before you do, and we know how to access it in the fastest way possible.
We offer two kinds of purses for two kinds of people. If you are in a hurry, we have the standard, sleek Purse
with room for one value and as much cache as you desire. Even if you have time, most people will want to explore this option first to see what a purse can do for them. For the more creative people, we also offer the more fleixble AbstractPurse
where you decide where and how you want to store your value and cache. This option requires you to implement some of the details yourself, but it will give your purse your own, unique personal touch.
What are you waiting for? add Purses
and get your purse today, or visit us at Purses.jl.
Your value, your cache, your purse
(†) Only guaranteed if the purse is used in a type-stable environment.