# Performance Issue with Gtk.jl

**URL:** <https://discourse.julialang.org/t/performance-issue-with-gtk-jl/6171>\
**Category:** General Usage\
**Created:** [September 30, 2017, 6:49pm UTC](https://discourse.julialang.org/t/performance-issue-with-gtk-jl/6171 "2017-09-30T18:49:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [September 30, 2017, 6:49pm UTC](https://discourse.julialang.org/t/performance-issue-with-gtk-jl/6171/1 "2017-09-30T18:49:31Z")

</div>

Hi,

I have a performance issue that may be linked to Gtk.jl. My application needs 30 sec to start up the first time and profiling tells me that most of the time is spend in inference. The app is a little larger so that some dynamic typing (e.g. when using Dicts) cannot be avoided.

The inference call is triggered from this line in Gtk.jl

```
https://github.com/JuliaGraphics/Gtk.jl/blob/master/src/GLib/signals.jl#L11

```

it involves a `cfunction` so it may be linked to [Performance regression of Cuba.jl on Julia 0.6](https://discourse.julialang.org/t/performance-regression-of-cuba-jl-on-julia-0-6/2424) which I however do not really understand. @yuyichao do you know if there is an issue with the Gtk.jl code?

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [October 1, 2017, 5:47pm UTC](https://discourse.julialang.org/t/performance-issue-with-gtk-jl/6171/2 "2017-10-01T17:47:47Z")

</div>

@tim.holy: Have you observed performance issues with the “low-level” `signal-connect` interface of Gtk.jl? That which uses `cfunction`? The other “high-level” interface is much faster during `signal-connect` but it has a serious performance hit, when the signal is fired the first time.

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [October 2, 2017, 6:24am UTC](https://discourse.julialang.org/t/performance-issue-with-gtk-jl/6171/3 "2017-10-02T06:24:42Z")

</div>

@jameson: Do you have an idea why `signal_connect` low level can be that slow?

I don’t see this massive performance issue when I execute the code regularly (i.e. not in a callback)

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [October 2, 2017, 8:21am UTC](https://discourse.julialang.org/t/performance-issue-with-gtk-jl/6171/4 "2017-10-02T08:21:36Z")

</div>

… without having any details, but

“serious performance hit, when the signal is fired the first time”  
and  
“me that most of the time is spend in inference.”

sounds like, we see this delay as compilation time of the code. In one place as JIT at the time the signal connect is done OR at the time the code is called the first time and not available as compiled.  
I did see similar effects when i worked/tested GUIs with Gtk.jl but my callbacks usually were rather short functions that only update data.

Can you somehow make an example available?

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [October 2, 2017, 8:24am UTC](https://discourse.julialang.org/t/performance-issue-with-gtk-jl/6171/5 "2017-10-02T08:24:31Z")

</div>

Unfortunately this is a pretty big code base, that I cannot make public available. Small callbacks are no issues but here I have the feeling that inference takes a lot longer than it would when I call the function not in a callback.

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [October 2, 2017, 8:27am UTC](https://discourse.julialang.org/t/performance-issue-with-gtk-jl/6171/6 "2017-10-02T08:27:31Z")

</div>

I would love to get rid of type unstable code. But if one implements a larger Application with config files, one starts to have `Dicts` that are inherently type unstable. I use TOML which gives me Dicts

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [October 2, 2017, 8:59am UTC](https://discourse.julialang.org/t/performance-issue-with-gtk-jl/6171/7 "2017-10-02T08:59:23Z")

</div>

But maybe that’s already the full example:

- GUI with Gtk.jl (window and a button)
- connect button-press with a call to ‘read\_in\_configuration’
- read\_in\_configuration calls TOML and uses random data  
?

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [May 31, 2018, 8:45am UTC](https://discourse.julialang.org/t/performance-issue-with-gtk-jl/6171/8 "2018-05-31T08:45:12Z")

</div>

I have now a minimal example that shows the issue:

```julia
using Gtk.ShortNames
ENV["WINSTON_OUTPUT"] = :gtk
using Winston

box = Box(:v)
b = Button("test")
push!(box,b)
c = Canvas()
push!(box,c)
setproperty!(box,:expand,c,true)
w = Window(box,"Test")

function callback(widgetptr::Ptr, m::Ptr)
  p = Winston.plot(1:5)
  display(c,p)
  return nothing
end

@time signal_connect(callback, b, "clicked", Void, (), false, C_NULL )

showall(w)

```

Here, the signal\_connect requires more than 10 seconds on julia 0.6.0 and about 5 seconds on julia 0.6.3.

@jameson: You have proposed using a schedule in the callback

```julia
using Gtk.ShortNames
ENV["WINSTON_OUTPUT"] = :gtk
using Winston

box = Box(:v)
b = Button("test")
push!(box,b)
c = Canvas()
push!(box,c)
setproperty!(box,:expand,c,true)
w = Window(box,"Test")

function callback(widgetptr::Ptr, m::Ptr)
  @schedule begin
    p = Winston.plot(1:5)
    display(c,p)
  end
  return nothing
end

@time signal_connect(callback, b, "clicked", Void, (), false, C_NULL )

showall(w)

```

Now the signal connection is faster (0.6 sec) but when I click the button it requires 5 seconds. And the UI is frozen during that time.

If you or anybody else has an idea how to solve this it would be great. I suppose that the new multi-threaded task manager will solve the UI freeze?  
But this still does not solve the Winston slowness ( [https://github.com/JuliaLang/julia/issues/27083](https://github.com/JuliaLang/julia/issues/27083)) which was fast once upon a time. Will be very interesting how fast Winston is on Julia 0.7 ([https://github.com/JuliaGraphics/Winston.jl/pull/292](https://github.com/JuliaGraphics/Winston.jl/pull/292))
