Description
CallHook calls Eval("__hooks[__callHookName](__callInput)") per page per hook — parsing and compiling the same JS expression 820+ times per hook invocation. setPayloadFrontMatter and setPayloadTOC each call Eval("Object.defineProperty(...)") per page for the lazy getter setup.
Eval lexes, parses, and compiles the source string on every call. For a static expression called 820 times, that's 819 redundant compilations.
Fix
Pre-compile static expressions as named functions during Init():
function __callHookByName(name, input) {
return __hooks[name](input);
}
function __installLazyFM(target, jsonStr) {
Object.defineProperty(target, 'frontMatter', { get: ..., set: ..., configurable: true });
}
function __installLazyTOC(target, jsonStr) {
Object.defineProperty(target, 'toc', { get: ..., set: ..., configurable: true });
}
Call via InvokeJS("__callHookByName", nameVal, input) instead of Eval(...). InvokeJS calls the pre-compiled function directly — no parse, no compile.
Measured impact
820-page RHDS benchmark: ~200ms reduction in post-render hooks. Small individually, but it compounds with the other fast-path optimizations.
Scope
Refs #1185, #1180
Description
CallHookcallsEval("__hooks[__callHookName](__callInput)")per page per hook — parsing and compiling the same JS expression 820+ times per hook invocation.setPayloadFrontMatterandsetPayloadTOCeach callEval("Object.defineProperty(...)")per page for the lazy getter setup.Evallexes, parses, and compiles the source string on every call. For a static expression called 820 times, that's 819 redundant compilations.Fix
Pre-compile static expressions as named functions during
Init():Call via
InvokeJS("__callHookByName", nameVal, input)instead ofEval(...).InvokeJScalls the pre-compiled function directly — no parse, no compile.Measured impact
820-page RHDS benchmark: ~200ms reduction in post-render hooks. Small individually, but it compounds with the other fast-path optimizations.
Scope
alloy-setup.jseval block inInit()Evalcalls ininvokeHookFastPath,setPayloadFrontMatter,setPayloadTOCwithInvokeJSEvala static expression inside a loopRefs #1185, #1180