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

precompilation of callback functions #104

Open
hhaensel opened this issue Jan 18, 2023 · 0 comments
Open

precompilation of callback functions #104

hhaensel opened this issue Jan 18, 2023 · 0 comments

Comments

@hhaensel
Copy link

I have difficulties in understanding what is compiled upon the first call of a callback function.
It seems that even if the callback function has been used before something is compiled upon the first notification.
MWE: with the definitions

using Observables

o = Observable("Hello")

function f(s::String)
    println(s)
end

I end up with the following timings

julia> @time f("Hello")
Hello
  0.000326 seconds (8 allocations: 160 bytes)

julia> on(f, o)
ObserverFunction `f` operating on Observable("Hello")

julia> @time notify(o);
Hello
  0.002647 seconds (22 allocations: 976 bytes, 88.23% compilation time)

julia> @time notify(o);
Hello
  0.000283 seconds (9 allocations: 208 bytes)

After redefinition of f, I have the same scenario. Calling f directly doesn't need any extra compilation (f is probably compiled directly after definition). But calling f on the observable needs extra compilation.

julia> function f(s::String)
           s = s * s
           println(s, " world!")
       end
f (generic function with 1 method)

julia> @time f("Hello")
HelloHello world!
  0.000377 seconds (10 allocations: 224 bytes)

julia> @time notify(o);
HelloHello world!
  0.003482 seconds (29 allocations: 1.312 KiB, 91.26% compilation time)

julia> @time notify(o);
HelloHello world!
  0.000332 seconds (12 allocations: 576 bytes)

Where does this compilation come from and could it be avoided? (Obviously calling notify() would be one way of forcing precompilation.)

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