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

Watch events enhancements #57950

Merged
merged 4 commits into from Mar 27, 2024
Merged

Watch events enhancements #57950

merged 4 commits into from Mar 27, 2024

Conversation

sheetalkamat
Copy link
Member

@sheetalkamat sheetalkamat commented Mar 26, 2024

  • adds ignoreUpdate to directory watcher so we are not unnecessarily watching for update events if we dont care
  • Change protocol to get batched watch change notifications

Vscode PR reference: microsoft/vscode#193848

cc: @bpasero

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Mar 26, 2024
@typescript-bot
Copy link
Collaborator

Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @mjbvz, @zkat, and @joj for you. Feel free to loop in other consumers/maintainers if necessary.

@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.

@sheetalkamat sheetalkamat changed the title [WIP] Watch events enhancements Watch events enhancements Mar 27, 2024
@sheetalkamat sheetalkamat marked this pull request as ready for review March 27, 2024 18:59
path,
recursive: !!recursive,
// Special case node_modules as we watch it for changes to closed script infos as well
ignoreUpdate: !path.endsWith("/node_modules") ? true : undefined,
Copy link
Member

Choose a reason for hiding this comment

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

Can this path be \node_modules on Windows?

Copy link
Member

Choose a reason for hiding this comment

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

Slightly related: I did notice another watch request for node_modules/@types, so I wonder if these could also ignoreUpdate?

Copy link
Member Author

Choose a reason for hiding this comment

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

it isnt "\node_module" on windows because our paths are normalized.
We dont care about updates in node_modules/@types since thats not what we watch for file updates. We only watch node_modules for updates to scriptinfos that are anywhere including in @types so this condition suffices

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I think I misunderstood our discussion around changes in node_modules then. I had assumed TS only cares about added/deleted events in node_modules to rerun module resolution, but not for updates. So now with your change, folder watchers ignore updates unless its node_modules being watched?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. we only care about updates inside node_modules and no other folder.

Copy link
Member Author

Choose a reason for hiding this comment

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

Reference to code here https://github.com/microsoft/TypeScript/blob/main/src/server/editorServices.ts#L3102 this normally works out because with fs.watch most of the time we get "rename" event instead of "change" when doing npm i but with parcel you get update so that cannot be ignored from vscode watcher usage perspective

Copy link
Member

@bpasero bpasero Mar 27, 2024

Choose a reason for hiding this comment

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

Yeah I understand. My idea was to collect events to node_modules in the TS extension and then send you a single event per module that is impacted to the server. That can be a added event to emulate the rename you got from fs.watch. Its a bit of a hack and very specific to this case but would essentially reduce the event load on node_modules, which can be a huge source of file events. I do not have strong feelings though, now with the batching it might not make much of a difference.

Copy link
Member Author

Choose a reason for hiding this comment

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

What i meant by ignoreUpdate here is that we really dont care if there is file that was modified within that folder and thats true for any folder watched except node_modules. So from protocol wise this change looks good.

On whether to send single directory event for module inside node_modules or all files can be totally customized irrespective of this protocol change. In general, the more specific you are about the path the better reuse happens between programs. We were anyways getting these events from fs.watch and we handle both cases since the fileName may or may not be present when the event comes through fs.watch.

@DanielRosenwasser
Copy link
Member

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 27, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
cherry-pick this to release-5.4 ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

Hey, @DanielRosenwasser! I've created #57967 for you. This involved updating baselines; please check the diff.

@sheetalkamat sheetalkamat merged commit c87b5bc into main Mar 27, 2024
25 checks passed
@sheetalkamat sheetalkamat deleted the watchEventsEnhancements branch March 27, 2024 20:36
DanielRosenwasser pushed a commit that referenced this pull request Mar 27, 2024
Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 5.4.32 milestone Mar 28, 2024
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.

None yet

5 participants