Skip to content

Commit 90890ee

Browse files
committed
style(glob): trim comments to at most four lines
1 parent 775e0f2 commit 90890ee

3 files changed

Lines changed: 14 additions & 41 deletions

File tree

src/utils/glob-oom.test.mts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,10 @@ function filterJsonFiles(filepath: string): boolean {
1616
// This suite lives in its own file, with no mock-fs node_modules preload, so the
1717
// large ignore set it builds is the only significant allocation in the worker.
1818
describe('globWithGitIgnore() large monorepo memory', () => {
19-
// Regression: `socket fix` / `socket scan` aborted with
20-
// `FATAL ERROR: CALL_AND_RETRY_LAST … heap out of memory` (SIGABRT) on large
21-
// monorepos. globWithGitIgnore discovers every nested .gitignore and unions
22-
// their patterns; handing that whole set to fast-glob's `ignore` option made
23-
// fast-glob re-compile and re-test the entire array inside every directory
24-
// scan, so tens of thousands of patterns exhausted V8 code space. Routing the
25-
// gitignore set through a single reused `ignore` instance bounds the cost. The
26-
// flat union built below is large enough to crash the old path; the walk must
27-
// instead complete and return the right manifests. Uses the real filesystem
28-
// because mock-fs would hold every pattern in memory and add its own overhead.
19+
// Regression: scanning a large monorepo OOM'd because the whole unioned
20+
// gitignore set was handed to fast-glob, which recompiled it per directory
21+
// scan. The 100k-pattern tree below crashes the pre-fix path; the walk must
22+
// complete with the right manifests. Real fs (mock-fs is too heavy here).
2923
it('does not exhaust memory on a huge nested-.gitignore pattern set', async () => {
3024
const realTmp = mkdtempSync(path.join(tmpdir(), 'socket-glob-oom-'))
3125
try {

src/utils/glob.mts

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -291,28 +291,10 @@ export async function globWithGitIgnore(
291291
}
292292
}
293293

294-
// Match every gitignore-derived pattern through a single reused `ignore`
295-
// instance instead of handing the whole set to fast-glob's native `ignore`
296-
// option. fast-glob re-compiles and re-tests its entire ignore array inside
297-
// each directory scan (`node::fs::AfterScanDir`), so a large monorepo whose
298-
// nested `.gitignore` files union to tens of thousands of patterns aborts with
299-
// `CALL_AND_RETRY_LAST … heap out of memory`. Raising `--max-old-space-size`
300-
// does not reliably help: much of the cost is regex executable code in V8 code
301-
// space rather than the data heap. The `ignore` package compiles each rule
302-
// once and memoizes it, so the cost scales with the pattern count rather than
303-
// being multiplied by the number of directories walked. fast-glob
304-
// keeps only the small, bounded set it needs to PRUNE directories during the
305-
// walk (`defaultIgnore`, which already excludes node_modules and .git, plus
306-
// the anchored CLI minimatch ignores); the high-cardinality gitignore set is
307-
// applied per streamed entry by `ig` below. The `ignore` package also honors
308-
// negated re-includes, which fast-glob, globby, and tinyglobby cannot express.
309-
// The negated-pattern path already worked this way; routing both cases through
310-
// it removes the asymmetry that left the common, non-negated case crashing on
311-
// large repos.
312-
// Match fast-glob's case sensitivity (its `caseSensitiveMatch` defaults to
313-
// true) so routing the non-negated path through the `ignore` package does not
314-
// silently start matching case-insensitively, which is the `ignore` package's
315-
// own default.
294+
// Match the high-cardinality gitignore set through one reused `ignore`
295+
// instance, not fast-glob's `ignore` (which recompiles its whole array per
296+
// directory scan and OOMs on tens of thousands of patterns); fast-glob keeps
297+
// only the bounded prune set. `ignorecase` tracks fast-glob's default.
316298
const ig = ignore({
317299
ignorecase: additionalOptions.caseSensitiveMatch === false,
318300
}).add([...ignores])
@@ -343,11 +325,10 @@ export async function globWithGitIgnore(
343325
globOptions,
344326
) as AsyncIterable<string>
345327
for await (const p of stream) {
346-
// Note: the input files must be INSIDE the cwd. If you get strange looking
347-
// relative path errors here, most likely your path is outside the given cwd.
348328
// Normalize to POSIX separators: the `ignore` patterns are forward-slash
349-
// anchored (see ignoreFileLinesToGlobPatterns), so a Windows backslash path
350-
// from path.relative would never match them.
329+
// anchored (ignoreFileLinesToGlobPatterns), so a Windows backslash path from
330+
// path.relative would never match. Input must be inside cwd, else
331+
// path.relative returns an odd `..`-prefixed relative path.
351332
const relPath = normalizePath(
352333
globOptions.absolute ? path.relative(cwd, p) : p,
353334
)

src/utils/path-resolve.mts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,9 @@ export async function getPackageFilesForScan(
145145
} as PackageFilesForScanOptions
146146

147147
// Apply the supported files filter during streaming so globWithGitIgnore drops
148-
// non-manifest paths as they are walked instead of collecting every path first.
149-
// This bounds RESULT-path memory on large monorepos with 100k+ files. Note it
150-
// does NOT bound the gitignore ignore-pattern memory: that OOM (regex compile
151-
// exhausting V8 code space) is handled inside globWithGitIgnore by matching the
152-
// gitignore set through a single reused `ignore` instance.
148+
// non-manifest paths as they are walked. This bounds RESULT-path memory; it
149+
// does NOT bound the gitignore ignore-pattern memory (that OOM is handled
150+
// inside globWithGitIgnore via a single reused `ignore` instance).
153151
const filter = createSupportedFilesFilter(supportedFiles)
154152

155153
const normalizedInputPaths = inputPaths.map(p =>

0 commit comments

Comments
 (0)