[geary/mjog/invert-folder-class-hierarchy: 63/72] Geary.Imap.ClientConnection: Coalesce received_bytes signal emmission
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/invert-folder-class-hierarchy: 63/72] Geary.Imap.ClientConnection: Coalesce received_bytes signal emmission
- Date: Wed, 3 Mar 2021 11:52:48 +0000 (UTC)
commit 0ee85dee12785c397cbdaa5fe4218c8a780e6906
Author: Michael Gratton <mike vee net>
Date: Sun Feb 28 20:04:36 2021 +1100
Geary.Imap.ClientConnection: Coalesce received_bytes signal emmission
Since `received_bytes` is emitted whenever a complete line is received
from the server, it can be emitted a *lot*. To reduce the CPU overhead
of this, and since it's only used for timekeeping at higher levels,
coalesce emission to only occur at most once a second.
src/engine/imap/transport/imap-client-connection.vala | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/src/engine/imap/transport/imap-client-connection.vala
b/src/engine/imap/transport/imap-client-connection.vala
index 390984e94..25156ec3a 100644
--- a/src/engine/imap/transport/imap-client-connection.vala
+++ b/src/engine/imap/transport/imap-client-connection.vala
@@ -73,6 +73,10 @@ public class Geary.Imap.ClientConnection : BaseObject, Logging.Source {
private int tag_counter = 0;
private char tag_prefix = 'a';
+ private int64 last_seen = 0;
+
+ private size_t bytes_accumulator = 0;
+
private Geary.Nonblocking.Queue<Command> pending_queue =
new Geary.Nonblocking.Queue<Command>.fifo();
private Gee.Queue<Command> sent_queue = new Gee.LinkedList<Command>();
@@ -555,7 +559,17 @@ public class Geary.Imap.ClientConnection : BaseObject, Logging.Source {
}
private void on_bytes_received(size_t bytes) {
- received_bytes(bytes);
+ // the deser's bytes_received signal can be called 10's of
+ // times per second, so avoid some CPU overhead by turning
+ // down the number of times per second it is emitted to higher
+ // levels.
+ this.bytes_accumulator += bytes;
+ var now = GLib.get_real_time();
+ if (this.last_seen + 1000000 <= now) {
+ received_bytes(this.bytes_accumulator);
+ this.bytes_accumulator = 0;
+ this.last_seen = now;
+ }
}
private void on_eos() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]