Skip to content

High CPU usage with run_async #460

@johanfforsberg

Description

@johanfforsberg

Hi!

I just checked back on this project and noticed that there is now integrated support for asyncio, which should make my usage a lot easier.

However when trying it, I find that the CPU usage is very high, approaching 100% of a core even if the application is doing little work apart from rendering. For example it happens with a slightly modified plotting example from the docs:

import asyncio

import numpy as np
from imgui_bundle import imgui, implot, imgui_md, hello_imgui, immapp


def gui():
    # Render Markdown text
    imgui_md.render_unindented("""
    # Render an animated plot with ImPlot
     This example uses `ImPlot` for real-time plotting, and `imgui_md` for markdown.
    """)

    # Render an animated plot (updates every frame)
    if implot.begin_plot(
            title_id="Plot",
            # size in em units (1em = height of a character)
            size=hello_imgui.em_to_vec2(40, 20)):
        x = np.arange(0, np.pi * 4, 0.01)
        y = np.cos(x + imgui.get_time())
        implot.plot_line("y1", x, y)
        implot.end_plot()

    if imgui.button("Exit"):
        hello_imgui.get_runner_params().app_shall_exit = True


# Run the app with ImPlot and markdown support
asyncio.run(
    immapp.run_async(
        gui,
        with_implot=True,
        with_markdown=True,
        window_size=(700, 500)))

CPU usage with the non-async version is ~15%.

I'm on Debian trixie, used python 3.13 and 3.14 (installed with uv), and imgui_bundle 1.92.601.

Thanks for your work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions