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

menu with lots of options slows down keyboard entry into textbox #4074

Open
bjarthur opened this issue Jul 31, 2024 · 3 comments
Open

menu with lots of options slows down keyboard entry into textbox #4074

bjarthur opened this issue Jul 31, 2024 · 3 comments
Labels
bug interaction anything event related Performance also memory WGLMakie This relates to WGLMakie.jl, the Web-based WebGL backend for Makie. Widgets Menu, Slider, TextBox, etc

Comments

@bjarthur
Copy link
Contributor

on M2 apple silicon, a Menu with lots (say 10k) options slows down entering characters into a Textbox, but only on WGLMakie, not GLMakie. like this:

using WGLMakie
        
f = Figure()
Textbox(f[1,1], placeholder="type quickly")
Menu(f[2,1], options = string.(1:10_000))

if you type quickly enough and length(options) is large enough, the characters will appear out of order in the textbox.

i'll agree with anyone who says a menu with 10k options is a bad UI, but still, why the performance problems in WGLMakie but not GLMakie?

@bjarthur bjarthur added the bug label Jul 31, 2024
@SimonDanisch
Copy link
Member

Because WGLMakie is a lot slower than GLMakie ;)
Rendering speed should be somewhat comparable, but any event/update must travel quite far for WGLMakie and I expect doing anything with the menu to trigger quite a lot of events.

@bjarthur
Copy link
Contributor Author

but just entering text into the box shouldn't trigger any menu related events. so why does just having the menu there with lots of options slow the textbox down?

@ffreyer ffreyer added interaction anything event related WGLMakie This relates to WGLMakie.jl, the Web-based WebGL backend for Makie. Performance also memory Widgets Menu, Slider, TextBox, etc labels Aug 28, 2024
@ffreyer
Copy link
Collaborator

ffreyer commented Feb 23, 2025

This is more or less caused by layouting. Typing in the Textbox resizes it. Without setting tellwidth and tellheight to false, the resize propagates to the Menu block and then every plot inside. Allocations confirm this:

Writing "1" to an empty Textbox with your example code:

  • both true (default): 6.4M allocs
  • one true, one false: 2.6M allocs
  • both false: 5.6k allocs
code
begin
    using WGLMakie

    f = Figure()
    Textbox(f[1,1], placeholder="type quickly", tellwidth = false, tellheight = false)
    Menu(f[2,1], options = string.(1:10_000), tellwidth = false, tellheight = false)
    f
end

begin
    str = "1"
    ks = map(collect(str)) do letter
        key = if letter == ' '
            Keyboard.space
        elseif letter == '.'
            Keyboard.period
        elseif isnumeric(letter)
            eval(:(Keyboard.$(Symbol(lowercase("_$letter")))))
        else
            eval(:(Keyboard.$(Symbol(lowercase(letter)))))
        end
    end

    @time begin
        events(f).mouseposition[] = (300, 250)
        events(f).mousebutton[] = Makie.MouseButtonEvent(Mouse.left, Mouse.press)
        events(f).mousebutton[] = Makie.MouseButtonEvent(Mouse.left, Mouse.release)

        for (letter, key) in zip(str, ks)
            events(f).keyboardbutton[] = Makie.KeyEvent(key, Keyboard.press)
            events(f).unicode_input[] = letter
            events(f).keyboardbutton[] = Makie.KeyEvent(key, Keyboard.release)
        end
    end
end

@ffreyer ffreyer mentioned this issue Feb 24, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug interaction anything event related Performance also memory WGLMakie This relates to WGLMakie.jl, the Web-based WebGL backend for Makie. Widgets Menu, Slider, TextBox, etc
Projects
None yet
Development

No branches or pull requests

3 participants