DevTools: Fix regression that slows down "Goto Source" dialog

The regression was caused by r174810. The root cause is the
implementation of WebInspector.StaticViewportElement which doesn't
support lazy DOM element creation. So every time the viewport processed
cumulative heights of inner elements, it actually forced all DOM elements
for viewport to be created.

To keep things simple, the patch moves fastHeight calls out of
ViewportElement interface into ViewportProvider.

BUG=377749
R=loislo@chromium.org

Review URL: https://codereview.chromium.org/305813005

git-svn-id: svn://svn.chromium.org/blink/trunk@175059 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4d5bc2e3
...@@ -159,6 +159,15 @@ WebInspector.ConsoleView.prototype = { ...@@ -159,6 +159,15 @@ WebInspector.ConsoleView.prototype = {
return this._visibleViewMessages[index]; return this._visibleViewMessages[index];
}, },
/**
* @param {number} index
* @return {number}
*/
fastHeight: function(index)
{
return this._visibleViewMessages[index].fastHeight();
},
/** /**
* @param {!WebInspector.Target} target * @param {!WebInspector.Target} target
*/ */
......
...@@ -352,6 +352,20 @@ WebInspector.FilteredItemSelectionDialog.prototype = { ...@@ -352,6 +352,20 @@ WebInspector.FilteredItemSelectionDialog.prototype = {
return this._filteredItems.length; return this._filteredItems.length;
}, },
/**
* @param {number} index
* @return {number}
*/
fastHeight: function(index)
{
if (!this._rowHeight) {
var delegateIndex = this._filteredItems[index];
var element = this._createItemElement(delegateIndex);
this._rowHeight = element.measurePreferredSize(this._viewportControl.contentElement()).height;
}
return this._rowHeight;
},
/** /**
* @param {number} index * @param {number} index
* @return {!WebInspector.ViewportElement} * @return {!WebInspector.ViewportElement}
...@@ -360,11 +374,9 @@ WebInspector.FilteredItemSelectionDialog.prototype = { ...@@ -360,11 +374,9 @@ WebInspector.FilteredItemSelectionDialog.prototype = {
{ {
var delegateIndex = this._filteredItems[index]; var delegateIndex = this._filteredItems[index];
var element = this._createItemElement(delegateIndex); var element = this._createItemElement(delegateIndex);
if (!this._rowHeight)
this._rowHeight = element.measurePreferredSize(this._viewportControl.contentElement()).height;
if (index === this._selectedIndexInFiltered) if (index === this._selectedIndexInFiltered)
element.classList.add("selected"); element.classList.add("selected");
return new WebInspector.StaticViewportElement(element, this._rowHeight); return new WebInspector.StaticViewportElement(element);
}, },
__proto__: WebInspector.DialogDelegate.prototype __proto__: WebInspector.DialogDelegate.prototype
......
...@@ -65,6 +65,12 @@ WebInspector.ViewportControl.Provider = function() ...@@ -65,6 +65,12 @@ WebInspector.ViewportControl.Provider = function()
} }
WebInspector.ViewportControl.Provider.prototype = { WebInspector.ViewportControl.Provider.prototype = {
/**
* @param {number} index
* @return {number}
*/
fastHeight: function(index) { return 0; },
/** /**
* @return {number} * @return {number}
*/ */
...@@ -86,11 +92,6 @@ WebInspector.ViewportElement.prototype = { ...@@ -86,11 +92,6 @@ WebInspector.ViewportElement.prototype = {
wasShown: function() { }, wasShown: function() { },
/**
* @return {number}
*/
fastHeight: function() { },
/** /**
* @return {!Element} * @return {!Element}
*/ */
...@@ -101,12 +102,10 @@ WebInspector.ViewportElement.prototype = { ...@@ -101,12 +102,10 @@ WebInspector.ViewportElement.prototype = {
* @constructor * @constructor
* @implements {WebInspector.ViewportElement} * @implements {WebInspector.ViewportElement}
* @param {!Element} element * @param {!Element} element
* @param {number} height
*/ */
WebInspector.StaticViewportElement = function(element, height) WebInspector.StaticViewportElement = function(element)
{ {
this._element = element; this._element = element;
this._height = height;
} }
WebInspector.StaticViewportElement.prototype = { WebInspector.StaticViewportElement.prototype = {
...@@ -114,14 +113,6 @@ WebInspector.StaticViewportElement.prototype = { ...@@ -114,14 +113,6 @@ WebInspector.StaticViewportElement.prototype = {
wasShown: function() { }, wasShown: function() { },
/**
* @return {number}
*/
fastHeight: function()
{
return this._height;
},
/** /**
* @return {!Element} * @return {!Element}
*/ */
...@@ -188,9 +179,9 @@ WebInspector.ViewportControl.prototype = { ...@@ -188,9 +179,9 @@ WebInspector.ViewportControl.prototype = {
if (!itemCount) if (!itemCount)
return; return;
this._cumulativeHeights = new Int32Array(itemCount); this._cumulativeHeights = new Int32Array(itemCount);
this._cumulativeHeights[0] = this._provider.itemElement(0).fastHeight(); this._cumulativeHeights[0] = this._provider.fastHeight(0);
for (var i = 1; i < itemCount; ++i) for (var i = 1; i < itemCount; ++i)
this._cumulativeHeights[i] = this._cumulativeHeights[i - 1] + this._provider.itemElement(i).fastHeight(); this._cumulativeHeights[i] = this._cumulativeHeights[i - 1] + this._provider.fastHeight(i);
}, },
/** /**
...@@ -361,7 +352,7 @@ WebInspector.ViewportControl.prototype = { ...@@ -361,7 +352,7 @@ WebInspector.ViewportControl.prototype = {
for (var i = 0; i < this._renderedItems.length; ++i) { for (var i = 0; i < this._renderedItems.length; ++i) {
this._renderedItems[i].willHide(); this._renderedItems[i].willHide();
// Tolerate 1-pixel error due to double-to-integer rounding errors. // Tolerate 1-pixel error due to double-to-integer rounding errors.
if (this._cumulativeHeights && Math.abs(this._cachedItemHeight(this._firstVisibleIndex + i) - this._renderedItems[i].fastHeight()) > 1) if (this._cumulativeHeights && Math.abs(this._cachedItemHeight(this._firstVisibleIndex + i) - this._provider.fastHeight(i + this._firstVisibleIndex)) > 1)
delete this._cumulativeHeights; delete this._cumulativeHeights;
} }
this._rebuildCumulativeHeightsIfNeeded(); this._rebuildCumulativeHeightsIfNeeded();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment