Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: chrome/browser/resources/md_history/app.crisper.js

Issue 2324293002: Roll performance-oriented iron-list changes (Closed)
Patch Set: test fix courtesy of michaelpg@ Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 function PromiseResolver() { 4 function PromiseResolver() {
5 this.resolve_; 5 this.resolve_;
6 this.reject_; 6 this.reject_;
7 this.promise_ = new Promise(function(resolve, reject) { 7 this.promise_ = new Promise(function(resolve, reject) {
8 this.resolve_ = resolve; 8 this.resolve_ = resolve;
9 this.reject_ = reject; 9 this.reject_ = reject;
10 }.bind(this)); 10 }.bind(this));
(...skipping 7183 matching lines...) Expand 10 before | Expand all | Expand 10 after
7194 _physicalIndexForKey: null, 7194 _physicalIndexForKey: null,
7195 _estScrollHeight: 0, 7195 _estScrollHeight: 0,
7196 _scrollHeight: 0, 7196 _scrollHeight: 0,
7197 _viewportHeight: 0, 7197 _viewportHeight: 0,
7198 _viewportWidth: 0, 7198 _viewportWidth: 0,
7199 _physicalItems: null, 7199 _physicalItems: null,
7200 _physicalSizes: null, 7200 _physicalSizes: null,
7201 _firstVisibleIndexVal: null, 7201 _firstVisibleIndexVal: null,
7202 _lastVisibleIndexVal: null, 7202 _lastVisibleIndexVal: null,
7203 _collection: null, 7203 _collection: null,
7204 _itemsRendered: false,
7205 _lastPage: null,
7206 _maxPages: 3, 7204 _maxPages: 3,
7207 _focusedItem: null, 7205 _focusedItem: null,
7208 _focusedIndex: -1, 7206 _focusedIndex: -1,
7209 _offscreenFocusedItem: null, 7207 _offscreenFocusedItem: null,
7210 _focusBackfillItem: null, 7208 _focusBackfillItem: null,
7211 _itemsPerRow: 1, 7209 _itemsPerRow: 1,
7212 _itemWidth: 0, 7210 _itemWidth: 0,
7213 _rowHeight: 0, 7211 _rowHeight: 0,
7212 _templateCost: 0,
7214 get _physicalBottom() { 7213 get _physicalBottom() {
7215 return this._physicalTop + this._physicalSize; 7214 return this._physicalTop + this._physicalSize;
7216 }, 7215 },
7217 get _scrollBottom() { 7216 get _scrollBottom() {
7218 return this._scrollPosition + this._viewportHeight; 7217 return this._scrollPosition + this._viewportHeight;
7219 }, 7218 },
7220 get _virtualEnd() { 7219 get _virtualEnd() {
7221 return this._virtualStart + this._physicalCount - 1; 7220 return this._virtualStart + this._physicalCount - 1;
7222 }, 7221 },
7223 get _hiddenContentSize() { 7222 get _hiddenContentSize() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
7261 get _optPhysicalSize() { 7260 get _optPhysicalSize() {
7262 if (this.grid) { 7261 if (this.grid) {
7263 return this._estRowsInView * this._rowHeight * this._maxPages; 7262 return this._estRowsInView * this._rowHeight * this._maxPages;
7264 } 7263 }
7265 return this._viewportHeight * this._maxPages; 7264 return this._viewportHeight * this._maxPages;
7266 }, 7265 },
7267 get _optPhysicalCount() { 7266 get _optPhysicalCount() {
7268 return this._estRowsInView * this._itemsPerRow * this._maxPages; 7267 return this._estRowsInView * this._itemsPerRow * this._maxPages;
7269 }, 7268 },
7270 get _isVisible() { 7269 get _isVisible() {
7271 return this.scrollTarget && Boolean(this.scrollTarget.offsetWidth || this. scrollTarget.offsetHeight); 7270 return Boolean(this.offsetWidth || this.offsetHeight);
7272 }, 7271 },
7273 get firstVisibleIndex() { 7272 get firstVisibleIndex() {
7274 if (this._firstVisibleIndexVal === null) { 7273 if (this._firstVisibleIndexVal === null) {
7275 var physicalOffset = Math.floor(this._physicalTop + this._scrollerPaddin gTop); 7274 var physicalOffset = Math.floor(this._physicalTop + this._scrollerPaddin gTop);
7276 this._firstVisibleIndexVal = this._iterateItems(function(pidx, vidx) { 7275 this._firstVisibleIndexVal = this._iterateItems(function(pidx, vidx) {
7277 physicalOffset += this._getPhysicalSizeIncrement(pidx); 7276 physicalOffset += this._getPhysicalSizeIncrement(pidx);
7278 if (physicalOffset > this._scrollPosition) { 7277 if (physicalOffset > this._scrollPosition) {
7279 return this.grid ? vidx - vidx % this._itemsPerRow : vidx; 7278 return this.grid ? vidx - vidx % this._itemsPerRow : vidx;
7280 } 7279 }
7281 if (this.grid && this._virtualCount - 1 === vidx) { 7280 if (this.grid && this._virtualCount - 1 === vidx) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
7314 return Math.ceil(this._viewportHeight / this._rowHeight); 7313 return Math.ceil(this._viewportHeight / this._rowHeight);
7315 }, 7314 },
7316 get _physicalRows() { 7315 get _physicalRows() {
7317 return Math.ceil(this._physicalCount / this._itemsPerRow); 7316 return Math.ceil(this._physicalCount / this._itemsPerRow);
7318 }, 7317 },
7319 ready: function() { 7318 ready: function() {
7320 this.addEventListener('focus', this._didFocus.bind(this), true); 7319 this.addEventListener('focus', this._didFocus.bind(this), true);
7321 }, 7320 },
7322 attached: function() { 7321 attached: function() {
7323 this.updateViewportBoundaries(); 7322 this.updateViewportBoundaries();
7324 this._render(); 7323 if (this._physicalCount === 0) {
7324 this._debounceTemplate(this._render);
7325 }
7325 this.listen(this, 'iron-resize', '_resizeHandler'); 7326 this.listen(this, 'iron-resize', '_resizeHandler');
7326 }, 7327 },
7327 detached: function() { 7328 detached: function() {
7328 this._itemsRendered = false;
7329 this.unlisten(this, 'iron-resize', '_resizeHandler'); 7329 this.unlisten(this, 'iron-resize', '_resizeHandler');
7330 }, 7330 },
7331 _setOverflow: function(scrollTarget) { 7331 _setOverflow: function(scrollTarget) {
7332 this.style.webkitOverflowScrolling = scrollTarget === this ? 'touch' : ''; 7332 this.style.webkitOverflowScrolling = scrollTarget === this ? 'touch' : '';
7333 this.style.overflow = scrollTarget === this ? 'auto' : ''; 7333 this.style.overflow = scrollTarget === this ? 'auto' : '';
7334 }, 7334 },
7335 updateViewportBoundaries: function() { 7335 updateViewportBoundaries: function() {
7336 this._scrollerPaddingTop = this.scrollTarget === this ? 0 : parseInt(windo w.getComputedStyle(this)['padding-top'], 10); 7336 this._scrollerPaddingTop = this.scrollTarget === this ? 0 : parseInt(windo w.getComputedStyle(this)['padding-top'], 10);
7337 this._viewportHeight = this._scrollTargetHeight; 7337 this._viewportHeight = this._scrollTargetHeight;
7338 if (this.grid) { 7338 if (this.grid) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
7419 var inst = this.stamp(null); 7419 var inst = this.stamp(null);
7420 physicalItems[i] = inst.root.querySelector('*'); 7420 physicalItems[i] = inst.root.querySelector('*');
7421 Polymer.dom(this).appendChild(inst.root); 7421 Polymer.dom(this).appendChild(inst.root);
7422 } 7422 }
7423 return physicalItems; 7423 return physicalItems;
7424 }, 7424 },
7425 _increasePoolIfNeeded: function() { 7425 _increasePoolIfNeeded: function() {
7426 if (this._viewportHeight === 0) { 7426 if (this._viewportHeight === 0) {
7427 return false; 7427 return false;
7428 } 7428 }
7429 var isClientHeightFull = this._physicalBottom >= this._scrollBottom && thi s._physicalTop <= this._scrollPosition; 7429 var self = this;
7430 if (this._physicalSize >= this._optPhysicalSize && isClientHeightFull) { 7430 var isClientFull = this._physicalBottom >= this._scrollBottom && this._phy sicalTop <= this._scrollPosition;
7431 if (this._physicalSize >= this._optPhysicalSize && isClientFull) {
7431 return false; 7432 return false;
7432 } 7433 }
7433 var currentPage = Math.floor(this._physicalSize / this._viewportHeight); 7434 var maxPoolSize = Math.round(this._physicalCount * .5);
7434 if (currentPage === 0) { 7435 if (!isClientFull) {
7435 this._debounceTemplate(this._increasePool.bind(this, Math.round(this._ph ysicalCount * .5))); 7436 this._debounceTemplate(this._increasePool.bind(this, maxPoolSize));
7436 } else if (this._lastPage !== currentPage && isClientHeightFull) { 7437 return true;
7437 Polymer.dom.addDebouncer(this.debounce('_debounceTemplate', this._increa sePool.bind(this, this._itemsPerRow), 16));
7438 } else {
7439 this._debounceTemplate(this._increasePool.bind(this, this._itemsPerRow)) ;
7440 } 7438 }
7441 this._lastPage = currentPage; 7439 this._yield(function() {
7440 self._increasePool(Math.min(maxPoolSize, Math.max(1, Math.round(50 / sel f._templateCost))));
7441 });
7442 return true; 7442 return true;
7443 }, 7443 },
7444 _yield: function(cb) {
7445 var g = window;
7446 var handle = g.requestIdleCallback ? g.requestIdleCallback(cb) : g.setTime out(cb, 16);
7447 Polymer.dom.addDebouncer({
7448 complete: function() {
7449 g.cancelIdleCallback ? g.cancelIdleCallback(handle) : g.clearTimeout(h andle);
7450 cb();
7451 }
7452 });
7453 },
7444 _increasePool: function(missingItems) { 7454 _increasePool: function(missingItems) {
7445 var nextPhysicalCount = Math.min(this._physicalCount + missingItems, this. _virtualCount - this._virtualStart, Math.max(this.maxPhysicalCount, DEFAULT_PHYS ICAL_COUNT)); 7455 var nextPhysicalCount = Math.min(this._physicalCount + missingItems, this. _virtualCount - this._virtualStart, Math.max(this.maxPhysicalCount, DEFAULT_PHYS ICAL_COUNT));
7446 var prevPhysicalCount = this._physicalCount; 7456 var prevPhysicalCount = this._physicalCount;
7447 var delta = nextPhysicalCount - prevPhysicalCount; 7457 var delta = nextPhysicalCount - prevPhysicalCount;
7458 var ts = window.performance.now();
7448 if (delta <= 0) { 7459 if (delta <= 0) {
7449 return; 7460 return;
7450 } 7461 }
7451 [].push.apply(this._physicalItems, this._createPool(delta)); 7462 [].push.apply(this._physicalItems, this._createPool(delta));
7452 [].push.apply(this._physicalSizes, new Array(delta)); 7463 [].push.apply(this._physicalSizes, new Array(delta));
7453 this._physicalCount = prevPhysicalCount + delta; 7464 this._physicalCount = prevPhysicalCount + delta;
7454 if (this._physicalStart > this._physicalEnd && this._isIndexRendered(this. _focusedIndex) && this._getPhysicalIndex(this._focusedIndex) < this._physicalEnd ) { 7465 if (this._physicalStart > this._physicalEnd && this._isIndexRendered(this. _focusedIndex) && this._getPhysicalIndex(this._focusedIndex) < this._physicalEnd ) {
7455 this._physicalStart = this._physicalStart + delta; 7466 this._physicalStart = this._physicalStart + delta;
7456 } 7467 }
7457 this._update(); 7468 this._update();
7469 this._templateCost = (window.performance.now() - ts) / delta;
7458 }, 7470 },
7459 _render: function() { 7471 _render: function() {
7460 var requiresUpdate = this._virtualCount > 0 || this._physicalCount > 0; 7472 if (this.isAttached && this._isVisible) {
7461 if (this.isAttached && !this._itemsRendered && this._isVisible && requires Update) { 7473 if (this._physicalCount === 0) {
7462 this._lastPage = 0; 7474 this._increasePool(DEFAULT_PHYSICAL_COUNT);
7463 this._update(); 7475 } else {
7464 this._itemsRendered = true; 7476 this._update();
7477 }
7465 } 7478 }
7466 }, 7479 },
7467 _ensureTemplatized: function() { 7480 _ensureTemplatized: function() {
7468 if (!this.ctor) { 7481 if (!this.ctor) {
7469 var props = {}; 7482 var props = {};
7470 props.__key__ = true; 7483 props.__key__ = true;
7471 props[this.as] = true; 7484 props[this.as] = true;
7472 props[this.indexAs] = true; 7485 props[this.indexAs] = true;
7473 props[this.selectedAs] = true; 7486 props[this.selectedAs] = true;
7474 props.tabIndex = true; 7487 props.tabIndex = true;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
7535 }, 7548 },
7536 _itemsChanged: function(change) { 7549 _itemsChanged: function(change) {
7537 if (change.path === 'items') { 7550 if (change.path === 'items') {
7538 this._virtualStart = 0; 7551 this._virtualStart = 0;
7539 this._physicalTop = 0; 7552 this._physicalTop = 0;
7540 this._virtualCount = this.items ? this.items.length : 0; 7553 this._virtualCount = this.items ? this.items.length : 0;
7541 this._collection = this.items ? Polymer.Collection.get(this.items) : nul l; 7554 this._collection = this.items ? Polymer.Collection.get(this.items) : nul l;
7542 this._physicalIndexForKey = {}; 7555 this._physicalIndexForKey = {};
7543 this._firstVisibleIndexVal = null; 7556 this._firstVisibleIndexVal = null;
7544 this._lastVisibleIndexVal = null; 7557 this._lastVisibleIndexVal = null;
7558 this._physicalCount = this._physicalCount || 0;
7559 this._physicalItems = this._physicalItems || [];
7560 this._physicalSizes = this._physicalSizes || [];
7561 this._physicalStart = 0;
7545 this._resetScrollPosition(0); 7562 this._resetScrollPosition(0);
7546 this._removeFocusedItem(); 7563 this._removeFocusedItem();
7547 if (!this._physicalItems) { 7564 this._debounceTemplate(this._render);
7548 this._physicalCount = Math.max(1, Math.min(DEFAULT_PHYSICAL_COUNT, thi s._virtualCount));
7549 this._physicalItems = this._createPool(this._physicalCount);
7550 this._physicalSizes = new Array(this._physicalCount);
7551 }
7552 this._physicalStart = 0;
7553 } else if (change.path === 'items.splices') { 7565 } else if (change.path === 'items.splices') {
7554 this._adjustVirtualIndex(change.value.indexSplices); 7566 this._adjustVirtualIndex(change.value.indexSplices);
7555 this._virtualCount = this.items ? this.items.length : 0; 7567 this._virtualCount = this.items ? this.items.length : 0;
7568 this._debounceTemplate(this._render);
7556 } else { 7569 } else {
7557 this._forwardItemPath(change.path.split('.').slice(1).join('.'), change. value); 7570 this._forwardItemPath(change.path.split('.').slice(1).join('.'), change. value);
7558 return;
7559 } 7571 }
7560 this._itemsRendered = false;
7561 this._debounceTemplate(this._render);
7562 }, 7572 },
7563 _adjustVirtualIndex: function(splices) { 7573 _adjustVirtualIndex: function(splices) {
7564 splices.forEach(function(splice) { 7574 splices.forEach(function(splice) {
7565 splice.removed.forEach(this._removeItem, this); 7575 splice.removed.forEach(this._removeItem, this);
7566 if (splice.index < this._virtualStart) { 7576 if (splice.index < this._virtualStart) {
7567 var delta = Math.max(splice.addedCount - splice.removed.length, splice .index - this._virtualStart); 7577 var delta = Math.max(splice.addedCount - splice.removed.length, splice .index - this._virtualStart);
7568 this._virtualStart = this._virtualStart + delta; 7578 this._virtualStart = this._virtualStart + delta;
7569 if (this._focusedIndex >= 0) { 7579 if (this._focusedIndex >= 0) {
7570 this._focusedIndex = this._focusedIndex + delta; 7580 this._focusedIndex = this._focusedIndex + delta;
7571 } 7581 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
7720 } 7730 }
7721 }, 7731 },
7722 scrollToItem: function(item) { 7732 scrollToItem: function(item) {
7723 return this.scrollToIndex(this.items.indexOf(item)); 7733 return this.scrollToIndex(this.items.indexOf(item));
7724 }, 7734 },
7725 scrollToIndex: function(idx) { 7735 scrollToIndex: function(idx) {
7726 if (typeof idx !== 'number' || idx < 0 || idx > this.items.length - 1) { 7736 if (typeof idx !== 'number' || idx < 0 || idx > this.items.length - 1) {
7727 return; 7737 return;
7728 } 7738 }
7729 Polymer.dom.flush(); 7739 Polymer.dom.flush();
7730 if (!this._itemsRendered) { 7740 if (this._physicalCount === 0) {
7731 return; 7741 return;
7732 } 7742 }
7733 idx = Math.min(Math.max(idx, 0), this._virtualCount - 1); 7743 idx = Math.min(Math.max(idx, 0), this._virtualCount - 1);
7734 if (!this._isIndexRendered(idx) || idx >= this._maxVirtualStart) { 7744 if (!this._isIndexRendered(idx) || idx >= this._maxVirtualStart) {
7735 this._virtualStart = this.grid ? idx - this._itemsPerRow * 2 : idx - 1; 7745 this._virtualStart = this.grid ? idx - this._itemsPerRow * 2 : idx - 1;
7736 } 7746 }
7737 this._manageFocus(); 7747 this._manageFocus();
7738 this._assignModels(); 7748 this._assignModels();
7739 this._updateMetrics(); 7749 this._updateMetrics();
7740 this._physicalTop = Math.floor(this._virtualStart / this._itemsPerRow) * t his._physicalAverage; 7750 this._physicalTop = Math.floor(this._virtualStart / this._itemsPerRow) * t his._physicalAverage;
(...skipping 17 matching lines...) Expand all
7758 this._physicalAverage = 0; 7768 this._physicalAverage = 0;
7759 this._physicalAverageCount = 0; 7769 this._physicalAverageCount = 0;
7760 }, 7770 },
7761 _resizeHandler: function() { 7771 _resizeHandler: function() {
7762 if (IOS && Math.abs(this._viewportHeight - this._scrollTargetHeight) < 100 ) { 7772 if (IOS && Math.abs(this._viewportHeight - this._scrollTargetHeight) < 100 ) {
7763 return; 7773 return;
7764 } 7774 }
7765 Polymer.dom.addDebouncer(this.debounce('_debounceTemplate', function() { 7775 Polymer.dom.addDebouncer(this.debounce('_debounceTemplate', function() {
7766 this.updateViewportBoundaries(); 7776 this.updateViewportBoundaries();
7767 this._render(); 7777 this._render();
7768 if (this._itemsRendered && this._physicalItems && this._isVisible) { 7778 if (this._physicalCount > 0 && this._isVisible) {
7769 this._resetAverage(); 7779 this._resetAverage();
7770 this.scrollToIndex(this.firstVisibleIndex); 7780 this.scrollToIndex(this.firstVisibleIndex);
7771 } 7781 }
7772 }.bind(this), 1)); 7782 }.bind(this), 1));
7773 }, 7783 },
7774 _getModelFromItem: function(item) { 7784 _getModelFromItem: function(item) {
7775 var key = this._collection.getKey(item); 7785 var key = this._collection.getKey(item);
7776 var pidx = this._physicalIndexForKey[key]; 7786 var pidx = this._physicalIndexForKey[key];
7777 if (pidx != null) { 7787 if (pidx != null) {
7778 return this._physicalItems[pidx]._templateInstance; 7788 return this._physicalItems[pidx]._templateInstance;
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after
8817 8827
8818 case HistoryRange.MONTH: 8828 case HistoryRange.MONTH:
8819 histogramValue = HistoryPageViewHistogram.GROUPED_MONTH; 8829 histogramValue = HistoryPageViewHistogram.GROUPED_MONTH;
8820 break; 8830 break;
8821 } 8831 }
8822 break; 8832 break;
8823 } 8833 }
8824 md_history.BrowserService.getInstance().recordHistogram('History.HistoryPage View', histogramValue, HistoryPageViewHistogram.END); 8834 md_history.BrowserService.getInstance().recordHistogram('History.HistoryPage View', histogramValue, HistoryPageViewHistogram.END);
8825 } 8835 }
8826 }); 8836 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_downloads/crisper.js ('k') | chrome/test/data/webui/settings/languages_page_browsertest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698