Skip to content

Commit 74a2fbf

Browse files
bpaseromustard-mh
authored andcommitted
watcher - perf improvements for non-recursive watching (microsoft#245644)
1 parent 213c601 commit 74a2fbf

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/vs/platform/files/common/diskFileSystemProvider.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,26 @@ export abstract class AbstractDiskFileSystemProvider extends Disposable implemen
6363
return this.watchNonRecursive(resource, opts);
6464
}
6565

66+
private getRefreshWatchersDelay(count: number): number {
67+
if (count > 200) {
68+
// If there are many requests to refresh, start to throttle
69+
// the refresh to reduce pressure. We see potentially thousands
70+
// of requests coming in on startup repeatedly so we take it easy.
71+
return 500;
72+
}
73+
74+
// By default, use a short delay to keep watchers updating fast but still
75+
// with a delay so that we can efficiently deduplicate requests or reuse
76+
// existing watchers.
77+
return 0;
78+
}
79+
6680
//#region File Watching (universal)
6781

6882
private universalWatcher: AbstractUniversalWatcherClient | undefined;
6983

7084
private readonly universalWatchRequests: IUniversalWatchRequest[] = [];
71-
private readonly universalWatchRequestDelayer = this._register(new ThrottledDelayer<void>(0));
85+
private readonly universalWatchRequestDelayer = this._register(new ThrottledDelayer<void>(this.getRefreshWatchersDelay(this.universalWatchRequests.length)));
7286

7387
private watchUniversal(resource: URI, opts: IWatchOptions): IDisposable {
7488
const request = this.toWatchRequest(resource, opts);
@@ -114,12 +128,9 @@ export abstract class AbstractDiskFileSystemProvider extends Disposable implemen
114128
}
115129

116130
private refreshUniversalWatchers(): void {
117-
118-
// Buffer requests for universal watching to decide on right watcher
119-
// that supports potentially watching more than one path at once
120131
this.universalWatchRequestDelayer.trigger(() => {
121132
return this.doRefreshUniversalWatchers();
122-
}).catch(error => onUnexpectedError(error));
133+
}, this.getRefreshWatchersDelay(this.universalWatchRequests.length)).catch(error => onUnexpectedError(error));
123134
}
124135

125136
private doRefreshUniversalWatchers(): Promise<void> {
@@ -155,7 +166,7 @@ export abstract class AbstractDiskFileSystemProvider extends Disposable implemen
155166
private nonRecursiveWatcher: AbstractNonRecursiveWatcherClient | undefined;
156167

157168
private readonly nonRecursiveWatchRequests: INonRecursiveWatchRequest[] = [];
158-
private readonly nonRecursiveWatchRequestDelayer = this._register(new ThrottledDelayer<void>(0));
169+
private readonly nonRecursiveWatchRequestDelayer = this._register(new ThrottledDelayer<void>(this.getRefreshWatchersDelay(this.nonRecursiveWatchRequests.length)));
159170

160171
private watchNonRecursive(resource: URI, opts: IWatchOptions): IDisposable {
161172

@@ -184,12 +195,9 @@ export abstract class AbstractDiskFileSystemProvider extends Disposable implemen
184195
}
185196

186197
private refreshNonRecursiveWatchers(): void {
187-
188-
// Buffer requests for nonrecursive watching to decide on right watcher
189-
// that supports potentially watching more than one path at once
190198
this.nonRecursiveWatchRequestDelayer.trigger(() => {
191199
return this.doRefreshNonRecursiveWatchers();
192-
}).catch(error => onUnexpectedError(error));
200+
}, this.getRefreshWatchersDelay(this.nonRecursiveWatchRequests.length)).catch(error => onUnexpectedError(error));
193201
}
194202

195203
private doRefreshNonRecursiveWatchers(): Promise<void> {

0 commit comments

Comments
 (0)