Repos / mcross / 9ff8648065
commit 9ff8648065a0fc0c2c0061f5da52d4a58320a6b3
Author: Bùi Thành Nhân <hi@imnhan.com>
Date:   Sun May 17 14:41:49 2020 +0700

    more responsive UI, full disclosure

diff --git a/README.md b/README.md
index 41f4426..4393e55 100644
--- a/README.md
+++ b/README.md
@@ -81,8 +81,11 @@ ## Responsive & pleasant to use
 ## Lightweight
 
 In terms of both disk space & memory/cpu usage.
-It's completely unoptimized at the moment but tkinter and zero-dependency
-python gives us a fairly good starting point imo.
+It's completely unoptimized at the moment.
+Actually the way I'm hooking up tkinter and curio is... not ideal. See comments
+in controller.py for more info. TL;DR I'm prioritizing gui responsiveness and
+code simplicity, sacrificing a non-negligible amount of CPU cycles even at
+idle.
 
 
 # Server bugs/surprises
diff --git a/pyproject.toml b/pyproject.toml
index 2d8ebf7..9d475b3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "mcross"
-version = "0.5.2"
+version = "0.5.3"
 description = "Do you remember www?"
 authors = ["nhanb <hi@imnhan.com>"]
 license = "MIT"
diff --git a/src/mcross/gui/controller.py b/src/mcross/gui/controller.py
index 4cea4c4..d7da00a 100644
--- a/src/mcross/gui/controller.py
+++ b/src/mcross/gui/controller.py
@@ -58,7 +58,14 @@ async def main():
                     for coroutine in self.pending_coros:
                         await coroutine
                     self.pending_coros = []
-                    await curio.sleep(0.05)  # 50ms
+                    await curio.sleep(0.016)
+                    # 16ms = 1/60 - we're targeting around 60fps
+                    # Yes it's wasteful to call root.update() that fast.
+                    # In practice CPU usage idles around 4% on my i5 but hey it's not
+                    # spinning up my laptop fans yet.
+                    # Doesn't seem like there's a better way atm. The alternative
+                    # described at [1] is multithreading which I'm not a fan of.
+                    # [1] https://github.com/dabeaz/curio/issues/111
             except TclError as e:
                 if "application has been destroyed" not in str(e):
                     raise