Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

VM Turns are not properly detected, could impact perf #59

@vicb

Description

@vicb

This is how to "run some function at the end of each VM turn" from the README

zone.fork({
  afterTask: function () {
    // do some cleanup
  }
}).run(function () {
  // do stuff
});

But consider the following code:

function schedule() {
  setTimeout(function() { console.log('setTimeout')}, 0);
  Promise.resolve('promise')
    .then(function(_) { console.log(_); return 'then'; })
    .then(function(_) { console.log(_); })
  ;
}

zone
  .fork({
    afterTask: function () { console.log('vm turn end'); }
  })
  .run(schedule);

If VM turn were properly detected, the output shoud be

vm turn end
// microtask queue
promise
then
// macrotask queue
setTimeout
vm turn end

but the actual output is

vm turn end
promise
vm turn end
then
vm turn end
setTimeout
vm turn end

I believe this means that the change detection would run 3x more than required in Angular2 on such a code.

/cc @vsavkin @btford

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions