nebula-contrib / nebula-node

Nebula Graph Client for Node.js
26 stars 9 forks source link

使用findKey替代filter #28

Closed re0marb1e closed 10 months ago

re0marb1e commented 10 months ago

替换后性能提升很大 针对超过上万个节点的一层子图的数据转换,benchmark测试对比如下:

// 优化前
traverse x 0.25 ops/sec ±5.47% (20 runs sampled)
traverse
{
  "moe": 0.13541623338731565,
  "rme": 3.6953588948731206,
  "sem": 0.06469958594711689,
  "deviation": 0.28934534458768696,
  "mean": 3.6644947687000005,
  "sample": [
    3.41819225,
    3.629525334,
    3.915294291,
    4.119651583,
    4.426213667,
    3.814337834,
    3.489183708,
    3.888829125,
    3.412354375,
    3.58216675,
    3.925581417,
    3.825514958,
    3.40265525,
    3.5915570409999997,
    3.324650875,
    3.537536833,
    3.332048917,
    3.5182589159999997,
    3.733412333,
    3.402929917
  ],
  "variance": 0.08372072843456732
}
// 优化后
traverse x 0.57 ops/sec ±3.47% (21 runs sampled)
traverse
{
  "moe": 0.060402615606996446,
  "rme": 3.471986632011474,
  "sem": 0.02895619156615362,
  "deviation": 0.13269393968954085,
  "mean": 1.739713369,
  "sample": [
    1.6411605,
    1.644053667,
    1.662385708,
    1.757631875,
    1.756604125,
    1.5522004169999999,
    1.596555166,
    1.698327792,
    1.696909,
    1.73860075,
    1.807974458,
    1.8391250000000001,
    1.889619375,
    1.940904167,
    1.972651,
    2.020747166,
    1.554726834,
    1.6190627499999999,
    1.6645644160000002,
    1.705834208,
    1.774342375
  ],
  "variance": 0.017607681630331506
}
QingZ11 commented 10 months ago

替换后性能提升很大 针对超过上万个节点的一层子图的数据转换,benchmark测试对比如下:

// 优化前
traverse x 0.25 ops/sec ±5.47% (20 runs sampled)
traverse
{
  "moe": 0.13541623338731565,
  "rme": 3.6953588948731206,
  "sem": 0.06469958594711689,
  "deviation": 0.28934534458768696,
  "mean": 3.6644947687000005,
  "sample": [
    3.41819225,
    3.629525334,
    3.915294291,
    4.119651583,
    4.426213667,
    3.814337834,
    3.489183708,
    3.888829125,
    3.412354375,
    3.58216675,
    3.925581417,
    3.825514958,
    3.40265525,
    3.5915570409999997,
    3.324650875,
    3.537536833,
    3.332048917,
    3.5182589159999997,
    3.733412333,
    3.402929917
  ],
  "variance": 0.08372072843456732
}
// 优化后
traverse x 0.57 ops/sec ±3.47% (21 runs sampled)
traverse
{
  "moe": 0.060402615606996446,
  "rme": 3.471986632011474,
  "sem": 0.02895619156615362,
  "deviation": 0.13269393968954085,
  "mean": 1.739713369,
  "sample": [
    1.6411605,
    1.644053667,
    1.662385708,
    1.757631875,
    1.756604125,
    1.5522004169999999,
    1.596555166,
    1.698327792,
    1.696909,
    1.73860075,
    1.807974458,
    1.8391250000000001,
    1.889619375,
    1.940904167,
    1.972651,
    2.020747166,
    1.554726834,
    1.6190627499999999,
    1.6645644160000002,
    1.705834208,
    1.774342375
  ],
  "variance": 0.017607681630331506
}

Thank you for your contribution ~