Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tune FAR aggregation #49581

Merged
merged 4 commits into from
Jun 16, 2022
Merged

Tune FAR aggregation #49581

merged 4 commits into from
Jun 16, 2022

Conversation

amcasey
Copy link
Member

@amcasey amcasey commented Jun 16, 2022

In making the work queue management more intelligible, we centralized the redundancy check at dequeue time. As a result, the queue tends to get very large (~1.6M items for SyntaxKind in this repo) and dequeuing via shift is too slow to do that many times. This change makes a few tweaks:

  1. Use Project identity for de-duping and only maintain a set of keys for loadAncestorProjectTree
  2. Attempt to filter prior to insertion
  3. Use splice if many consecutive work queue items will be discarded.

On my box, this cuts FAR for SyntaxKind in parser.ts from 38 minutes to 20 seconds (vs 26 seconds for 4.6) (we could do better, but effectively decided not to optimize this worst case scenario).

In making the work queue management more intelligible, we centralized the redundancy check at dequeue time.  As a result, the queue tends to get very large (~1.6M items for `SyntaxKind` in this repo) and dequeuing via `shift` is too slow to do that many times.  This change makes a few tweaks:

1. Use `Project` identity for de-duping and only maintain a set of keys for `loadAncestorProjectTree`
2. Attempt to filter prior to insertion
3. Use `splice` if many consecutive work queue items will be discarded.

On my box, this cuts FAR for `SyntaxKind` in parser.ts from 38 minutes to 20 seconds (we could do better, but effectively decided not to optimize this worst case scenario).
@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jun 16, 2022
Copy link
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

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

I think I understand it; would be good to get another pair of eyes and get it in by today.

@DanielRosenwasser
Copy link
Member

Ah, @andrewbranch already reviewed it. Still curious about the comments I left.

@amcasey
Copy link
Member Author

amcasey commented Jun 16, 2022

After a bunch of second-guessing myself, I'm pretty sure the null checks are now correct.

@amcasey amcasey merged commit 01ba3a4 into microsoft:main Jun 16, 2022
@amcasey amcasey deleted the FarQueue branch June 16, 2022 23:11
queue.splice(0, skipCount);
}

// NB: we may still skip if it's a project reference redirect
const { project, location } = queue.shift()!;
Copy link
Member

Choose a reason for hiding this comment

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

Would it make more sense long-term not to de-queue at all? Just iterate through and toss the array at the end?

Copy link
Member

Choose a reason for hiding this comment

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

I guess not, then it would just get longer and longer.

@DanielRosenwasser
Copy link
Member

I realized that this is actually a pretty big 4.7 regression. If we have another patch release, it may be worth cherry-picking into 4.7.

@typescript-bot cherry-pick this to release-4.7

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 21, 2022

Heya @DanielRosenwasser, I've started to run the task to cherry-pick this into release-4.7 on this PR at 7f1e10c. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

Hey @DanielRosenwasser, I couldn't open a PR with the cherry-pick. (You can check the log here). You may need to squash and pick this PR into release-4.7 manually.

@DanielRosenwasser
Copy link
Member

Unfortunately looks like a pretty non-trivial cherry-pick. 😕

@amcasey
Copy link
Member Author

amcasey commented Jun 21, 2022

I realized that this is actually a pretty big 4.7 regression. If we have another patch release, it may be worth cherry-picking into 4.7.

@typescript-bot cherry-pick this to release-4.7

@DanielRosenwasser Did you confirm that? I'm pretty sure this was regressed by the second part of my FAR cleanup, which was new in 4.8.

Would it make more sense long-term not to de-queue at all?

Yes, post-beta I plan to see whether I can eliminate the shift altogehter.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 21, 2022

Heya @amcasey, I've started to run the task to cherry-pick this into release-4.7 on this PR at 7f1e10c. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

Hey @amcasey, I couldn't open a PR with the cherry-pick. (You can check the log here). You may need to squash and pick this PR into release-4.7 manually.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jun 21, 2022

@DanielRosenwasser Did you confirm that? I'm pretty sure this was regressed by the second part of my FAR cleanup, which was new in 4.8.

Okay, so just to be clear 4.7 is not exhibiting a 38 minute FAR search for SyntaxKind? 😅

@andrewbranch
Copy link
Member

38 minutes to 20 seconds

Oh, you know what, I initially read this as "38 seconds to 20 seconds" and I still thought that was pretty serious

@amcasey
Copy link
Member Author

amcasey commented Jun 21, 2022

@DanielRosenwasser Did you confirm that? I'm pretty sure this was regressed by the second part of my FAR cleanup, which was new in 4.8.

Okay, so just to be clear 4.7 is not exhibiting a 38 minute FAR search for SyntaxKind? 😅

I didn't specifically verify, but the shift is new in 4.8. If you want to confirm you can just FAR on SyntaxKind in parser.ts.

amcasey added a commit to amcasey/TypeScript that referenced this pull request Jun 21, 2022
amcasey added a commit that referenced this pull request Jun 24, 2022
….shift` (#49623)

* Add a simple queue implementation with better performance than `Array.shift`

This lets us clean up the hack introduced in #49581

* Correct typo

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants