refactor(compiler): generate less code for bindings to DOM elements
Detailed changes: - remove `UNINITIALIZED`, initialize change detection fields with `undefined`. * we use `view.numberOfChecks === 0` now everywhere as indicator whether we are in the first change detection cycle (previously we used this only in a couple of places). * we keep the initialization itself as change detection get slower without it. - remove passing around `throwOnChange` in various generated calls, and store it on the view as property instead. - change generated code for bindings to DOM elements as follows: Before: ``` var currVal_10 = self.context.bgColor; if (jit_checkBinding15(self.throwOnChange,self._expr_10,currVal_10)) { self.renderer.setElementStyle(self._el_0,'backgroundColor',((self.viewUtils.sanitizer.sanitize(jit_21,currVal_10) == null)? null: self.viewUtils.sanitizer.sanitize(jit_21,currVal_10).toString())); self._expr_10 = currVal_10; } var currVal_11 = jit_inlineInterpolate16(1,' ',self.context.data.value,' '); if (jit_checkBinding15(self.throwOnChange,self._expr_11,currVal_11)) { self.renderer.setText(self._text_1,currVal_11); self._expr_11 = currVal_11; } ```, After: ``` var currVal_10 = self.context.bgColor; jit_checkRenderStyle14(self,self._el_0,'backgroundColor',null,self._expr_10,self._expr_10=currVal_10,false,jit_21); var currVal_11 = jit_inlineInterpolate15(1,' ',self.context.data.value,' '); jit_checkRenderText16(self,self._text_1,self._expr_11,self._expr_11=currVal_11,false); ``` Performance impact: - None seen (checked against internal latency lab) Part of #13651
This commit is contained in:
@ -29,7 +29,7 @@ export function init(moduleRef: NgModuleRef<AppModule>) {
|
||||
}
|
||||
|
||||
function detectChanges() {
|
||||
for (var i = 0; i < 10; i++) {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
appRef.tick();
|
||||
}
|
||||
detectChangesRuns += 10;
|
||||
|
@ -41,8 +41,8 @@ class _View_TreeComponent_Host0 extends import1.AppView<any> {
|
||||
this.init([].concat([this._el_0]), [this._el_0], []);
|
||||
return new import9.ComponentRef_(0, this, this._el_0, this._TreeComponent_0_4.context);
|
||||
}
|
||||
detectChangesInternal(throwOnChange: boolean): void {
|
||||
this._TreeComponent_0_4.detectChangesInternal(throwOnChange);
|
||||
detectChangesInternal(): void {
|
||||
this._TreeComponent_0_4.detectChangesInternal(this.throwOnChange);
|
||||
}
|
||||
destroyInternal(): void { this._TreeComponent_0_4.destroyInternal(); }
|
||||
injectorGetInternal(token: any, requestNodeIndex: number, notFoundResult: any): any {
|
||||
|
@ -49,8 +49,8 @@ class _View_TreeRootComponent_Host0 extends import1.AppView<any> {
|
||||
this.init([].concat([this._el_0]), [this._el_0], []);
|
||||
return new import9.ComponentRef_(0, this, this._el_0, this._TreeRootComponent_0_4);
|
||||
}
|
||||
detectChangesInternal(throwOnChange: boolean): void {
|
||||
this._TreeRootComponent_0_4_View.detectChangesInternal(throwOnChange);
|
||||
detectChangesInternal(): void {
|
||||
this._TreeRootComponent_0_4_View.detectChangesInternal(this.throwOnChange);
|
||||
}
|
||||
destroyInternal(): void { this._TreeRootComponent_0_4_View.destroyInternal(); }
|
||||
injectorGetInternal(token: any, requestNodeIndex: number, notFoundResult: any): any {
|
||||
@ -106,13 +106,13 @@ class _View_TreeRootComponent0 extends import1.AppView<import3.TreeRootComponent
|
||||
}
|
||||
return notFoundResult;
|
||||
}
|
||||
detectChangesInternal(throwOnChange: boolean): void {
|
||||
detectChangesInternal(): void {
|
||||
const currVal_0: any = (this.context.data.left != (null as any));
|
||||
if (checkBinding(throwOnChange, this._expr_0, currVal_0)) {
|
||||
if (checkBinding(this.throwOnChange, this._expr_0, currVal_0)) {
|
||||
this._NgIf_0_6.ngIf = currVal_0;
|
||||
this._expr_0 = currVal_0;
|
||||
}
|
||||
this._appEl_0.detectChangesInNestedViews(throwOnChange);
|
||||
this._appEl_0.detectChangesInNestedViews(this.throwOnChange);
|
||||
}
|
||||
}
|
||||
class _View_TreeRootComponent1 extends import1.AppView<any> {
|
||||
@ -133,9 +133,9 @@ class _View_TreeRootComponent1 extends import1.AppView<any> {
|
||||
return (null as any);
|
||||
}
|
||||
destroyInternal() { this._TreeComponent0_0_4View.destroyInternal(); }
|
||||
detectChangesInternal(throwOnChange: boolean): void {
|
||||
detectChangesInternal(): void {
|
||||
this._TreeComponent0_0_4View.updateData(this.parentView.context.data);
|
||||
this._TreeComponent0_0_4View.detectChangesInternal(throwOnChange);
|
||||
this._TreeComponent0_0_4View.detectChangesInternal(this.throwOnChange);
|
||||
}
|
||||
visitRootNodesInternal(cb: any, context: any) { cb(this._el_0, context); }
|
||||
}
|
||||
|
Reference in New Issue
Block a user