From bcf97080272263019696296527cd8852d8d9f0ac Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 12 Apr 2024 12:12:58 -0300 Subject: infra: experimental HSMUSIC_DEBUG_CONTENT_PERF mode --- src/content-function.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/content-function.js b/src/content-function.js index 16b1864..44f8b84 100644 --- a/src/content-function.js +++ b/src/content-function.js @@ -1,7 +1,7 @@ import {inspect as nodeInspect} from 'node:util'; import {decorateError} from '#aggregate'; -import {colors, ENABLE_COLOR} from '#cli'; +import {colors, decorateTime, ENABLE_COLOR} from '#cli'; import {Template} from '#html'; import {annotateFunction, empty, setIntersection} from '#sugar'; @@ -9,6 +9,8 @@ function inspect(value, opts = {}) { return nodeInspect(value, {colors: ENABLE_COLOR, ...opts}); } +const DECORATE_TIME = process.env.HSMUSIC_DEBUG_CONTENT_PERF === '1'; + export class ContentFunctionSpecError extends Error {} export default function contentFunction({ @@ -104,6 +106,11 @@ export function expectDependencies({ let wrappedGenerate; + const optionalDecorateTime = (prefix, fn) => + (DECORATE_TIME + ? decorateTime(`${prefix}/${generate.name}`, fn) + : fn); + if (isInvalidated) { wrappedGenerate = function() { throw new Error(`Generate invalidated because unfulfilled dependencies provided: ${[...invalidatingDependencyKeys].join(', ')}`); @@ -119,7 +126,7 @@ export function expectDependencies({ annotateFunction(wrappedGenerate, {name: generate, trait: 'unfulfilled'}); wrappedGenerate.fulfilled = false; } else { - const callUnderlyingGenerate = ([arg1, arg2], ...extraArgs) => { + let callUnderlyingGenerate = ([arg1, arg2], ...extraArgs) => { if (hasDataFunction && !arg1) { throw new Error(`Expected data`); } @@ -161,6 +168,9 @@ export function expectDependencies({ } }; + callUnderlyingGenerate = + optionalDecorateTime(`generate`, callUnderlyingGenerate); + if (hasSlotsDescription) { const stationery = fulfilledDependencies.html.stationery({ annotation: generate.name, @@ -204,19 +214,19 @@ export function expectDependencies({ wrappedGenerate[contentFunction.identifyingSymbol] = true; if (hasSprawlFunction) { - wrappedGenerate.sprawl = sprawl; + wrappedGenerate.sprawl = optionalDecorateTime(`sprawl`, sprawl); } if (hasQueryFunction) { - wrappedGenerate.query = query; + wrappedGenerate.query = optionalDecorateTime(`query`, query); } if (hasRelationsFunction) { - wrappedGenerate.relations = relations; + wrappedGenerate.relations = optionalDecorateTime(`relations`, relations); } if (hasDataFunction) { - wrappedGenerate.data = data; + wrappedGenerate.data = optionalDecorateTime(`data`, data); } wrappedGenerate.fulfill ??= function fulfill(dependencies) { -- cgit 1.3.0-6-gf8a5