[CONJS-220] study Js-sdsl Deque in place of denque Created: 2022-09-20  Updated: 2023-01-12  Resolved: 2023-01-12

Status: Closed
Project: MariaDB Connector/node.js
Component/s: performance
Affects Version/s: None
Fix Version/s: N/A

Type: Task Priority: Major
Reporter: Diego Dupin Assignee: Diego Dupin
Resolution: Won't Do Votes: 0
Labels: None


 Description   

see https://github.com/mariadb-corporation/mariadb-connector-nodejs/issues/209

connector make intense use of deque, using npm denque package. MIT license Js-sdsl Deque package might be a replacement, announcing 3x the performance of denque.

So:

  • ensure that package correspond to the needs
  • benchmark used operation
  • ensure code quality
  • ...


 Comments   
Comment by Diego Dupin [ 2023-01-12 ]

in our specific use-case, our benchmark performs better using denque: most of our use is push and shift and even if js-sdsl is faster in other things, denque performs better in this use-case
tested with :

const Benchmark = require('benchmark');
const { LinkList, Queue } = require('js-sdsl');
const QueueDenque = require('denque');
 
const t1 = new LinkList();
const t2 = new QueueDenque();
const t3 = new Queue(new Array(2000));
 
for (let i = 0; i < 600; i++) {
  t1.pushBack('elm');
  t2.push('elm');
  t3.push('elm');
}
 
var suite = new Benchmark.Suite();
 
// add tests
suite
  .add('LinkList with 1000 element push and shift', function () {
    t1.pushBack('elm');
    return t1.popFront();
  })
  .add('denque with 1000 element push and shift', function () {
    t2.push('elm');
    return t2.shift();
  })
  .add('Queue with 1000 element push and shift', function () {
    t3.push('elm');
    return t3.pop();
  })
  // add listeners
  .on('cycle', function (event) {
    console.log(String(event.target));
  })
  // run async
  .run({ async: true });

resulting in

 
LinkList with 1000 element push and front x 10,151,006 ops/sec ±3.79% (68 runs sampled)
denque with 1000 element push and shift x 171,003,836 ops/sec ±0.56% (94 runs sampled)
Queue with 1000 element push and shift x 19,941,066 ops/sec ±1.07% (95 runs sampled)

so closing as won't do

Generated at Thu Feb 08 03:23:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.