Skip to content

Commit 712f96d

Browse files
perf: replace Map/Set with WeakMap/WeakSet (#8549)
1 parent 4162311 commit 712f96d

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

Diff for: packages/compiler-core/src/transform.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export interface TransformContext
117117
removeIdentifiers(exp: ExpressionNode | string): void
118118
hoist(exp: string | JSChildNode | ArrayExpression): SimpleExpressionNode
119119
cache<T extends JSChildNode>(exp: T, isVNode?: boolean): CacheExpression | T
120-
constantCache: Map<TemplateChildNode, ConstantTypes>
120+
constantCache: WeakMap<TemplateChildNode, ConstantTypes>
121121

122122
// 2.x Compat only
123123
filters?: Set<string>
@@ -181,7 +181,7 @@ export function createTransformContext(
181181
directives: new Set(),
182182
hoists: [],
183183
imports: [],
184-
constantCache: new Map(),
184+
constantCache: new WeakMap(),
185185
temps: 0,
186186
cached: 0,
187187
identifiers: Object.create(null),

Diff for: packages/runtime-core/src/apiCreateApp.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export function createAppAPI<HostElement>(
227227
})
228228
}
229229

230-
const installedPlugins = new Set()
230+
const installedPlugins = new WeakSet()
231231

232232
let isMounted = false
233233

Diff for: packages/runtime-core/src/compat/componentAsync.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ type LegacyAsyncComponent = (
1818
reject?: (reason?: any) => void
1919
) => LegacyAsyncReturnValue | undefined
2020

21-
const normalizedAsyncComponentMap = new Map<LegacyAsyncComponent, Component>()
21+
const normalizedAsyncComponentMap = new WeakMap<
22+
LegacyAsyncComponent,
23+
Component
24+
>()
2225

2326
export function convertLegacyAsyncComponent(comp: LegacyAsyncComponent) {
2427
if (normalizedAsyncComponentMap.has(comp)) {

Diff for: packages/runtime-core/src/compat/componentFunctional.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import { InternalSlots } from '../componentSlots'
88
import { getCompatListeners } from './instanceListeners'
99
import { compatH } from './renderFn'
1010

11-
const normalizedFunctionalComponentMap = new Map<
11+
const normalizedFunctionalComponentMap = new WeakMap<
1212
ComponentOptions,
1313
FunctionalComponent
1414
>()
15-
1615
export const legacySlotProxyHandlers: ProxyHandler<InternalSlots> = {
1716
get(target, key: string) {
1817
const slot = target[key]

0 commit comments

Comments
 (0)