ds300 / derivablejs

Functional Reactive State for JavaScript and TypeScript
Apache License 2.0
515 stars 23 forks source link

Optimize update arguments #109

Closed TrySound closed 6 years ago

TrySound commented 6 years ago

Suggest to prefer partial application with closure over library bindings

const add = param => prev => prev + param;
a.update(add(1));

/cc @andreypopp @ds300

andreypopp commented 6 years ago

Partial application means a closure allocation, right? Can we benchmark it?

TrySound commented 6 years ago

Hm.. funny. I'd say it's the fastest way since we do not distribute untranspiled code.

  "application": {
    "arguments": {
      "hz": 207.22860271599558,
      "rme": 0.8511124319233537,
      "samples": 85
    },
    "bind": {
      "hz": 1146.6444793281294,
      "rme": 1.0630412553036088,
      "samples": 89
    },
    "closure": {
      "hz": 1385.7883377519702,
      "rme": 1.1899308415523433,
      "samples": 91
    },
    "rest": {
      "hz": 1526.58855314177,
      "rme": 0.9115397150273621,
      "samples": 92
    }
  }