How to define pre-compile workloads for Makie figures in a module?

I modified the interactive button counting example from the official Makie documentation. It has a mouse-hover and button-click interactive events.

May someone please help me with the pre-compilation workload code? I would like to reduce the compilation latency an user would experience when the user mouse-hover over any of the bars (DataInspector event) or click on any of the buttons (the on event).

My sample code:

module CounterTutorial

    using GLMakie

    function create_dashboard(initial_count_values::AbstractVector{<:Integer})

        num_buttons = length(initial_count_values)

        fig = Figure()

        ax = Axis(fig[1, 1])
        fig[2, 1] = buttongrid = GridLayout(tellwidth = false)

        counts = Observable(initial_count_values)

        button_labels = [lift(x -> "Count: $(x[i])", counts) for i in eachindex(initial_count_values)]

        buttons = buttongrid[1, 1:num_buttons] = [Button(fig, label = l) for l in button_labels]

        for i in 1:num_buttons
            on(buttons[i].clicks) do _
                counts[][i] += 1
                notify(counts)
            end
        end

        barplot!(counts, color = cgrad(:Spectral)[LinRange(0, 1, num_buttons)])
        ylims!(ax, 0, maximum(initial_count_values) * 2)

        DataInspector()

        return fig
    end

    using PrecompileTools

    @compile_workload begin

        vs_initial = [1, 2, 3]
        fig = CounterTutorial.create_dashboard(vs_initial)

        # Execute the code path for:
        #   - the DataInspector event for mouse-hover over a bar
        #   - the `on(buttons[i].clicks)` event
    end
end

println("Calling create_dashboard!")
vs_initial = [1, 4, 3, 7, 2]
fig = CounterTutorial.create_dashboard(vs_initial)
display(fig)

I’m on GLMakie v0.13.8, PrecompileTools v1.3.3, Julia v1.12.5. Please let me know if there are alternative approaches to reduce the compilation latency for the user for this type of Makie application. I didn’t managed to get JuliaC v0.3.0 to with this code under my setup.

For the buttons I think you could just notify(b.clicks) for each to execute the stored functions. For DataInspector I’m not sure, it’s triggered by the mouse hovering over specific pixels. But you can in principle fake mouse interaction by triggering your own events. Check how I did it for the fake interaction videos in the docs: Makie.jl/docs/fake_interaction.jl at master · MakieOrg/Makie.jl · GitHub