Browse Source

Throttle unread status changes.

Reduces unread status changes to publish to the eventbus
at most once every 200ms per window. These events are
handled synchronously on the EDT so cause massive
performance issues.

When connecting to several bouncers with huge backbuffers
this makes the client usable in seconds rather than tens of minutes.

Internally this uses RX to handle the throttling, because it's
super easy. We might eventually want to expose that externally
instead of using an event bus, but I'm not sure.
ShaneMcC-patch-1
Chris Smith 6 years ago
parent
commit
39704a47c9
2 changed files with 20 additions and 5 deletions
  1. 2
    1
      build.gradle
  2. 18
    4
      src/main/java/com/dmdirc/ui/messages/UnreadStatusManagerImpl.java

+ 2
- 1
build.gradle View File

61
     bundle group: 'com.getsentry.raven', name: 'raven', version: '7.8.0'
61
     bundle group: 'com.getsentry.raven', name: 'raven', version: '7.8.0'
62
     bundle group: 'com.google.guava', name:'guava', version: '19.0'
62
     bundle group: 'com.google.guava', name:'guava', version: '19.0'
63
     bundle group: 'net.engio', name: 'mbassador', version: '1.3.0'
63
     bundle group: 'net.engio', name: 'mbassador', version: '1.3.0'
64
-    bundle group: 'com.google.code.gson', name: 'gson', 'version': '2.5'
64
+    bundle group: 'com.google.code.gson', name: 'gson', version: '2.5'
65
+    bundle group: 'io.reactivex.rxjava2', name: 'rxjava', version: '2.1.12'
65
 
66
 
66
     bundle group: 'com.dmdirc', name: 'com.dmdirc.config.binding', version: '+', changing: true
67
     bundle group: 'com.dmdirc', name: 'com.dmdirc.config.binding', version: '+', changing: true
67
     bundle group: 'com.dmdirc', name: 'com.dmdirc.config.provider', version: '+', changing: true
68
     bundle group: 'com.dmdirc', name: 'com.dmdirc.config.provider', version: '+', changing: true

+ 18
- 4
src/main/java/com/dmdirc/ui/messages/UnreadStatusManagerImpl.java View File

30
 import com.dmdirc.util.colours.Colour;
30
 import com.dmdirc.util.colours.Colour;
31
 
31
 
32
 import java.util.Optional;
32
 import java.util.Optional;
33
-
33
+import java.util.concurrent.TimeUnit;
34
+
35
+import io.reactivex.Emitter;
36
+import io.reactivex.Observable;
37
+import io.reactivex.ObservableEmitter;
38
+import io.reactivex.Observer;
39
+import io.reactivex.functions.Consumer;
40
+import io.reactivex.subjects.PublishSubject;
41
+import io.reactivex.subjects.ReplaySubject;
42
+import io.reactivex.subjects.Subject;
34
 import net.engio.mbassy.listener.Handler;
43
 import net.engio.mbassy.listener.Handler;
44
+import org.reactivestreams.Publisher;
35
 
45
 
36
 /**
46
 /**
37
  * Tracks unread messages and other notifications.
47
  * Tracks unread messages and other notifications.
38
  */
48
  */
39
 public class UnreadStatusManagerImpl implements UnreadStatusManager {
49
 public class UnreadStatusManagerImpl implements UnreadStatusManager {
40
 
50
 
41
-    private final EventBus eventBus;
42
     private final WindowModel container;
51
     private final WindowModel container;
43
     private final ColourManager colourManager;
52
     private final ColourManager colourManager;
53
+    private final Subject<UnreadStatusChangedEvent> eventSubject;
44
 
54
 
45
     private int unreadLines;
55
     private int unreadLines;
46
     private Optional<Colour> notificationColour = Optional.empty();
56
     private Optional<Colour> notificationColour = Optional.empty();
51
 
61
 
52
     public UnreadStatusManagerImpl(final WindowModel container) {
62
     public UnreadStatusManagerImpl(final WindowModel container) {
53
         this.container = container;
63
         this.container = container;
54
-        this.eventBus = container.getEventBus();
55
         this.colourManager = new ColourManagerImpl(container.getConfigManager());
64
         this.colourManager = new ColourManagerImpl(container.getConfigManager());
65
+        this.eventSubject = PublishSubject.create();
66
+
67
+        eventSubject
68
+                .throttleLast(200, TimeUnit.MILLISECONDS)
69
+                .subscribe(unreadStatusChangedEvent -> container.getEventBus().publish(unreadStatusChangedEvent));
56
     }
70
     }
57
 
71
 
58
     @Handler
72
     @Handler
177
     }
191
     }
178
 
192
 
179
     private void publishChangedEvent() {
193
     private void publishChangedEvent() {
180
-        eventBus.publishAsync(new UnreadStatusChangedEvent(container, this, notificationColour,
194
+        eventSubject.onNext(new UnreadStatusChangedEvent(container, this, notificationColour,
181
                 unreadLines));
195
                 unreadLines));
182
     }
196
     }
183
 
197
 

Loading…
Cancel
Save