Skip to content

Commit

Permalink
perf: replace Map/Set with WeakMap/WeakSet (#8549)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfred-Skyblue committed Oct 20, 2023
1 parent 4162311 commit 712f96d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
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

0 comments on commit 712f96d

Please sign in to comment.