floatdrop/p-batch

addAll optimization

Open

#1 创建于 2017年2月20日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)JavaScript (0 fork)github user discovery
enhancementhelp wanted

仓库指标

Star
 (1 star)
PR 合并指标
 (PR 指标待抓取)

描述

From benchmarks it is clear, that batching can reduce performance a lot and should be applied with care (read for heavy network operations):

load x 896,756 ops/sec ±3.82% (79 runs sampled)
PBatch x 5,118 ops/sec ±2.37% (79 runs sampled)
dataloader x 4,931 ops/sec ±1.65% (83 runs sampled)

But we have cases, when loader can be optimised with SSE computation and it looks like a case for batching. In such cases we can gather multiple keys in a loop and launch addKeys for them. But performance will be eaten by spawning Promise, which we do not use! To reduce spawned Promise count we can:

  • addAll can call loader immediately
  • addAll can store group of keys and resolve only one promise, but still call load on multiple groups

In both ways it should respect maxBatchSize option.

First way can be faster, because we do not need to concatenate keys to this._batch, but this leads to underutilization of loader.

Maybe an option to addAll could switch between cases: immediately, deferred and ratio (which means – if there are more keys than maxBatchSize * ratio then do immediately, otherwise deferred).


https://github.com/facebook/dataloader/issues/70

贡献者指南