Skip to content

fix(debug): don't insert task boundaries between events - #88459

Merged
Connor Peet (connor4312) merged 2 commits into
masterfrom
feat/debug-event-boundary
Jan 13, 2020
Merged

Connor Peet (connor4312) merged 2 commits into
masterfrom
feat/debug-event-boundary

Conversation

@connor4312

Copy link
Copy Markdown
Member

See discussion in microsoft/vscode-js-debug#206.

This PR adjusts logic such that we only assert task boundaries around
requests and responses, rather than around every single event. I believe
this will solve the primary case where misordering can happen, as given
in the existing unit test and described more verbosely in the doc
comment in this PR.

A more conservative approach would be to only omit the boundary between
events of the same type. That would be safer, but I browsing through
the code I didn't see any cases where it looked like we could get
tripped up by bucketing here (e.g. cases where we resolve a deferred
promise in an event handler).

Seems to fix the performance issue for me.

cc Dmitry Gozman (@dgozman) and SteVen Batten (@sbatten) roblourens fyi

See discussion in microsoft/vscode-js-debug#206.

This PR adjusts logic such that we only assert task boundaries around
requests and responses, rather than around every single event. I believe
this will solve the primary case where misordering can happen, as given
in the existing unit test and described more verbosely in the doc
comment in this PR.

A more conservative approach would be to only omit the boundary between
events of the same type. That would be safer, but I browsing through
the code I didn't see any cases where it looked like we could get
tripped up by bucketing here (e.g. cases where we resolve a deferred
promise in an event handler).

Seems to fix the performance issue for me.
@connor4312

Copy link
Copy Markdown
Member Author

Test issue appears unrelated

* is assigned if they're processed in the same task. Inserting a task
* boundary avoids this issue.
*/
protected needsTaskBoundaryBetween(messageA: DebugProtocol.ProtocolMessage, messageB: DebugProtocol.ProtocolMessage) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal preference is that this should be a helper function not a protected method on the abstractDebugAdapter

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought was that if an adapter implementation does something where they need a task boundary between a certain event type, they could override this method with their own check.

@isidorn Isidor Nikolic (isidorn) added this to the January 2020 milestone Jan 13, 2020
@isidorn

Isidor Nikolic (isidorn) commented Jan 13, 2020 •

Copy link
Copy Markdown

Connor Peet (@connor4312) nice work!
I left a minor comment in the code, apart from that Is it possible to write a unit test to catch the issue which we are fixing (there are no longer that many timeouts). I do not have a good idea how to do this, but wanted to check with you. Maybe MockDebugAdapter could remember the timeOut count it did, and at the end of the test we assert that number (it shuold be lower than before the changes).

Both of my comments are "optional" so feel free to merge in -> approved.
Sicne this is a performance regression which we should fix I have assigned it to this milestone.

@dgozman

Copy link
Copy Markdown
Contributor

The change looks good to me.

For the test, I'd suggest something like this to ensure we are called in the same microtask:

this._counter = 0;
this._sameMircroTask = true;
...
onOutput(event => {
  if (++this._counter === 1) {
    Promise.resolve().then(() => this._sameMircroTask = false);
  } else {
    assert(this._sameMircroTask);
  }
});

@connor4312

Copy link
Copy Markdown
Member Author

Yea I think Dmitry's approach is good for a test case. It's hard to reliably test speed but we can make sure events get processed together.

@connor4312
Connor Peet (connor4312) merged commit 5e1dbb1 into master Jan 13, 2020
@connor4312
Connor Peet (connor4312) deleted the feat/debug-event-boundary branch January 13, 2020 19:47
Martin Aeschlimann (aeschli) pushed a commit that referenced this pull request Jan 13, 2020
* fix(debug): don't insert task boundaries between events

See discussion in microsoft/vscode-js-debug#206.

This PR adjusts logic such that we only assert task boundaries around
requests and responses, rather than around every single event. I believe
this will solve the primary case where misordering can happen, as given
in the existing unit test and described more verbosely in the doc
comment in this PR.

A more conservative approach would be to only omit the boundary between
events of the same type. That would be safer, but I browsing through
the code I didn't see any cases where it looked like we could get
tripped up by bucketing here (e.g. cases where we resolve a deferred
promise in an event handler).

Seems to fix the performance issue for me.

* fixup! add unit tests for ordering
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants