arqex / freezer

A tree data structure that emits events on updates, even if the modification is triggered by one of the leaves, making it easier to think in a reactive way.
MIT License
1.28k stars 56 forks source link

For big object,or may be too many levels,set will slow down #58

Closed Daley closed 8 years ago

Daley commented 8 years ago
function testFreezer() {
  var cfg = JSON.parse(fs.readFileSync("config/export.data"));
  var freezer = new Freezer(cfg);
  freezer.on('update', function (updated) {
    console.log("........update");
  });

  var vo = freezer.get().space[0].projects[0];
  console.log("start test");

  var getVar = function () {
    var idx = (Math.random() * vo.vars.length) >> 0;   
    return vo.vars[idx];
  }

  setInterval(function () {
    var s = Math.random() + "";
    var val = getVar();
    console.time("startSet");
    val.set("val", s);
    console.timeEnd("startSet");
  }, 100);
}
arqex commented 8 years ago

Hi Daley,

Thanks for contacting, can you sent me the export.data file to have a look at what's happening?

Thanks

Daley commented 8 years ago

"export.data" structure: https://github.com/Daley/BatWorker/blob/master/public/export.data you can copy some element to make it bigger

Thank you very much

Daley commented 8 years ago

sorry arqex,It's my fault!

function testFreezer() {
  var cfg = JSON.parse(fs.readFileSync("config/export.data"));
  var freezer = new Freezer(cfg);
  freezer.on('update', function (updated) {
    console.log("........update");
  });

  console.log("start test");

  var getVar = function () {
    var vo = freezer.get().space[0].projects[0];
    var idx = (Math.random() * vo.vars.length) >> 0;   
    return vo.vars[idx];
  }

  setInterval(function () {
    var s = Math.random() + "";
    var val = getVar();
    console.time("startSet");
    val.set("val", s);
    console.timeEnd("startSet");
  }, 100);
}

It's ok

arqex commented 8 years ago

That's a refief! I have started to do some optimizations to freezer that I hope can boost a bit its performance. They will be included in the next version.

All thanks to this issue :) It is always nice to have some feedback.