Open pbayer opened 3 years ago
Can it be beneficial to introduce a function
partial(f, a...; kw...) = (c...) -> f(a..., c...; kw...)
since that is faster than current Bhv
:
julia> f(a,b,c; x=1, y=2) = a+b+c+x+y
f (generic function with 1 method)
julia> partial(f, a...; kw...) = (c...) -> f(a..., c...; kw...)
partial (generic function with 1 method)
julia> f1 = Bhv(f, 1,2);
julia> f2 = partial(f, 1,2)
#25 (generic function with 1 method)
julia> using BenchmarkTools
julia> @btime f1(3)
25.046 ns (0 allocations: 0 bytes)
9
julia> @btime f2(3)
13.615 ns (0 allocations: 0 bytes)
9
But partial
has two disadvantages to Bhv
:
invokelatest
, which will kill the speed advantage:julia> @btime Base.invokelatest(f2, 3)
44.490 ns (1 allocation: 16 bytes)
9
I am able to get to the same speed as partial
if I make Bhv
a parametric struct like that:
using BenchmarkTools
f(a,b,c; x=1, y=2) = a+b+c+x+y
partial(f, a...; kw...) = (c...) -> f(a..., c...; kw...)
struct Bhv{F}
f
a
kw
ϕ::F
function Bhv(f, a...; kw...)
ϕ = (c...) -> f(a..., c...; kw...)
new{typeof(ϕ)}(f, a, kw, ϕ)
end
end
(bhv::Bhv)(c...) = bhv.ϕ(c...)
julia> f1 = partial(f, 1, 2)
#11 (generic function with 1 method)
julia> f2 = Bhv(f, 1, 2);
julia> @btime f1(3)
13.089 ns (0 allocations: 0 bytes)
9
julia> @btime f2(3)
13.443 ns (0 allocations: 0 bytes)
9
Thus I can maintain the advantage of Bhv
to be updatable to current world age.
Actors
v0.2.1@JuliaRegistrator register
Release notes:
Bhv
much fasterRegistration pull request created: JuliaRegistries/General/26647
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:
git tag -a v0.2.1 -m "<description of version>" d8faab1c9e5082ee3c23b48d59e4b4a7b7e37eca
git push origin v0.2.1
Actors
v0.2.2@JuliaRegistrator register
Release notes:
@msg
macro for easy message definition,Registration pull request created: JuliaRegistries/General/26680
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:
git tag -a v0.2.2 -m "<description of version>" e146b7e7d56cccb9b02c3094b4f501e76ecff7ba
git push origin v0.2.2
Actors
v0.2.5@JuliaRegistrator register
Release notes:
stop()
function, see commit 94cdfbdRegistration pull request created: JuliaRegistries/General/41679
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:
git tag -a v0.2.5 -m "<description of version>" 9a85dec4316b4b758068fb1686a5b4239737ceca
git push origin v0.2.5
This issue collects different improvements (ideas and proposals) to the actor machinery:
send_after
for doing periodic work (as here in Elixir)