Skip to content

Commit

Permalink
Use splice() instead of repeated shift() to remove from queue (#106)
Browse files Browse the repository at this point in the history
Calling splice() is more efficient than shift()ing from the start of the
array up to batchSize(default of 300) times.
The amount of time taken by shift() is proportional to the length of the
array. This would only matter for large arrays.
  • Loading branch information
TysonAndre authored Oct 6, 2023
1 parent 99d8fb3 commit 568f3fc
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions lib/client/ingest/signal_fx_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,7 @@ SignalFxClient.prototype._encodeEvent = function (_event) {
SignalFxClient.prototype.startAsyncSend = function () {
var _this = this;
// Send post request in separate thread
var datapointsList = [];
while (_this.queue.length !== 0 && datapointsList.length < _this.batchSize) {
datapointsList.push(_this.queue.shift());
}
var datapointsList = _this.queue.splice(0, _this.batchSize);

if (datapointsList.length > 0) {
var dataToSend = _this._batchData(datapointsList);
Expand Down

0 comments on commit 568f3fc

Please sign in to comment.