Skip to content

Commit bbdd48b

Browse files
authored
Switch to async.mapLimit (#170)
This will use the number of threads -1 which should significantly speed things up with a huge list of files.
1 parent ec0cfba commit bbdd48b

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lib/htmllint.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const os = require('os');
34
const path = require('path');
45
const { execFile } = require('child_process');
56
const async = require('async');
@@ -15,6 +16,10 @@ const MAX_CHARS = 5000;
1516
// https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
1617
const MAX_BUFFER = 20_000 * 1024;
1718

19+
// eslint-disable-next-line unicorn/explicit-length-check
20+
const CPUS = os.cpus() && os.cpus().length;
21+
const THREADS = CPUS > 2 ? CPUS - 1 : 1;
22+
1823
// Replace left/right quotation marks with normal quotation marks
1924
function normalizeQuotationMarks(string) {
2025
if (string) {
@@ -132,7 +137,7 @@ function htmllint(config, done) {
132137
const files = config.files.map(file => path.normalize(file));
133138
const chunks = chunkify(files, MAX_CHARS);
134139

135-
async.mapSeries(chunks, (chunk, cb) => {
140+
async.mapLimit(chunks, THREADS, (chunk, cb) => {
136141
const args = javaArgs(java, chunk, config);
137142

138143
execFile('java', args, { maxBuffer: MAX_BUFFER, shell: true }, (error, stdout, stderr) => {

0 commit comments

Comments
 (0)