Skip to content

Commit 8c5ae51

Browse files
authored
perf(): improve runtime for native build (#1549)
1 parent 486b472 commit 8c5ae51

32 files changed

Lines changed: 235 additions & 188 deletions

src/client/client-host-ref.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,20 @@ export const registerInstance = (lazyInstance: any, hostRef: d.HostRef) =>
1111
hostRefs.set(hostRef.$lazyInstance$ = lazyInstance, hostRef);
1212

1313
export const registerHost = (elm: d.HostElement) => {
14-
// TODO: it's so ugly, but minifies really well
1514
if (BUILD.lazyLoad) {
16-
1715
const hostRef: d.HostRef = {
1816
$flags$: 0,
19-
$hostElement$: elm
17+
$hostElement$: elm,
18+
$instanceValues$: new Map()
2019
};
2120
hostRef.$onReadyPromise$ = new Promise(r => hostRef.$onReadyResolve$ = r);
22-
if (BUILD.prop || BUILD.state) {
23-
hostRef.$instanceValues$ = new Map();
24-
}
2521
return hostRefs.set(elm, hostRef);
26-
2722
} else {
28-
const hostRef: d.HostRef = {
23+
24+
return hostRefs.set(elm, {
2925
$flags$: 0,
30-
};
31-
if (BUILD.prop || BUILD.state) {
32-
hostRef.$instanceValues$ = new Map();
33-
}
34-
return hostRefs.set(elm, hostRef);
26+
$instanceValues$: new Map()
27+
});
3528
}
3629
};
3730

src/client/client-window.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export const win = window;
66

77
export const doc = document;
88

9+
export const H = HTMLElement;
10+
911
export const plt: d.PlatformRuntime = {
1012
$flags$: 0,
1113
$resourcesUrl$: '',
@@ -36,3 +38,5 @@ export const supportsConstructibleStylesheets = BUILD.constructableCSS ? /*@__PU
3638
} catch (e) {}
3739
return false;
3840
})() : false;
41+
42+
export {H as HTMLElement};

src/compiler/app-core/build-conditionals.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export function getBuildFeatures(cmps: d.ComponentCompilerMeta[]) {
3131
noVdomRender: cmps.every(c => !c.hasVdomRender),
3232
observeAttribute: cmps.some(c => c.hasAttribute),
3333
prop: cmps.some(c => c.hasProp),
34+
propBoolean: cmps.some(c => c.hasPropBoolean),
35+
propNumber: cmps.some(c => c.hasPropNumber),
36+
propString: cmps.some(c => c.hasPropString),
3437
propMutable: cmps.some(c => c.hasPropMutable),
3538
reflect: cmps.some(c => c.hasReflect),
3639
scoped: cmps.some(c => c.encapsulation === 'scoped'),

src/compiler/app-core/optimize-module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ export async function optimizeModule(config: d.Config, compilerCtx: d.CompilerCt
8383

8484
const results = await config.sys.minifyJs(input, opts);
8585
if (results != null && typeof results.output === 'string' && results.diagnostics.length === 0 && compilerCtx != null) {
86+
if (isCore) {
87+
results.output = results.output
88+
.replace(/disconnectedCallback\(\)\{\}/g, '');
89+
}
8690
await compilerCtx.cache.put(cacheKey, results.output);
8791
}
8892

src/compiler/output-targets/output-module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function getBuildConditionals(config: d.Config, cmps: d.ComponentCompilerMeta[])
7575
build.hydrateServerSide = false;
7676

7777
updateBuildConditionals(config, build);
78+
build.taskQueue = false;
7879

7980
return build;
8081
}

src/compiler/transformers/collections/parse-collection-deprecated.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ function parseComponentDeprecated(config: d.Config, compilerCtx: d.CompilerCtx,
7777
hasMode: false,
7878
hasAttribute: false,
7979
hasProp: false,
80+
hasPropNumber: false,
81+
hasPropBoolean: false,
82+
hasPropString: false,
8083
hasPropMutable: false,
8184
hasReflect: false,
8285
hasRenderFn: false,

src/compiler/transformers/component-build-conditionals.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export function setComponentBuildConditionals(cmpMeta: d.ComponentCompilerMeta)
88
cmpMeta.hasPropMutable = cmpMeta.properties.some(p => p.mutable);
99
cmpMeta.hasReflect = cmpMeta.properties.some(p => p.reflect);
1010
cmpMeta.hasAttribute = cmpMeta.properties.some(p => typeof p.attribute === 'string');
11+
cmpMeta.hasPropBoolean = cmpMeta.properties.some(p => p.type === 'boolean');
12+
cmpMeta.hasPropNumber = cmpMeta.properties.some(p => p.type === 'number');
13+
cmpMeta.hasPropString = cmpMeta.properties.some(p => p.type === 'string');
1114
}
1215

1316
if (cmpMeta.states.length > 0) {

src/compiler/transformers/component-native/native-imports.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export function addNativeImports(transformCtx: ts.TransformationContext, compile
99
...COMMON_IMPORTS,
1010
`attachShadow as ${ATTACH_SHADOW}`,
1111
`registerHost as ${REGISTER_HOST}`,
12+
`HTMLElement`
1213
];
1314
const moduleFile = getModuleFromSourceFile(compilerCtx, tsSourceFile);
1415
if (moduleFile && moduleFile.isLegacy) {

src/compiler/transformers/static-to-meta/component.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,23 @@ export function parseStaticComponentMeta(config: d.Config, compilerCtx: d.Compil
8080
hasMode: false,
8181
hasAttribute: false,
8282
hasProp: false,
83+
hasPropNumber: false,
84+
hasPropBoolean: false,
85+
hasPropString: false,
8386
hasPropMutable: false,
8487
hasReflect: false,
8588
hasRenderFn: false,
8689
hasState: false,
8790
hasStyle: false,
88-
hasVdomAttribute: true,
89-
hasVdomClass: true,
90-
hasVdomFunctional: true,
91-
hasVdomKey: true,
92-
hasVdomListener: true,
93-
hasVdomRef: true,
91+
hasVdomAttribute: false,
92+
hasVdomClass: false,
93+
hasVdomFunctional: false,
94+
hasVdomKey: false,
95+
hasVdomListener: false,
96+
hasVdomRef: false,
9497
hasVdomRender: false,
95-
hasVdomStyle: true,
96-
hasVdomText: true,
98+
hasVdomStyle: false,
99+
hasVdomText: false,
97100
hasWatchCallback: false,
98101
isPlain: false,
99102
htmlAttrNames: [],

src/declarations/build-conditionals.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export interface BuildFeatures {
5151
watchCallback: boolean;
5252
member: boolean;
5353
updatable: boolean;
54+
propBoolean: boolean;
55+
propNumber: boolean;
56+
propString: boolean;
5457

5558
// lifecycle events
5659
lifecycle: boolean;

0 commit comments

Comments
 (0)