altosuilib: Rate limit map loading pacifier updates
authorKeith Packard <keithp@keithp.com>
Wed, 11 May 2016 05:50:23 +0000 (22:50 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 12 May 2016 06:22:15 +0000 (23:22 -0700)
Just updating the pacifier was consuming a huge amount of CPU. Update
no more than once every 100ms.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosuilib/AltosUIMapPreloadNew.java

index cce07ab41a9a266a9ed79359514ede9e536f0bd5..d6c257e0750e9ddfd38f52aada93e09cc52b5739 100644 (file)
@@ -153,8 +153,12 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener
 
        double  latitude, longitude;
 
+       long    loader_notify_time;
+
        /* AltosMapLoaderListener interfaces */
        public void loader_start(final int max) {
+               loader_notify_time = System.currentTimeMillis();
+
                SwingUtilities.invokeLater(new Runnable() {
                                public void run() {
                                        pbar.setMaximum(max);
@@ -167,6 +171,13 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener
        }
 
        public void loader_notify(final int cur, final int max, final String name) {
+               long    now = System.currentTimeMillis();
+
+               if (now - loader_notify_time < 100)
+                       return;
+
+               loader_notify_time = now;
+
                SwingUtilities.invokeLater(new Runnable() {
                                public void run() {
                                        pbar.setValue(cur);