perf: optimize hot paths — morph, dmEx, dmIt, dmAct#132
Conversation
… when attrs match, simplify noMorph Agent-Logs-Url: https://github.com/dadhi/dmax/sessions/90d6b16d-998a-4c9f-a856-a241dade6193 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dadhi/dmax/sessions/90d6b16d-998a-4c9f-a856-a241dade6193 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
|
@copilot let upload the optimization pass for other areas as well using the same principles, dmAct, dmIt and for dmEx |
…mpty loops, single-item fast path Agent-Logs-Url: https://github.com/dadhi/dmax/sessions/7dd03f41-caf2-4108-bbe7-6c17dbdbc944 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Done in 37d4609. Applied the same principles to dmEx, dmIt, and dmAct: dmEx — precompute per-target dmIt — single-item fast path in dmAct — precompute Net: −37 lines, −77 bytes. All 770+ tests pass. |
|
@copilot I wonder about cases we are missing in tests. Let review the fuzz and asserts snd cover the missing combinations. Also we need to ensure that examples are working well. |
…ow targets, dmIt single/multi growth Agent-Logs-Url: https://github.com/dadhi/dmax/sessions/2ed391cb-0117-478d-9c1e-ad79385bc2b0 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dadhi/dmax/sessions/2ed391cb-0117-478d-9c1e-ad79385bc2b0 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Reviewed the fuzz and asserts coverage against the new optimization paths and added missing tests in 0509612: morph — 3 new asserts: text-only fast path (attrs match, unfocused), text-only with focused element (must go normal path), text-only with attrs mismatch (both attrs and text updated). dmEx — 2 new asserts: target dmIt — 2 new asserts: single-item growth from 2→3 (exercises fuzz — 2 new cases: Total: 352 fuzz + 92 headless + 335 notebook (up from 328) + actions + naming + size — all green. |
|
@copilot lasr thing - any idras for code reorg/compression without changing names or whitespacing? ideally we need to be under 14kb minified+br |
Agent-Logs-Url: https://github.com/dadhi/dmax/sessions/fc97f7b9-e1a3-488a-9ac2-ba0863f63f0a Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
|
@copilot Resume but ensure that code compaction does not affect perf. Perf is first priority then code organization. No functionality shoud be dropped, add tests if needed to cover for new code / drop no lpnger needed tests if any. |
|
@copilot Resume |
Agent-Logs-Url: https://github.com/dadhi/dmax/sessions/b1b54223-0210-4c22-abfd-2ae513f0c63b Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
|
l |
|
@copilot please proceed |
Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
All optimizations are in place and tests pass (352 fuzz, 92 headless, naming, size). The minified+brotli size is 13,789 bytes — under the 14kb target. Size limits tightened to 1665 lines / 88035 bytes. |
Targeting the dmax vs datastar vs fixi benchmark's dominant workload, applying the same optimization principles across morph, dmEx, dmIt, and dmAct hot paths.
Changes
morph()
nodeValueand return. Skips focus/scroll preservation,updateAttrs, andmorphChildrenfor ~1024 cells per morph cycle.updateAttrswhen attrs already match — reuse theattrsMatchflag from thesameAttrs()check that already runs for the early-exit test.noMorph()— removeel && el.hasAttribute &&guards; call site guarantees both args are ELEMENT_NODE.!fl && !tlguard inupdateAttrs()— unreachable now that morph gates the call behind!attrsMatch.from.tagNameaccess — only read when element is actually the focused element.dmEx (per-trigger-fire optimization)
_m) — eliminatesgetWriteMode()loop iteration on every trigger fire._j) — eliminates.some()callback scan on every fire._el) — eliminatesgetElById()DOM lookup and isSp ternary chain on every fire.dmIt (single-item fast path)
createDocumentFragment()for single item — when only 1 item is added (common incremental push case), append the node directly without fragment allocation.dmAct (per-request optimization)
hasAdds/hasRouteModsflags — skip for-loops overaddsandactRouteModswhen they're empty (avoids JIT overhead for zero-iteration for-of).Test coverage for optimization paths
Added targeted tests to cover the new fast paths and precomputed values:
^jsosprecomputed flag verifies JSON.stringify applied to output; target writing to_window.document.titleverifies precomputed_elfor window targetscount === 1fast path), multi-item growth from 1→4 (exercises fragment path with correct$ixrewriting)^jsostarget modifier exercise test, single-item-growth dmIt patternNet: −37 lines, −77 bytes (1705 lines / 89850 bytes). All tests pass (352 fuzz, 92 headless, actions, notebook 335, naming, size).