Skip to content

Commit

Permalink
Merge pull request #867 from vaadin/optimize-increase-pool
Browse files Browse the repository at this point in the history
Minimize the amount of calls to _increasePool
  • Loading branch information
platosha committed Apr 28, 2017
2 parents f0fb451 + e4c677e commit a443b77
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
12 changes: 11 additions & 1 deletion iron-list-behavior.html
Expand Up @@ -432,7 +432,17 @@
Polymer.dom.addDebouncer(this.debounce('_debounceTemplate', this._increasePool.bind(this, this._itemsPerRow), 16));
} else {
// fill the rest of the pages
this._debounceTemplate(this._increasePool.bind(this, this._itemsPerRow));

// Count average item height
var itemHeight = this._physicalSize / this._physicalCount;
// Number of items in one page (to fill one viewport)
var itemsPerPage = this._viewportHeight / itemHeight;
// Amount of items needed in total
var totalNeededItems = this._maxPages * itemsPerPage;
// Estimated count of missing items
var missingItems = Math.ceil(totalNeededItems - this._physicalCount);

this._debounceTemplate(this._increasePool.bind(this, missingItems || 1));
}
this._lastPage = currentPage;
return true;
Expand Down
22 changes: 22 additions & 0 deletions test/physical-count.html
Expand Up @@ -86,6 +86,28 @@
scroller._update();
expect(scroller._increasePoolIfNeeded()).to.be.false;
});

it('should minimize increase pool iterations', function(done) {
var spy = sinon.spy(grid.$.scroller, '_increasePool');
grid.style.height = '1000px';

Polymer.RenderStatus.afterNextRender(grid, function() {
expect(spy.callCount).to.be.below(4);
done();
});
});

it('should minimize physical count', function(done) {
expect(grid.$.scroller._physicalCount).to.be.below(26);
grid.style.height = '1000px';

Polymer.RenderStatus.afterNextRender(grid, function() {
expect(grid.$.scroller._physicalCount).to.be.below(87);
done();
});
});


});
</script>

Expand Down

0 comments on commit a443b77

Please sign in to comment.