Skip to content

Commit 5a65b24

Browse files
committed
Improvements to benchmarking debug logs. debug now logs total passthrough copy file weight.
1 parent 0526bff commit 5a65b24

8 files changed

+63
-37
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"debug": "^4.3.5",
124124
"dependency-graph": "^1.0.0",
125125
"fast-glob": "^3.3.2",
126+
"filesize": "^10.1.4",
126127
"graceful-fs": "^4.2.11",
127128
"gray-matter": "^4.0.3",
128129
"is-glob": "^4.0.3",

src/Eleventy.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { performance } from "node:perf_hooks";
33
import { TemplatePath } from "@11ty/eleventy-utils";
44
import BundlePlugin from "@11ty/eleventy-plugin-bundle";
55
import debugUtil from "debug";
6+
import { filesize } from "filesize";
67

78
import TemplateData from "./Data/TemplateData.js";
89
import TemplateWriter from "./TemplateWriter.js";
@@ -375,6 +376,7 @@ class Eleventy {
375376
let slashRet = [];
376377

377378
if (copyCount) {
379+
debug("Total passthrough copy aggregate size: %o", filesize(this.writer.getCopySize()));
378380
slashRet.push(`Copied ${chalk.bold(copyCount)}`);
379381
}
380382

src/TemplateContent.js

+28-27
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ class TemplateContent {
385385
return [cacheable, key, inputPathMap, useCache];
386386
}
387387

388-
async compile(str, bypassMarkdown, engineOverride) {
388+
async compile(str, options = {}) {
389+
let { type, bypassMarkdown, engineOverride } = options;
390+
389391
let tr = await this.getTemplateRender();
390392

391393
if (engineOverride !== undefined) {
@@ -396,7 +398,7 @@ class TemplateContent {
396398
}
397399

398400
if (bypassMarkdown && !this.engine.needsCompilation(str)) {
399-
return async function () {
401+
return function () {
400402
return str;
401403
};
402404
}
@@ -428,8 +430,9 @@ class TemplateContent {
428430
}
429431
}
430432

431-
let templateBenchmark = this.bench.get("Template Compile");
432-
let inputPathBenchmark = this.bench.get(`> Compile > ${this.inputPath}`);
433+
let typeStr = type ? ` ${type}` : "";
434+
let templateBenchmark = this.bench.get(`Template Compile${typeStr}`);
435+
let inputPathBenchmark = this.bench.get(`> Compile${typeStr} > ${this.inputPath}`);
433436
templateBenchmark.before();
434437
inputPathBenchmark.before();
435438
let fn = await tr.getCompiledTemplate(str);
@@ -491,15 +494,13 @@ class TemplateContent {
491494
return this._renderFunction(str, data);
492495
}
493496

494-
return this._render(str, data, true);
497+
return this._render(str, data, {
498+
type: "Computed Data",
499+
bypassMarkdown: true,
500+
});
495501
}
496502

497503
async renderPermalink(permalink, data) {
498-
this.bench.get("(count) Render Permalink").incrementCount();
499-
this.bench
500-
.get(`(count) > Render Permalink > ${this.inputPath}${this._getPaginationLogSuffix(data)}`)
501-
.incrementCount();
502-
503504
let permalinkCompilation = this.engine.permalinkNeedsCompilation(permalink);
504505

505506
// No string compilation:
@@ -528,11 +529,17 @@ class TemplateContent {
528529
return this._renderFunction(permalink, data);
529530
}
530531

531-
return this._render(permalink, data, true);
532+
return this._render(permalink, data, {
533+
type: "Permalink",
534+
bypassMarkdown: true,
535+
});
532536
}
533537

534538
async render(str, data, bypassMarkdown) {
535-
return this._render(str, data, bypassMarkdown);
539+
return this._render(str, data, {
540+
bypassMarkdown,
541+
type: "",
542+
});
536543
}
537544

538545
_getPaginationLogSuffix(data) {
@@ -551,13 +558,19 @@ class TemplateContent {
551558
return suffix.join("");
552559
}
553560

554-
async _render(str, data, bypassMarkdown) {
561+
async _render(str, data, options = {}) {
562+
let { bypassMarkdown, type } = options;
563+
555564
try {
556565
if (bypassMarkdown && !this.engine.needsCompilation(str)) {
557566
return str;
558567
}
559568

560-
let fn = await this.compile(str, bypassMarkdown, data[this.config.keys.engineOverride]);
569+
let fn = await this.compile(str, {
570+
bypassMarkdown,
571+
engineOverride: data[this.config.keys.engineOverride],
572+
type,
573+
});
561574

562575
if (fn === undefined) {
563576
return;
@@ -567,29 +580,17 @@ class TemplateContent {
567580

568581
// Benchmark
569582
let templateBenchmark = this.bench.get("Render");
570-
// Skip benchmark for each individual pagination entry (very busy output)
571-
let logRenderToOutputBenchmark = "pagination" in data;
572583
let inputPathBenchmark = this.bench.get(
573-
`> Render > ${this.inputPath}${this._getPaginationLogSuffix(data)}`,
584+
`> Render${type ? ` ${type}` : ""} > ${this.inputPath}${this._getPaginationLogSuffix(data)}`,
574585
);
575-
let outputPathBenchmark;
576-
if (data.page?.outputPath && logRenderToOutputBenchmark) {
577-
outputPathBenchmark = this.bench.get(`> Render to > ${data.page.outputPath}`);
578-
}
579586

580587
templateBenchmark.before();
581588
if (inputPathBenchmark) {
582589
inputPathBenchmark.before();
583590
}
584-
if (outputPathBenchmark) {
585-
outputPathBenchmark.before();
586-
}
587591

588592
let rendered = await fn(data);
589593

590-
if (outputPathBenchmark) {
591-
outputPathBenchmark.after();
592-
}
593594
if (inputPathBenchmark) {
594595
inputPathBenchmark.after();
595596
}

src/TemplatePassthrough.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class TemplatePassthrough {
240240
}
241241

242242
let fileCopyCount = 0;
243+
let fileSizeCount = 0;
243244
let map = {};
244245
let b = this.benchmarks.aggregate.get("Passthrough Copy File");
245246
// returns a promise
@@ -250,13 +251,15 @@ class TemplatePassthrough {
250251
map[copyOp.src] = copyOp.dest;
251252
b.before();
252253
})
253-
.on(copy.events.COPY_FILE_COMPLETE, (/*copyOp*/) => {
254+
.on(copy.events.COPY_FILE_COMPLETE, (copyOp) => {
254255
fileCopyCount++;
256+
fileSizeCount += copyOp.stats.size;
255257
b.after();
256258
})
257259
.then(() => {
258260
return {
259261
count: fileCopyCount,
262+
size: fileSizeCount,
260263
map,
261264
};
262265
});
@@ -311,15 +314,18 @@ class TemplatePassthrough {
311314
(results) => {
312315
// collate the count and input/output map results from the array.
313316
let count = 0;
317+
let size = 0;
314318
let map = {};
315319

316320
for (let result of results) {
317321
count += result.count;
322+
size += result.size;
318323
Object.assign(map, result.map);
319324
}
320325

321326
return {
322327
count,
328+
size,
323329
map,
324330
};
325331
},

src/TemplatePassthroughManager.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class TemplatePassthroughManager {
2626

2727
reset() {
2828
this.count = 0;
29+
this.size = 0;
2930
this.conflictMap = {};
3031
this.incrementalFile = null;
3132
debug("Resetting counts to 0");
@@ -109,6 +110,10 @@ class TemplatePassthroughManager {
109110
return this.count;
110111
}
111112

113+
getCopySize() {
114+
return this.size;
115+
}
116+
112117
setFileSystemSearch(fileSystemSearch) {
113118
this.fileSystemSearch = fileSystemSearch;
114119
}
@@ -145,7 +150,7 @@ class TemplatePassthroughManager {
145150
// Eventually we’ll want to move all of this to use Node’s fs.cp, which is experimental and only on Node 16+
146151

147152
return pass.write().then(
148-
({ count, map }) => {
153+
({ size, count, map }) => {
149154
for (let src in map) {
150155
let dest = map[src];
151156
if (this.conflictMap[dest]) {
@@ -178,7 +183,8 @@ class TemplatePassthroughManager {
178183
} else {
179184
if (count) {
180185
this.count += count;
181-
debug("Copied %o (%d files)", inputPath, count || 0);
186+
this.size += size;
187+
debug("Copied %o (%d files, %d size)", inputPath, count || 0, size || 0);
182188
} else {
183189
debug("Skipped copying %o (emulated passthrough copy)", inputPath);
184190
}
@@ -296,7 +302,7 @@ class TemplatePassthroughManager {
296302
map: aliases,
297303
});
298304

299-
debug(`TemplatePassthrough copy finished. Current count: ${this.count}`);
305+
debug(`TemplatePassthrough copy finished. Current count: ${this.count} (size: ${this.size})`);
300306
return results;
301307
});
302308
}

src/TemplateWriter.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import FileSystemSearch from "./FileSystemSearch.js";
1212
import ConsoleLogger from "./Util/ConsoleLogger.js";
1313

1414
const debug = debugUtil("Eleventy:TemplateWriter");
15-
const debugDev = debugUtil("Dev:Eleventy:TemplateWriter");
1615

1716
class TemplateWriterMissingConfigArgError extends EleventyBaseError {}
1817
class EleventyPassthroughCopyError extends EleventyBaseError {}
@@ -101,7 +100,6 @@ class TemplateWriter {
101100
this.writeCount = 0;
102101
this.renderCount = 0;
103102
this.skippedCount = 0;
104-
debugDev("Resetting counts to 0");
105103
}
106104

107105
set extensionMap(extensionMap) {
@@ -345,7 +343,6 @@ class TemplateWriter {
345343
await this._addToTemplateMap(paths, to);
346344
await this.templateMap.cache();
347345

348-
debugDev("TemplateMap cache complete.");
349346
return this.templateMap;
350347
}
351348

@@ -475,6 +472,10 @@ class TemplateWriter {
475472
return this.eleventyFiles.getPassthroughManager().getCopyCount();
476473
}
477474

475+
getCopySize() {
476+
return this.eleventyFiles.getPassthroughManager().getCopySize();
477+
}
478+
478479
getRenderCount() {
479480
return this.renderCount;
480481
}

src/Util/MemoizeFunction.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
export default function (callback) {
1+
export default function (callback, options = {}) {
2+
let { bench, name } = options;
23
let cache = new Map();
34

45
return (...args) => {
56
// Only supports single-arg functions for now.
67
if (args.filter(Boolean).length > 1) {
8+
bench?.get(`(count) ${name} Not valid for memoize`).incrementCount();
79
return callback(...args);
810
}
911

1012
let [cacheKey] = args;
1113

1214
if (!cache.has(cacheKey)) {
1315
cache.set(cacheKey, callback(...args));
16+
17+
bench?.get(`(count) ${name} memoize miss`).incrementCount();
18+
19+
return cache.get(cacheKey);
1420
}
1521

22+
bench?.get(`(count) ${name} memoize hit`).incrementCount();
23+
1624
return cache.get(cacheKey);
1725
};
1826
}

src/defaultConfig.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ export default function (config) {
6868
immediate: true,
6969
});
7070

71-
config.addFilter("slug", MemoizeUtil(slugFilter));
72-
config.addFilter("slugify", MemoizeUtil(slugifyFilter));
71+
let memoizeBench = config.benchmarkManager.get("Configuration");
72+
config.addFilter("slug", MemoizeUtil(slugFilter, { name: "slug", bench: memoizeBench }));
73+
config.addFilter("slugify", MemoizeUtil(slugifyFilter, { name: "slugify", bench: memoizeBench }));
7374

7475
// Deprecated, use HtmlBasePlugin instead.
7576
// Adds a pathPrefix manually to a URL string

0 commit comments

Comments
 (0)