Skip to content

Commit 666c7e4

Browse files
committed
Batch reading content files to prevent too many open files error (#12079)
* Refactor * Refactor * Batch content file reads in Node into groups of 500 We shouldn’t need to do this for our Rust code because it utilizes Rayon’s default thread pool for parallelism. This threadpool has roughly the number of cores as the number of available threads except when overridden. This generally is much, much lower than 500 and can be explicitly overridden via an env var to work around potential issues with open file descriptors if anyone ever runs into that. * Fix sequential/parallel flip * Update changelog
1 parent 8012d18 commit 666c7e4

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Fix incorrectly generated CSS when using square brackets inside arbitrary properties ([#11709](https://github.com/tailwindlabs/tailwindcss/pull/11709))
1919
- Make `content` optional for presets in TypeScript types ([#11730](https://github.com/tailwindlabs/tailwindcss/pull/11730))
2020
- Handle variable colors that have variable fallback values ([#12049](https://github.com/tailwindlabs/tailwindcss/pull/12049))
21+
- Batch reading content files to prevent `too many open files` error ([#12079](https://github.com/tailwindlabs/tailwindcss/pull/12079))
2122

2223
## [3.3.3] - 2023-07-13
2324

src/lib/expandTailwindAtRules.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,26 @@ export default function expandTailwindAtRules(context) {
145145
// getClassCandidatesOxide(file, transformer(content), extractor, candidates, seen)
146146
// }
147147
} else {
148-
await Promise.all(
149-
context.changedContent.map(async ({ file, content, extension }) => {
150-
let transformer = getTransformer(context.tailwindConfig, extension)
151-
let extractor = getExtractor(context, extension)
152-
content = file ? await fs.promises.readFile(file, 'utf8') : content
153-
getClassCandidates(transformer(content), extractor, candidates, seen)
154-
})
155-
)
148+
/** @type {[item: {file?: string, content?: string}, meta: {transformer: any, extractor: any}][]} */
149+
let regexParserContent = []
150+
151+
for (let item of context.changedContent) {
152+
let transformer = getTransformer(context.tailwindConfig, item.extension)
153+
let extractor = getExtractor(context, item.extension)
154+
regexParserContent.push([item, { transformer, extractor }])
155+
}
156+
157+
const BATCH_SIZE = 500
158+
159+
for (let i = 0; i < regexParserContent.length; i += BATCH_SIZE) {
160+
let batch = regexParserContent.slice(i, i + BATCH_SIZE)
161+
await Promise.all(
162+
batch.map(async ([{ file, content }, { transformer, extractor }]) => {
163+
content = file ? await fs.promises.readFile(file, 'utf8') : content
164+
getClassCandidates(transformer(content), extractor, candidates, seen)
165+
})
166+
)
167+
}
156168
}
157169

158170
env.DEBUG && console.timeEnd('Reading changed files')

0 commit comments

Comments
 (0)