Skip to content

Commit 8760e41

Browse files
authored
perf: do not watch files in node_modules #3440
Problem: When setting up file watchers, Toolkit includes unwanted directories such as "node_modules". The default vscode setting `search.exclude` excludes "node_modules", but `vscode.workspace.findFiles()` uses the `files.exclude` as its default exclude pattern. #3216 Solution: Specify an exclude pattern that matches the defaults from both `search.exclude` and `files.exclude`, plus some other things like ".aws-sam/". Do this for all `WatchedFiles` subclasses because there is no case where we want to watch files in any of these folders. BEFORE: 2023-05-10 04:24:34 [VERBOSE]: cfn: template registry setup took 257ms AFTER: 2023-05-10 04:23:22 [VERBOSE]: cfn: template registry setup took 53ms
1 parent a0a9280 commit 8760e41

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/shared/fs/templateRegistry.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import globals from '../extensionGlobals'
1717
import { isUntitledScheme, normalizeVSCodeUri } from '../utilities/vsCodeUtils'
1818
import { sleep } from '../utilities/timeoutUtils'
1919
import { localize } from '../utilities/vsCodeUtils'
20+
import { PerfLog } from '../logger/logger'
2021

2122
export class CloudFormationTemplateRegistry extends WatchedFiles<CloudFormation.Template> {
2223
protected name: string = 'CloudFormationTemplateRegistry'
@@ -90,10 +91,10 @@ export class AsyncCloudFormationTemplateRegistry {
9091
private readonly instance: CloudFormationTemplateRegistry,
9192
asyncSetupFunc: (instance: CloudFormationTemplateRegistry) => Promise<void>
9293
) {
93-
getLogger().info('cfn: starting template registry setup.')
94+
const perflog = new PerfLog('cfn: template registry setup')
9495
asyncSetupFunc(instance).then(() => {
9596
this.isSetup = true
96-
getLogger().info('cfn: template registry setup successful.')
97+
perflog.done()
9798
})
9899
}
99100

@@ -120,11 +121,11 @@ export class AsyncCloudFormationTemplateRegistry {
120121
// Allows for new message to be created if templateRegistry variable attempted to be used again
121122
this.setupProgressMessage = undefined
122123
})
123-
getLogger().info('cfn: Waiting for template registry setup to complete.')
124+
getLogger().debug('cfn: getInstance() requested, still initializing')
124125
while (!this.isSetup) {
125126
await sleep(2000)
126127
}
127-
getLogger().info('cfn: Finished waiting for template registry setup.')
128+
getLogger().debug('cfn: getInstance() ready')
128129
}
129130
)
130131
}

src/shared/fs/watchedFiles.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import * as pathutils from '../utilities/pathUtils'
99
import * as path from 'path'
1010
import { isUntitledScheme, normalizeVSCodeUri } from '../utilities/vsCodeUtils'
1111

12+
/**
13+
* Prevent `findFiles()` from recursing into these directories.
14+
*
15+
* `findFiles()` defaults to the vscode `files.exclude` setting, which by default does not exclude "node_modules/".
16+
*/
17+
const alwaysExclude = '**/{.aws-sam,.git,.svn,.hg,.rvm,.gem,.project,node_modules,venv,bower_components}/'
18+
1219
export interface WatchedItem<T> {
1320
/**
1421
* The absolute path to the file
@@ -224,7 +231,7 @@ export abstract class WatchedFiles<T> implements vscode.Disposable {
224231
public async rebuild(): Promise<void> {
225232
this.reset()
226233
for (const glob of this.globs) {
227-
const itemUris = await vscode.workspace.findFiles(glob)
234+
const itemUris = await vscode.workspace.findFiles(glob, alwaysExclude)
228235
for (const item of itemUris) {
229236
await this.addItemToRegistry(item, true)
230237
}

0 commit comments

Comments
 (0)