floatdrop/p-batch

addAll optimization

Open

#1 ouverte le 20 févr. 2017

Voir sur GitHub
 (0 commentaires) (0 réactions) (0 assignés)JavaScript (0 forks)github user discovery
enhancementhelp wanted

Métriques du dépôt

Stars
 (1 star)
Métriques de merge PR
 (Métriques PR en attente)

Description

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

Guide contributeur