зеркало из https://github.com/mozilla/snowl.git
switch from Sync.sleep() back to a generator (although a custom one rather than Strands this time) in the river view to avoid the long-running script warning, which unfortunately gets applied to chrome code in tabs and can't distinguish between long-running code that horks the UI thread and code (like that in the river view) that spins the event loop so as not to hork the thread
This commit is contained in:
Родитель
8a496f5c18
Коммит
3c8abaabb5
|
@ -762,38 +762,53 @@ this._log.info("onMessageAdded: REFRESH RIVER");
|
||||||
_rebuildID: null,
|
_rebuildID: null,
|
||||||
|
|
||||||
_rebuildView: function() {
|
_rebuildView: function() {
|
||||||
let begin = new Date();
|
let generator = this._makeRebuildViewGenerator();
|
||||||
let rebuildID = this._rebuildID = Cc["@mozilla.org/uuid-generator;1"].
|
|
||||||
getService(Ci.nsIUUIDGenerator).
|
|
||||||
generateUUID().toString();
|
|
||||||
|
|
||||||
// Reset the view by removing all its groups and messages.
|
// Reset the view by removing all its message boxes.
|
||||||
// XXX Since contentBox is an HTML div, could we do this more quickly
|
// XXX Since contentBox is an HTML div, could we do this more quickly
|
||||||
// by setting innerHTML to an empty string?
|
// by setting innerHTML to an empty string?
|
||||||
while (this._contentBox.hasChildNodes())
|
while (this._contentBox.hasChildNodes())
|
||||||
this._contentBox.removeChild(this._contentBox.lastChild);
|
this._contentBox.removeChild(this._contentBox.lastChild);
|
||||||
|
|
||||||
// Build the box for each message and add it to the view.
|
(function() {
|
||||||
|
try {
|
||||||
|
let timeout = generator.next();
|
||||||
|
window.setTimeout(arguments.callee, timeout);
|
||||||
|
}
|
||||||
|
catch(ex if ex == StopIteration) {}
|
||||||
|
})()
|
||||||
|
},
|
||||||
|
|
||||||
|
_makeRebuildViewGenerator: function() {
|
||||||
let first = new Date();
|
let first = new Date();
|
||||||
|
|
||||||
|
let rebuildID = this._rebuildID = Cc["@mozilla.org/uuid-generator;1"].
|
||||||
|
getService(Ci.nsIUUIDGenerator).
|
||||||
|
generateUUID().toString();
|
||||||
|
this._log.trace("started rebuild " + rebuildID);
|
||||||
|
|
||||||
for each (let message in this._collection) {
|
for each (let message in this._collection) {
|
||||||
let before = new Date();
|
let before = new Date();
|
||||||
let messageBox = this._buildMessageBox(message);
|
this._contentBox.appendChild(this._buildMessageBox(message));
|
||||||
this._contentBox.appendChild(messageBox);
|
|
||||||
let after = new Date();
|
let after = new Date();
|
||||||
let timeout = this._rebuildViewTimeout;
|
let timeout = this._rebuildViewTimeout;
|
||||||
this._log.trace("last: " + (after - before) + "ms; " +
|
this._log.trace("rebuild stats: " +
|
||||||
|
"last: " + (after - before) + "ms; " +
|
||||||
"total: " + (after - first) + "ms; " +
|
"total: " + (after - first) + "ms; " +
|
||||||
"timeout: " + timeout + "ms");
|
"timeout: " + timeout + "ms");
|
||||||
Sync.sleep(timeout);
|
yield timeout;
|
||||||
|
|
||||||
// Stop rebuilding if another rebuild started while we were sleeping.
|
// Stop the rebuild if another rebuild started while we were yielded.
|
||||||
if (this._rebuildID != rebuildID) {
|
if (this._rebuildID != rebuildID) {
|
||||||
this._log.debug(this._rebuildID + " != " + rebuildID + "; stopping rebuild");
|
this._log.trace("interrupted rebuild " + rebuildID + " for rebuild " +
|
||||||
|
this._rebuildID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._log.info("time spent building view: " + (new Date() - begin) + "ms\n");
|
let last = new Date();
|
||||||
|
this._log.trace("finished rebuild " + rebuildID + " in " +
|
||||||
|
((last - first)/1000) + " seconds)");
|
||||||
},
|
},
|
||||||
|
|
||||||
_buildMessageBox: function(message) {
|
_buildMessageBox: function(message) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче