When performance matters, structure code to avoid unnecessary work: (1) keep cheap fast-paths first for short-circuiting, (2) cache expensive global lookups (like config) instead of repeatedly calling them, (3) reuse costly parser/services/stateful objects, (4) lazy-load heavy dependencies only when required, and (5) remove redundant rendering/computation that increases output size.
Practical rules:
// Fast path: user/node override avoids config evaluation
const useHtmlLabels = node.useHtmlLabels || getEffectiveHtmlLabels(getConfig());
getConfig() once per function scope.
const config = getConfig();
const titleColor = config.themeVariables.titleColor;
if (needsMathML && hasKatex(text)) {
const katex = await import('katex');
// ...use katex
}
These changes reduce CPU time, allocations, and network/module load, improving both runtime responsiveness and load time.
Enter the URL of a public GitHub repository