From 764eb9c5c26eacc6792bdb1506e2279bd39db2f7 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 23 Jun 2025 08:27:50 -0300 Subject: html, upd8: nicer expose approaches for new optimizations --- src/html.js | 49 +++++++++++++++++++++-------------- src/upd8.js | 23 ++++++++++++++-- src/write/build-modes/static-build.js | 2 -- 3 files changed, 50 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/html.js b/src/html.js index 097ecfee..685b72ca 100644 --- a/src/html.js +++ b/src/html.js @@ -53,10 +53,16 @@ export const attributeSpec = { }, }; -// Validation keeps running even after we validate -// all of data, this let us turn it off and let build run free -let VALIDATION_DISABLED = false; -export function finishValidation() { VALIDATION_DISABLED = true; } +let disabledSlotValidation = false; +let disabledTagTracing = false; + +export function disableSlotValidation() { + disabledSlotValidation = true; +} + +export function disableTagTracing() { + disabledTagTracing = true; +} // Pass to tag() as an attributes key to make tag() return a 8lank tag if the // provided content is empty. Useful for when you'll only 8e showing an element @@ -357,12 +363,13 @@ export class Tag { #traceError = null; constructor(tagName, attributes, content) { - this.tagName = tagName; - this.attributes = attributes; - this.content = content; - if (process.env.DEBUG) { - this.#traceError = new Error(); - } + this.tagName = tagName; + this.attributes = attributes; + this.content = content; + + if (!disabledTagTracing) { + this.#traceError = new Error(); + } } clone() { @@ -716,17 +723,19 @@ export class Tag { `of ${inspect(this, {compact: true})}`, {cause: caughtError}); - error[Symbol.for(`hsmusic.aggregate.alwaysTrace`)] = true; - error[Symbol.for(`hsmusic.aggregate.traceFrom`)] = this.#traceError; + if (this.#traceError && !disabledTagTracing) { + error[Symbol.for(`hsmusic.aggregate.alwaysTrace`)] = true; + error[Symbol.for(`hsmusic.aggregate.traceFrom`)] = this.#traceError; - error[Symbol.for(`hsmusic.aggregate.unhelpfulTraceLines`)] = [ - /content-function\.js/, - /util\/html\.js/, - ]; + error[Symbol.for(`hsmusic.aggregate.unhelpfulTraceLines`)] = [ + /content-function\.js/, + /util\/html\.js/, + ]; - error[Symbol.for(`hsmusic.aggregate.helpfulTraceLines`)] = [ - /content\/dependencies\/(.*\.js:.*(?=\)))/, - ]; + error[Symbol.for(`hsmusic.aggregate.helpfulTraceLines`)] = [ + /content\/dependencies\/(.*\.js:.*(?=\)))/, + ]; + } throw error; } @@ -1778,7 +1787,7 @@ export class Template { } static validateSlotValueAgainstDescription(value, description) { - if (VALIDATION_DISABLED) { + if (disabledSlotValidation) { return true; } diff --git a/src/upd8.js b/src/upd8.js index 28c08238..ae072d5a 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -44,6 +44,7 @@ import {mapAggregate, openAggregate, showAggregate} from '#aggregate'; import CacheableObject from '#cacheable-object'; import {formatDuration, stringifyCache} from '#cli'; import {displayCompositeCacheAnalysis} from '#composite'; +import * as html from '#html'; import find, {bindFind, getAllFindSpecs} from '#find'; import {processLanguageFile, watchLanguageFile, internalDefaultStringsFile} from '#language'; @@ -518,6 +519,11 @@ async function main() { type: 'flag', }, + 'skip-self-diagnosis': { + help: `Disable some runtime validation for the wiki's own code, which speeds up long builds, but may allow unpredicted corner cases to fail strangely and silently`, + type: 'flag', + }, + 'queue-size': { help: `Process more or fewer disk files at once to optimize performance or avoid I/O errors, unlimited if set to 0 (between 500 and 700 is usually a safe range for building HSMusic on Windows machines)\nDefaults to ${defaultQueueSize}`, type: 'value', @@ -656,7 +662,8 @@ async function main() { const thumbsOnly = cliOptions['thumbs-only'] ?? false; const noInput = cliOptions['no-input'] ?? false; - const showAggregateTraces = cliOptions['show-traces'] ?? false; + const skipSelfDiagnosis = cliOptions['skip-self-diagnosis'] ?? false; + const showTraces = cliOptions['show-traces'] ?? false; const precacheMode = cliOptions['precache-mode'] ?? 'common'; @@ -1156,6 +1163,18 @@ async function main() { return false; } + if (skipSelfDiagnosis) { + logWarn`${'Skipping code self-diagnosis.'} (--skip-self-diagnosis provided)`; + logWarn`This build should run substantially faster, but corner cases`; + logWarn`not previously predicted may fail strangely and silently.`; + + html.disableSlotValidation(); + } + + if (!showTraces) { + html.disableTagTracing(); + } + Object.assign(stepStatusSummary.determineMediaCachePath, { status: STATUS_STARTED_NOT_DONE, timeStart: Date.now(), @@ -1334,7 +1353,7 @@ async function main() { const niceShowAggregate = (error, ...opts) => { showAggregate(error, { - showTraces: showAggregateTraces, + showTraces, pathToFileURL: (f) => path.relative(__dirname, fileURLToPath(f)), ...opts, }); diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js index 1683c729..b5ded04c 100644 --- a/src/write/build-modes/static-build.js +++ b/src/write/build-modes/static-build.js @@ -233,8 +233,6 @@ export async function go({ return false; } - html.finishValidation(); - /* await progressPromiseAll(`Writing data files shared across languages.`, queue( dataWrites.map(({path, data}) => () => { -- cgit 1.3.0-6-gf8a5