Is there a delay when using println! from sdl2?

  1. I don't have a minimal failure case yet, sorry.

  2. I am using IntelliJ + building in debug mode + SDL2 + println! for debugging.

  3. I have a snippet of code that looks like:

        match event {
            sdl2::event::Event::Quit { .. } => Some(GfxEvent::Quit),
            sdl2::event::Event::Window { win_event, .. } => match win_event {
                sdl2::event::WindowEvent::SizeChanged(w, h) => Some(GfxEvent::Window(GfxWindowEvent::SizeChanged(w, h))),
                sdl2::event::WindowEvent::Resized(w, h) => Some(GfxEvent::Window(GfxWindowEvent::Resized(w, h))),
                _ => None,
            },
            sdl2::event::Event::KeyDown {
                timestamp,
                window_id: _,
                keycode,
                scancode,
                keymod,
                repeat: _,
            } => {
                println!("keydown event: {:?} {:?} {:?} {:?}", timestamp, keycode, scancode, keymod);
                None
            }
  1. There seems to be a noticable delay from when I hit a key to when the println! is executed. I'm not sure what is causing the delay. One possible hypothesis is -- is println! being buffered, and if so, is there some way to force it to output immedaitely?

Other hypothesis welcome.

Thanks!

Have you tried in release mode? println! is typically line-buffered, so whole lines should always be fully written.

  1. @alice : That fixed it. Thanks!

  2. It turns out:

"terminal + cargo run --release" = no delay
"terminal + cargo run" = no delay
"running via green arrow in IntelliJ" = delay

So it might actually be that the "window that IntelliJ uses to output unit test data" is causing the delays.

1 Like