timeline: Process events in batches

A batch size of 5 doesn't seem to impact the mainloop
any more than a batch of size 1, but it reduces the
amount of time spinning the loop quite considerably.
This commit is contained in:
Georges Basile Stavracas Neto
2020-04-14 19:08:06 +00:00
parent 16c156914a
commit d4a6cd0e61
+15 -4
View File
@@ -32,6 +32,8 @@
#include <libedataserver/libedataserver.h> #include <libedataserver/libedataserver.h>
#define BATCH_SIZE 5
typedef enum typedef enum
{ {
ADD_EVENT, ADD_EVENT,
@@ -581,15 +583,21 @@ timeline_source_dispatch (GSource *source,
{ {
TimelineSource *timeline_source; TimelineSource *timeline_source;
GcalTimeline *self; GcalTimeline *self;
gint processed_events;
GCAL_ENTRY;
processed_events = 0;
timeline_source = (TimelineSource*) source;
self = timeline_source->timeline;
while (processed_events < BATCH_SIZE && !g_queue_is_empty (self->event_queue))
{
GcalRange *event_range; GcalRange *event_range;
QueueData *queue_data; QueueData *queue_data;
GcalEvent *event; GcalEvent *event;
gint i; gint i;
GCAL_ENTRY;
timeline_source = (TimelineSource*) source;
self = timeline_source->timeline;
queue_data = g_queue_pop_head (self->event_queue); queue_data = g_queue_pop_head (self->event_queue);
event = queue_data->event; event = queue_data->event;
@@ -663,6 +671,9 @@ timeline_source_dispatch (GSource *source,
queue_data_free (queue_data); queue_data_free (queue_data);
processed_events++;
}
GCAL_RETURN (G_SOURCE_CONTINUE); GCAL_RETURN (G_SOURCE_CONTINUE);
} }