Skip to content

possible to make NonBlockingReader faster to poll? #1547

@maxandersen

Description

@maxandersen

I got code similar to this:

while (running) {
                terminal.draw(this::ui);

                // Non-blocking read with ~16ms timeout for ~60 FPS
                int c = backend.read(16);
                if (c == 'q' || c == 'Q' || c == 3) {
                    running = false;
                }
            }

using the NonBlockingReader and I was getting about 6 fps - which I initially thought was due to drawing taking time but with profiler I saw that the read operation - even with 1 ms timeout takes about 65% of the time in that loop.

I know I can explore doing this in a separate thread but feels like something must be going on making it taking that much time just checking

here is the profiler tree from jvisualvm:
Image

this is on Mac in a ghostty terminal which for similar app in rust gets 30-34 fps, I can get 21 fps with quite sloppy java - as long as I don't check for input.

Is the only option really to go multithreaded?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions