Skip to content

perf: optimize framework and router#251

Merged
mohamedmansour merged 4 commits intomainfrom
mmansour/optimize-framework-router-bundle
Apr 17, 2026
Merged

perf: optimize framework and router#251
mohamedmansour merged 4 commits intomainfrom
mmansour/optimize-framework-router-bundle

Conversation

@mohamedmansour
Copy link
Copy Markdown
Contributor

  • 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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-flight ensureLoaded() promises.
  • Framework: micro-optimize resolveRepeatValue, switch SSR template DOM cache to a WeakMap, and generate ARIA attribute names algorithmically in toKebabCase.
  • 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.

Comment thread packages/webui-router/src/router.ts
Comment thread packages/webui-router/src/router.ts
Comment thread packages/webui-framework/src/decorators.ts Outdated
mohamedmansour and others added 3 commits April 17, 2026 07:57
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>
@mohamedmansour mohamedmansour force-pushed the mmansour/optimize-framework-router-bundle branch from 0a713ed to 68f724e Compare April 17, 2026 15:04
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>
@mohamedmansour mohamedmansour merged commit 944fd29 into main Apr 17, 2026
21 checks passed
@mohamedmansour mohamedmansour deleted the mmansour/optimize-framework-router-bundle branch April 17, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants