Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Batch events and timings #3757

Closed
ianb opened this issue Nov 13, 2017 · 1 comment
Closed

Batch events and timings #3757

ianb opened this issue Nov 13, 2017 · 1 comment
Assignees
Labels
P3 perf Performance-related

Comments

@ianb
Copy link
Contributor

ianb commented Nov 13, 2017

Right now we get events (and with #3727 timings) one-by-one to our /events and /timing endpoints. It would be better to batch these, since some events happen very quickly in succession. Batching can be as simple as:

let pendingEvents = [];
let eventTimer = null;
function sendEvent(event) {
  // do normal stuff to prepare the event
  // set the time of the event
  pendingEvents.push(event);
  if (!eventTimer) {
    eventTimer = setTimeout(() => {
      eventTimer = null;
      flushAllEvents();
      pendingEvents = [];
    }, 1000);
  }
}

We should set queueTime to backdate the events. Note that means we should record how long it was between sendEvent() being called, and flushAllEvents() (per-event).

@jaredhirsch
Copy link
Member

Rather than using setTimeout, this seems like a good use case for window.requestIdleCallback.

@johngruen johngruen added this to the Sprint 1 (59-0) 🍷 milestone Nov 14, 2017
@johngruen johngruen added the P3 label Nov 14, 2017
@chenba chenba self-assigned this Nov 17, 2017
@chenba chenba added the perf Performance-related label Nov 17, 2017
chenba added a commit to chenba/screenshots that referenced this issue Nov 20, 2017
chenba added a commit to chenba/screenshots that referenced this issue Nov 21, 2017
chenba added a commit to chenba/screenshots that referenced this issue Nov 27, 2017
chenba added a commit to chenba/screenshots that referenced this issue Nov 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 perf Performance-related
Projects
None yet
Development

No branches or pull requests

4 participants