Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@init is slow #160

Open
hhaensel opened this issue Jan 15, 2023 · 2 comments
Open

@init is slow #160

hhaensel opened this issue Jan 15, 2023 · 2 comments

Comments

@hhaensel
Copy link
Member

model = @init is slow compared to calling the functions directly.
MWE:

using GenieFramework
@genietools

@clear
@in a = 1
@in s = "hello"

@handlers begin
    @onchange a begin                                                                                                                                                                                  
        println("a in 1:10: ", a in 1:10)                                                                                                                                                               
        println("a: ", a in 1:10)                                                                                                                                                               
    end
end

function init_macro()
    model = @eval(@init())
end

function init_direct()
    model = __GF_AUTO_HANDLERS__(init(Main_ReactiveModel))
end
julia> @time init_macro()
  0.001252 seconds (1.20 k allocations: 124.344 KiB, 0.04% compilation time)
var"##Main_ReactiveModel!#323"("GICFHUSCRBJAGRREMGWHFKNZERQIMZXV", LittleDict{Symbol, Any, Vector{Symbol}, Vector{Any}}(), Reactive{Bool}(Observable(false), 1, false, false, ""), Reactive{Bool}(Observable(false), 1, false, false, ""), Reactive{Int64}(Observable(1), 1, false, false, "Untitled-2:5"), Reactive{String}(Observable("hello"), 1, false, false, "Untitled-2:6"))

julia> @time init_direct()
  0.000327 seconds (113 allocations: 6.922 KiB)
var"##Main_ReactiveModel!#323"("AHPGLQNFMPFRSSCXHMRIYEKFANYJRUNS", LittleDict{Symbol, Any, Vector{Symbol}, Vector{Any}}(), Reactive{Bool}(Observable(false), 1, false, false, ""), Reactive{Bool}(Observable(false), 1, false, false, ""), Reactive{Int64}(Observable(1), 1, false, false, "Untitled-2:5"), Reactive{String}(Observable("hello"), 1, false, false, "Untitled-2:6"))
@hhaensel
Copy link
Member Author

There was an world age problem in @init´ in my PR #159, which needed invokelatest()`. I fixed this just now and added a case distinction. Now things are a bit faster.

julia> @time init_macro();
  0.000408 seconds (471 allocations: 38.391 KiB)

julia> @time init_direct()
  0.000281 seconds (113 allocations: 6.922 KiB);

This is probably acceptable

@hhaensel
Copy link
Member Author

We could, however, define a start function, that has a fallback routine and defines a specialised function for future use ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant