perf: optimize framework and router#251
Merged
mohamedmansour merged 4 commits intomainfrom Apr 17, 2026
Merged
Conversation
Contributor
mohamedmansour
commented
Apr 17, 2026
- Replace 28-entry ARIA lookup table with algorithmic generation, no more regex. (-1KB)
- Extract shared applyParamsQueryState helper eliminating router code duplication
- Parallelize component loading with Promise.all and per-item abort guards
- Replace DOM querySelector dedup with in-memory Set for CSS/style injection
- Convert templateDOMCache to WeakMap for GC-friendly caching
- Apply charCodeAt guard to resolveRepeatValue hot path
- Remove dead waitForRenderReady method
- Add ssrPreloadsCleared flag to skip redundant DOM queries
- Fix loadPromises memory leak in destroy()
- Cache basePath field to avoid repeated nullish coalescing
There was a problem hiding this comment.
Pull request overview
Performance-focused updates across the WebUI router and framework runtime to reduce DOM queries, cut duplication, and tighten hot-path checks while keeping existing behavior.
Changes:
- Router: extract shared param/query/state application, cache basePath, add in-memory CSS/style dedup sets, parallelize component preloading, and fix
destroy()retaining in-flightensureLoaded()promises. - Framework: micro-optimize
resolveRepeatValue, switch SSR template DOM cache to aWeakMap, and generate ARIA attribute names algorithmically intoKebabCase. - Cleanup: remove unused router helper (
waitForRenderReady) and add an SSR-preload clearing guard.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/webui-router/src/router.ts | Refactors route state application, reduces DOM query overhead via Sets, parallelizes preload, and improves teardown by clearing more caches. |
| packages/webui-framework/src/element/diff.ts | Hot-path optimization for repeat-scope dotted path resolution. |
| packages/webui-framework/src/element.ts | Makes SSR template DOM cache GC-friendly via WeakMap; clarifies disconnect behavior. |
| packages/webui-framework/src/decorators.ts | Shrinks ARIA reflection mapping by generating aria-* names algorithmically. |
Framework (packages/webui-framework): - decorators.ts: algorithmic ARIA attribute generation (removes 28 entries from lookup table) - element.ts: convert templateDOMCache to WeakMap for GC of unused template DOMs - element/diff.ts: apply charCodeAt guard to resolveRepeatValue hot path Router (packages/webui-router): - Remove dead waitForRenderReady method - Add ssrPreloadsCleared flag to short-circuit DOM query after first navigation - Clear loadPromises in destroy() to fix memory leak - Extract applyParamsQueryState helper (dedup mountComponent/applyState) - Cache basePath in start() instead of repeated config lookups - Parallelize component loading with Promise.all + abort guards - Use in-memory Set for CSS/style dedup (eliminates O(n) DOM scans per navigation) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Asserts that calling destroy() clears the in-flight loadPromises cache so in-flight ensureLoaded() requests do not retain the router, enabling GC and clean restart. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0a713ed to
68f724e
Compare
Promise.all awaited all in-flight imports even after the signal was aborted, delaying superseding navigations. The inner abort check in the .map() callback was dead code since .map() runs synchronously before any await. Race the preload against an abort promise so aborted navigations return immediately. Module imports themselves are not cancellable, but their promises remain cached via ensureComponentLoaded, so the winning navigation reuses any completed work. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
janechu
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.