From 359aeeec88a41aa3a50db4704e89b5bd2b9e3492 Mon Sep 17 00:00:00 2001 From: tbitw2549 Date: Thu, 24 Oct 2024 20:45:57 +0300 Subject: [PATCH] perf: more regex (and related areas) deallocation This applies the commit without the playground changes (oops!) --- packages/nuxt/src/components/module.ts | 5 +- .../components/plugins/islands-transform.ts | 24 +- .../nuxt/src/components/plugins/tree-shake.ts | 370 +++++++++--------- packages/nuxt/src/components/scan.ts | 9 +- packages/nuxt/src/components/templates.ts | 2 +- packages/nuxt/src/core/builder.ts | 2 +- packages/nuxt/src/core/nitro.ts | 4 +- packages/nuxt/src/core/nuxt.ts | 5 +- packages/nuxt/src/core/plugins/dev-only.ts | 5 +- .../nuxt/src/core/plugins/layer-aliasing.ts | 5 +- packages/nuxt/src/core/templates.ts | 19 +- packages/nuxt/src/imports/transform.ts | 5 +- packages/nuxt/src/pages/module.ts | 3 +- packages/nuxt/src/pages/plugins/page-meta.ts | 51 ++- .../nuxt/src/pages/plugins/route-injection.ts | 9 +- packages/vite/src/plugins/composable-keys.ts | 9 +- packages/vite/src/plugins/public-dirs.ts | 10 +- 17 files changed, 263 insertions(+), 274 deletions(-) diff --git a/packages/nuxt/src/components/module.ts b/packages/nuxt/src/components/module.ts index a2a1d8ca7d..4c5dc50c77 100644 --- a/packages/nuxt/src/components/module.ts +++ b/packages/nuxt/src/components/module.ts @@ -21,9 +21,6 @@ function compareDirByPathLength ({ path: pathA }: { path: string }, { path: path return pathB.split(SLASH_SEPARATOR_RE).filter(Boolean).length - pathA.split(SLASH_SEPARATOR_RE).filter(Boolean).length } -const DEFAULT_COMPONENTS_DIRS_RE = /\/components(?:\/(?:global|islands))?$/ -const STARTER_DOT_RE = /^\./g - export type getComponentsT = (mode?: 'client' | 'server' | 'all') => Component[] export default defineNuxtModule({ @@ -78,6 +75,8 @@ export default defineNuxtModule({ })) } + const DEFAULT_COMPONENTS_DIRS_RE = /\/components(?:\/(?:global|islands))?$/ + const STARTER_DOT_RE = /^\./g // Resolve dirs nuxt.hook('app:resolve', async () => { // components/ dirs from all layers diff --git a/packages/nuxt/src/components/plugins/islands-transform.ts b/packages/nuxt/src/components/plugins/islands-transform.ts index a3e2aba41a..2b854b9bbc 100644 --- a/packages/nuxt/src/components/plugins/islands-transform.ts +++ b/packages/nuxt/src/components/plugins/islands-transform.ts @@ -24,20 +24,20 @@ interface ComponentChunkOptions { buildDir: string } -const SCRIPT_RE = /]*>/gi -const HAS_SLOT_OR_CLIENT_RE = /]*>|nuxt-client/ -const TEMPLATE_RE = /