Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: replace Map/Set with WeakMap/WeakSet #8549

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/compiler-core/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export interface TransformContext
removeIdentifiers(exp: ExpressionNode | string): void
hoist(exp: string | JSChildNode | ArrayExpression): SimpleExpressionNode
cache<T extends JSChildNode>(exp: T, isVNode?: boolean): CacheExpression | T
constantCache: Map<TemplateChildNode, ConstantTypes>
constantCache: WeakMap<TemplateChildNode, ConstantTypes>

// 2.x Compat only
filters?: Set<string>
Expand Down Expand Up @@ -181,7 +181,7 @@ export function createTransformContext(
directives: new Set(),
hoists: [],
imports: [],
constantCache: new Map(),
constantCache: new WeakMap(),
temps: 0,
cached: 0,
identifiers: Object.create(null),
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/apiCreateApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export function createAppAPI<HostElement>(
})
}

const installedPlugins = new Set()
const installedPlugins = new WeakSet()

let isMounted = false

Expand Down
5 changes: 4 additions & 1 deletion packages/runtime-core/src/compat/componentAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ type LegacyAsyncComponent = (
reject?: (reason?: any) => void
) => LegacyAsyncReturnValue | undefined

const normalizedAsyncComponentMap = new Map<LegacyAsyncComponent, Component>()
const normalizedAsyncComponentMap = new WeakMap<
LegacyAsyncComponent,
Component
>()

export function convertLegacyAsyncComponent(comp: LegacyAsyncComponent) {
if (normalizedAsyncComponentMap.has(comp)) {
Expand Down
3 changes: 1 addition & 2 deletions packages/runtime-core/src/compat/componentFunctional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import { InternalSlots } from '../componentSlots'
import { getCompatListeners } from './instanceListeners'
import { compatH } from './renderFn'

const normalizedFunctionalComponentMap = new Map<
const normalizedFunctionalComponentMap = new WeakMap<
ComponentOptions,
FunctionalComponent
>()

export const legacySlotProxyHandlers: ProxyHandler<InternalSlots> = {
get(target, key: string) {
const slot = target[key]
Expand Down
Loading