Comments (4)
It seems that sometime in the last two years there was a significant regression to the benchmarks. What you describe is supposed to be fast (kinda the reason this library was created in the first place), but it was out of maintenance for a few years, so this might be due to a regression in the julia compiler or due to a minor modification in the library that was never tested for performance.
Similar issue is tracked here #72
I can not commit to fixing this in the near term, but do not hesitate to ask questions if you decide to give it a try.
from resumablefunctions.jl.
I'm trying this again on @gerlero's branch, and my conclusion so far seems to be that ResumableFunctions only really work reasonably in concrete typed functions.
Which is kind of a problem if you want to compose functions. You can't really write a function that takes an iterator and produces something with good performance.
using ResumableFunctions
using BenchmarkTools
bin(s, bins) = Iterators.map(((x, y),) -> (x, searchsortedfirst(bins, y)), s)
@resumable function any_hysteresis(s)
bin = -1
for (x, y) in s
@yield if iseven(y)
(x, (bin+1)÷2)
else
bin = y
(x, (y+1)÷2)
end
end
end
@resumable function hysteresis(s::Vector{Tuple{Int,Int}})
bin = -1
for (x, y) in s
@yield if iseven(y)
(x, (bin+1)÷2)
else
bin = y
(x, (y+1)÷2)
end
end
end
tolbins(bins, tol=1e-9) = collect(Iterators.flatmap((x -> (x-tol,x+tol)), bins))
hybin(s, bins, tol=1e-9) = bin(s, tolbins(bins, tol)) |> collect
s = collect(zip(1:1000, rand(1000)))
b = hybin(s, [0.5])
println("Any typed")
@btime for _ in any_hysteresis(b) end;
println("Struct types")
println(fieldtypes(typeof(any_hysteresis([(0,0)]))))
println("Vector typed")
@btime for _ in hysteresis(b) end;
println("Struct types")
println(fieldtypes(typeof(hysteresis([(0,0)]))))
Result:
Any typed
202.546 μs (11470 allocations: 335.52 KiB)
Struct types
(UInt8, Any, Any, Any, Any, Any, Any)
Vector typed
2.027 μs (1 allocation: 64 bytes)
Struct types
(UInt8, Int64, Vector{Tuple{Int64, Int64}}, Int64, Int64, Vector{Tuple{Int64, Int64}}, Int64)
from resumablefunctions.jl.
I tried to simplify the examples you gave a bit. While not covering everything you mentioned, I think a good first step would be to try to make the following faster:
@resumable function one_to_n(n)
for i in 1:n
@yield i
end
end
@resumable function one_to_n_typed(n::Int)
for i in 1:n
@yield i
end
end
function append_one_to_n(n)
l = typeof(n)[]
for i in 1:n
push!(l, i)
end
l
end
const n = 100
@btime collect(one_to_n($n)) evals=1; # 4.258 μs (306 allocations: 11.36 KiB)
@btime collect(one_to_n_typed($n)) evals=1; # 390.000 ns (5 allocations: 1.97 KiB)
@btime append_one_to_n($n); # 334.060 ns (4 allocations: 1.92 KiB)
@btime collect(1:$n) evals=1; # 30.000 ns (1 allocation: 896 bytes)
This issue is quite multifaceted. If we start working on it, probably we should split it in smaller pieces along the lines of the topics you have already enumerated (type annotations in the generated structs, the need for function annotation, specialization, reporting length and eltype when possible).
from resumablefunctions.jl.
from resumablefunctions.jl.
Related Issues (20)
- Recursive parametric functions troubles?
- Resumable function has stopped HOT 2
- `continue` results in infinite loops HOT 3
- macro clashing with ProgressLogging.jl HOT 1
- Error `@yield macro outside a @resumable function!` when using @yield inside a macro HOT 3
- is this package being maintained? HOT 5
- The CI/CD build is broken HOT 1
- Broken on Julia 1.10 (fix included) HOT 17
- Release v1.0.0? HOT 3
- CI, TagBot, Documenter fixes HOT 1
- a resumable function as a struct field var causes an error "struct expression not at top level"
- `@resumable` breaks blocks scope HOT 2
- let blocks without variable assignement like `let i; f(i); end` are not supported HOT 1
- significant regression in benchmarks HOT 4
- Functionals that refer to themselves are not supported (because they are not saved to the finite state machine)
- ResumableFunctions v0.6.6 StackOverflow with julia-1.10 HOT 8
- tests for downstream breakage HOT 1
- 0.6.7 breaks resumables with multiple fors over same variable HOT 6
- enable inference in self-referencing resumable functions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from resumablefunctions.jl.