diff --git a/modules/benchmarks/src/change_detection/change_detection.e2e-spec.ts b/modules/benchmarks/src/change_detection/change_detection.e2e-spec.ts index bbbf8afed9..4872bfee53 100644 --- a/modules/benchmarks/src/change_detection/change_detection.e2e-spec.ts +++ b/modules/benchmarks/src/change_detection/change_detection.e2e-spec.ts @@ -19,11 +19,12 @@ describe('change detection benchmark', () => { ignoreBrowserSynchronization: true, params: [{name: 'viewCount', value: 1}], }); + await $('#destroyDom').click(); + expect(await $('#root').getText()).toEqual(''); + await $('#createDom').click(); expect($('#root').getText()).toContain('1'); await $('#detectChanges').click(); expect($('#root').getText()).toContain('2'); - await $('#detectChanges').click(); - expect($('#root').getText()).toContain('3'); await $('#destroyDom').click(); expect(await $('#root').getText()).toEqual(''); }); diff --git a/modules/benchmarks/src/change_detection/transplanted_views/BUILD.bazel b/modules/benchmarks/src/change_detection/transplanted_views/BUILD.bazel index 0ee15f5b96..2ddcf16392 100644 --- a/modules/benchmarks/src/change_detection/transplanted_views/BUILD.bazel +++ b/modules/benchmarks/src/change_detection/transplanted_views/BUILD.bazel @@ -1,29 +1,26 @@ -package(default_visibility = ["//visibility:public"]) - load("//tools:defaults.bzl", "ng_module", "ng_rollup_bundle", "ts_devserver") load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test") load("//modules/benchmarks:e2e_test.bzl", "e2e_test") +package(default_visibility = ["//modules/benchmarks:__subpackages__"]) + ng_module( name = "transplanted_views_lib", - srcs = [ - "index_aot.ts", - "transplanted_views.ts", - ], - tags = ["ivy-only"], + srcs = glob(["*.ts"]), + generate_ve_shims = True, + tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//modules/benchmarks/src/change_detection:util_lib", - "//packages:types", - "//packages/common", "//packages/core", + "//packages/platform-browser", + "//packages/platform-browser-dynamic", ], ) ng_rollup_bundle( name = "bundle", entry_point = ":index_aot.ts", - tags = ["ivy-only"], deps = [ ":transplanted_views_lib", "@npm//rxjs", @@ -31,25 +28,21 @@ ng_rollup_bundle( ) ts_devserver( - name = "devserver", + name = "prodserver", + bootstrap = ["//packages/zone.js/dist:zone.js"], port = 4200, static_files = ["index.html"], - tags = ["ivy-only"], - deps = [ - ":bundle.min_debug.js", - ], + deps = [":bundle.min_debug.es2015.js"], ) benchmark_test( name = "perf", - server = ":devserver", - tags = ["ivy-only"], + server = ":prodserver", deps = ["//modules/benchmarks/src/change_detection:perf_tests_lib"], ) e2e_test( name = "e2e", - server = ":devserver", - tags = ["ivy-only"], + server = ":prodserver", deps = ["//modules/benchmarks/src/change_detection:e2e_tests_lib"], ) diff --git a/modules/benchmarks/src/change_detection/transplanted_views/index.ts b/modules/benchmarks/src/change_detection/transplanted_views/index.ts new file mode 100644 index 0000000000..a2d3333ada --- /dev/null +++ b/modules/benchmarks/src/change_detection/transplanted_views/index.ts @@ -0,0 +1,16 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {enableProdMode} from '@angular/core'; +import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; + +import {init} from './init'; +import {TransplantedViewsModule} from './transplanted_views'; + +enableProdMode(); +platformBrowserDynamic().bootstrapModule(TransplantedViewsModule).then(init); diff --git a/modules/benchmarks/src/change_detection/transplanted_views/index_aot.ts b/modules/benchmarks/src/change_detection/transplanted_views/index_aot.ts index 60c4de5e7e..f59c382834 100644 --- a/modules/benchmarks/src/change_detection/transplanted_views/index_aot.ts +++ b/modules/benchmarks/src/change_detection/transplanted_views/index_aot.ts @@ -5,24 +5,12 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {ɵrenderComponent as renderComponent} from '@angular/core'; -import {bindAction, profile} from '../../util'; +import {enableProdMode} from '@angular/core'; +import {platformBrowser} from '@angular/platform-browser'; -import {DeclarationComponent, createDom, destroyDom, detectChanges} from './transplanted_views'; +import {init} from './init'; +import {TransplantedViewsModuleNgFactory} from './transplanted_views.ngfactory'; -function noop() {} - -export function main() { - let component: DeclarationComponent; - if (typeof window !== 'undefined') { - component = renderComponent(DeclarationComponent); - bindAction('#destroyDom', () => destroyDom(component)); - bindAction('#createDom', () => createDom(component)); - bindAction('#detectChanges', () => detectChanges(component)); - bindAction( - '#detectChangesProfile', profile(() => detectChanges(component), noop, 'detect_changes')); - } -} - -main(); +enableProdMode(); +platformBrowser().bootstrapModuleFactory(TransplantedViewsModuleNgFactory).then(init); diff --git a/modules/benchmarks/src/change_detection/transplanted_views/init.ts b/modules/benchmarks/src/change_detection/transplanted_views/init.ts new file mode 100644 index 0000000000..600d862438 --- /dev/null +++ b/modules/benchmarks/src/change_detection/transplanted_views/init.ts @@ -0,0 +1,41 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {ApplicationRef, NgModuleRef} from '@angular/core'; + +import {bindAction, profile} from '../../util'; +import {numViews} from '../util'; + +import {DeclarationComponent, TransplantedViewsModule} from './transplanted_views'; + +export function init(moduleRef: NgModuleRef) { + const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef); + const declaration: DeclarationComponent = appRef.components[0].instance; + + bindAction('#destroyDom', destroyDom); + bindAction('#createDom', createDom); + bindAction('#detectChanges', detectChanges); + bindAction('#detectChangesProfile', profile(detectChanges, noop, 'detectChanges')); + + // helpers + function destroyDom() { + declaration.viewCount = 0; + appRef.tick(); + declaration.templateRefreshCount = 0; + appRef.tick(); + } + + function createDom() { + declaration.viewCount = numViews; + appRef.tick(); + } + + function detectChanges() { appRef.tick(); } + + function noop() {} +} diff --git a/modules/benchmarks/src/change_detection/transplanted_views/transplanted_views.ts b/modules/benchmarks/src/change_detection/transplanted_views/transplanted_views.ts index c02809f4ee..b74e47b8c7 100644 --- a/modules/benchmarks/src/change_detection/transplanted_views/transplanted_views.ts +++ b/modules/benchmarks/src/change_detection/transplanted_views/transplanted_views.ts @@ -6,9 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {CommonModule} from '@angular/common'; -import {ChangeDetectionStrategy, Component, Input, NgModule, TemplateRef, ɵdetectChanges} from '@angular/core'; -import {newArray, numViews} from '../util'; +import {ChangeDetectionStrategy, Component, Input, NgModule, TemplateRef} from '@angular/core'; +import {BrowserModule} from '@angular/platform-browser'; + +import {newArray} from '../util'; @Component({ selector: 'declaration-component', @@ -45,21 +46,10 @@ export class InsertionComponent { trackByIndex(index: number, item: any) { return index; } } -@NgModule({declarations: [DeclarationComponent, InsertionComponent], imports: [CommonModule]}) -export class TransplantedViewModule { -} - -export function destroyDom(component: DeclarationComponent) { - component.templateRefreshCount = 0; - component.viewCount = 0; - ɵdetectChanges(component); -} - -export function createDom(component: DeclarationComponent) { - component.viewCount = numViews; - ɵdetectChanges(component); -} - -export function detectChanges(component: DeclarationComponent) { - ɵdetectChanges(component); +@NgModule({ + declarations: [DeclarationComponent, InsertionComponent], + bootstrap: [DeclarationComponent], + imports: [BrowserModule] +}) +export class TransplantedViewsModule { }