baskerville / plato

Document reader
Other
1.26k stars 105 forks source link

Emulator is frightfully slow, on purpuse? #225

Closed Szybet closed 1 year ago

Szybet commented 2 years ago

It's me again, I have many questions The emulator was really slow for me, just unusable. I checked the code in emulator.rs and changed all lines that concerned something with waiting, like thread::sleep(Duration::from_secs(2)); to a lower value. Now it works just like on the ereader. Why?...

baskerville commented 2 years ago

What's the OS?

Szybet commented 2 years ago

Arch linux

baskerville commented 2 years ago

I don't experience any slowdowns on macOS.

Szybet commented 2 years ago

Well, then two questions:

  1. Why are there those slowdowns ( wait 2 seconds for example )?
  2. Would changing those slowdowns have a negative impact on other platforms?
baskerville commented 2 years ago

The calls to thread::sleep happen in parallel threads. The main thread never pauses more than 20 ms (event_pump.wait_event_timeout(20) and rx.recv_timeout(Duration::from_millis(20))).

Szybet commented 2 years ago

would changing them to lower break something?

baskerville commented 2 years ago

Would changing them to lower break something?

I'm not sure I'd want to apply a random hack to solve a problem we don't understand yet.

Could you provide the exact modifications (git diff) you've made?

Szybet commented 2 years ago

here they are

--- a/src/emulator.rs
+++ b/src/emulator.rs
@@ -299,7 +299,7 @@ fn main() -> Result<(), Error> {

     'outer: loop {
         let mut event_pump = sdl_context.event_pump().unwrap();
-        if let Some(sdl_evt) = event_pump.wait_event_timeout(20) {
+        if let Some(sdl_evt) = event_pump.wait_event_timeout(1) {
             match sdl_evt {
                 SdlEvent::Quit { .. } |
                 SdlEvent::KeyDown { keycode: Some(Keycode::Escape), keymod: Mod::NOMOD, .. } => {
@@ -370,7 +370,7 @@ fn main() -> Result<(), Error> {
             }
         }

-        while let Ok(evt) = rx.recv_timeout(Duration::from_millis(20)) {
+        while let Ok(evt) = rx.recv_timeout(Duration::from_millis(1)) {
             match evt {
                 Event::Open(info) => {
                     let rotation = context.display.rotation;
@@ -555,7 +555,7 @@ fn main() -> Result<(), Error> {
                         if enable {
                             let tx2 = tx.clone();
                             thread::spawn(move || {
-                                thread::sleep(Duration::from_secs(2));
+                                thread::sleep(Duration::from_secs(1));
                                 tx2.send(Event::Device(DeviceEvent::NetUp)).ok();
                             });
                         } else {