소스 검색

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 년 전
부모
커밋
39704a47c9
2개의 변경된 파일20개의 추가작업 그리고 5개의 파일을 삭제
  1. 2
    1
      build.gradle
  2. 18
    4
      src/main/java/com/dmdirc/ui/messages/UnreadStatusManagerImpl.java

+ 2
- 1
build.gradle 파일 보기

@@ -61,7 +61,8 @@ dependencies {
61 61
     bundle group: 'com.getsentry.raven', name: 'raven', version: '7.8.0'
62 62
     bundle group: 'com.google.guava', name:'guava', version: '19.0'
63 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 67
     bundle group: 'com.dmdirc', name: 'com.dmdirc.config.binding', version: '+', changing: true
67 68
     bundle group: 'com.dmdirc', name: 'com.dmdirc.config.provider', version: '+', changing: true

+ 18
- 4
src/main/java/com/dmdirc/ui/messages/UnreadStatusManagerImpl.java 파일 보기

@@ -30,17 +30,27 @@ import com.dmdirc.interfaces.WindowModel;
30 30
 import com.dmdirc.util.colours.Colour;
31 31
 
32 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 43
 import net.engio.mbassy.listener.Handler;
44
+import org.reactivestreams.Publisher;
35 45
 
36 46
 /**
37 47
  * Tracks unread messages and other notifications.
38 48
  */
39 49
 public class UnreadStatusManagerImpl implements UnreadStatusManager {
40 50
 
41
-    private final EventBus eventBus;
42 51
     private final WindowModel container;
43 52
     private final ColourManager colourManager;
53
+    private final Subject<UnreadStatusChangedEvent> eventSubject;
44 54
 
45 55
     private int unreadLines;
46 56
     private Optional<Colour> notificationColour = Optional.empty();
@@ -51,8 +61,12 @@ public class UnreadStatusManagerImpl implements UnreadStatusManager {
51 61
 
52 62
     public UnreadStatusManagerImpl(final WindowModel container) {
53 63
         this.container = container;
54
-        this.eventBus = container.getEventBus();
55 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 72
     @Handler
@@ -177,7 +191,7 @@ public class UnreadStatusManagerImpl implements UnreadStatusManager {
177 191
     }
178 192
 
179 193
     private void publishChangedEvent() {
180
-        eventBus.publishAsync(new UnreadStatusChangedEvent(container, this, notificationColour,
194
+        eventSubject.onNext(new UnreadStatusChangedEvent(container, this, notificationColour,
181 195
                 unreadLines));
182 196
     }
183 197
 

Loading…
취소
저장