Skip to content

Commit

Permalink
dashboard: parse all the JSON before doing DOM updates
Browse files Browse the repository at this point in the history
Inspired by SEDA's batching, of course.
  • Loading branch information
ivan committed Jun 9, 2023
1 parent 1c9ed0e commit 9cf8f41
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dashboard/assets/scripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1083,9 +1083,15 @@ ${String(kbPerSec).padStart(3, "0")} KB/s`;
console.log(`Processing ${queue.length} JSON messages`);
}
newItemsReceived += queue.length;
for (const item of queue) {
// Parse all the objects before calling into DOM updates to try to
// be a little faster, at the expense of allocating more memory.
const parsed = new Array(queue.length);
queue.forEach((item, idx) => {
newBytesReceived += item.length;
this.handleData(JSON.parse(item));
parsed[idx] = JSON.parse(item);
});
for (const obj of parsed) {
this.handleData(obj);
}
},
batchTimeWhenVisible,
Expand Down

0 comments on commit 9cf8f41

Please sign in to comment.