Skip to content

Commit 88e5642

Browse files
committed
perf(virtual-list): relaxed restrictions for fast path
1 parent 325cc5e commit 88e5642

File tree

3 files changed

+65
-27
lines changed

3 files changed

+65
-27
lines changed

src/components/virtual-scroll/test/basic/app.module.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,7 @@ export class E2EPage {
1111
webview: string = '';
1212
counter: number = 0;
1313

14-
constructor(plt: Platform, public navCtrl: NavController) {
15-
if (plt.is('ios')) {
16-
if (plt.testUserAgent('Safari')) {
17-
this.webview = ': iOS Safari';
18-
19-
} else if (!!(window as any)['webkit']) {
20-
this.webview = ': iOS WKWebView';
21-
22-
} else {
23-
this.webview = ': iOS UIWebView';
24-
}
25-
}
26-
}
14+
constructor(plt: Platform, public navCtrl: NavController) {}
2715

2816
addItems() {
2917
if (this.items.length === 0) {
@@ -54,8 +42,20 @@ export class E2EPage {
5442
this.counter++;
5543
}
5644

57-
reload() {
58-
window.location.reload(true);
45+
addRandomItem() {
46+
const index = Math.floor(Math.random() * this.items.length);
47+
this.items.splice( index, 0, {
48+
value: Math.floor(Math.random() * 10000),
49+
someMethod: function() {
50+
return '!!';
51+
}
52+
}
53+
);
54+
}
55+
56+
changeItem() {
57+
const index = Math.floor(Math.random() * this.items.length);
58+
this.items[index].value = Math.floor(Math.random() * 10000);
5959
}
6060

6161
trackByFn(index: number, item: any) {

src/components/virtual-scroll/test/basic/main.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<ion-header>
22
<ion-navbar>
3-
<ion-title>Virtual Scroll{{webview}}</ion-title>
43
<ion-buttons end>
5-
<button ion-button (click)="reload()">
6-
Reload
4+
<button ion-button icon-only (click)="changeItem()">
5+
Change random
6+
</button>
7+
<button ion-button icon-only (click)="addRandomItem()">
8+
Add random
79
</button>
810
<button ion-button icon-only (click)="addItem()">
9-
<ion-icon name="add"></ion-icon>
11+
Append
1012
</button>
1113
</ion-buttons>
1214
</ion-navbar>

src/components/virtual-scroll/virtual-scroll.ts

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
379379
return this._virtualTrackBy;
380380
}
381381

382-
383382
constructor(
384383
private _iterableDiffers: IterableDiffers,
385384
private _elementRef: ElementRef,
@@ -412,6 +411,28 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
412411
});
413412
}
414413

414+
/**
415+
* @hidden
416+
*/
417+
firstRecord(): number {
418+
const cells = this._cells;
419+
if (cells.length > 0) {
420+
return cells[0].record;
421+
}
422+
return 0;
423+
}
424+
425+
/**
426+
* @hidden
427+
*/
428+
lastRecord(): number {
429+
const cells = this._cells;
430+
if (cells.length > 0) {
431+
return cells[cells.length - 1].record;
432+
}
433+
return 0;
434+
}
435+
415436
/**
416437
* @hidden
417438
*/
@@ -429,8 +450,9 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
429450

430451
let needClean = false;
431452
if (changes) {
453+
var lastRecord = this.lastRecord() + 1;
432454
changes.forEachOperation((item, _, cindex) => {
433-
if (item.previousIndex != null || (cindex < this._recordSize)) {
455+
if (item.previousIndex != null || (cindex < lastRecord)) {
434456
needClean = true;
435457
}
436458
});
@@ -443,10 +465,13 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
443465
this.writeUpdate(needClean);
444466
}
445467

468+
/**
469+
* @hidden
470+
*/
446471
readUpdate(needClean: boolean) {
447472
if (needClean) {
448473
// reset everything
449-
console.debug(`virtual-scroll, readUpdate: slow path`);
474+
console.debug('virtual-scroll, readUpdate: slow path');
450475
this._cells.length = 0;
451476
this._nodes.length = 0;
452477
this._itmTmp.viewContainer.clear();
@@ -458,8 +483,11 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
458483
}
459484
}
460485

486+
/**
487+
* @hidden
488+
*/
461489
writeUpdate(needClean: boolean) {
462-
console.debug(`virtual-scroll, writeUpdate`);
490+
console.debug('virtual-scroll, writeUpdate need clean:', needClean);
463491
const data = this._data;
464492
const stopAtHeight = (data.scrollTop + data.renderHeight);
465493
data.scrollDiff = SCROLL_DIFFERENCE_MINIMUM + 1;
@@ -475,6 +503,9 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
475503
this.renderVirtual(needClean);
476504
}
477505

506+
/**
507+
* @hidden
508+
*/
478509
private calcDimensions() {
479510
calcDimensions(this._data, this._elementRef.nativeElement,
480511
this.approxItemWidth, this.approxItemHeight,
@@ -571,7 +602,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
571602
}
572603

573604
/**
574-
* @private
605+
* @hidden
575606
*/
576607
resize() {
577608
// only continue if we've already initialized
@@ -605,7 +636,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
605636
}
606637

607638
/**
608-
* @private
639+
* @hidden
609640
*/
610641
private _stepChangeDetection() {
611642
// we need to do some change detection in this frame
@@ -624,7 +655,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
624655
}
625656

626657
/**
627-
* @private
658+
* @hidden
628659
*/
629660
private _stepNoChanges() {
630661
const data = this._data;
@@ -675,7 +706,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
675706
}
676707

677708
/**
678-
* @private
709+
* @hidden
679710
*/
680711
scrollUpdate(ev: ScrollEvent) {
681712
// set the scroll top from the scroll event
@@ -718,6 +749,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
718749
}
719750

720751
/**
752+
* @hidden
721753
* NO DOM
722754
*/
723755
private _listeners() {
@@ -738,6 +770,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
738770
}
739771

740772
/**
773+
* @hidden
741774
* DOM WRITE
742775
*/
743776
private _setHeight(newVirtualHeight: number) {
@@ -762,6 +795,9 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
762795
}
763796
}
764797

798+
/**
799+
* @hidden
800+
*/
765801
setElementClass(className: string, add: boolean) {
766802
this._renderer.setElementClass(this._elementRef.nativeElement, className, add);
767803
}

0 commit comments

Comments
 (0)