Reduce idle CPU use to ~0%

Various animated things (search spinner, progress meters) were using CPU
even when hidden, either because they weren't properly hidden
(equivalent of `display: none` rather than `visibility: hidden`) or
because of bizarre Firefox bugs with progress meters on Linux.

Addresses #1455
This commit is contained in:
Dan Stillman 2018-03-06 04:19:01 -05:00
parent da09a3bb96
commit c4a64216ce
4 changed files with 36 additions and 10 deletions

View file

@ -206,14 +206,20 @@ var Zotero_Lookup = new function () {
} }
this.toggleProgress = function(on) { this.toggleProgress = function(on) {
// In Firefox 52.6.0, progressmeters burn CPU at idle on Linux when undetermined, even
// if they're hidden. (Being hidden is enough on macOS.)
var mode = on ? 'undetermined' : 'determined';
//single line //single line
var txtBox = document.getElementById("zotero-lookup-textbox"); var txtBox = document.getElementById("zotero-lookup-textbox");
txtBox.style.opacity = on ? 0.5 : 1; txtBox.style.opacity = on ? 0.5 : 1;
txtBox.disabled = !!on; txtBox.disabled = !!on;
document.getElementById("zotero-lookup-progress").setAttribute("collapsed", !on); var p1 = document.getElementById("zotero-lookup-progress");
p1.mode = mode;
//multiline //multiline
document.getElementById("zotero-lookup-multiline-textbox").disabled = !!on; document.getElementById("zotero-lookup-multiline-textbox").disabled = !!on;
document.getElementById("zotero-lookup-multiline-progress").setAttribute("collapsed", !on); var p2 = document.getElementById("zotero-lookup-multiline-progress");
p2.mode = mode;
} }
} }

View file

@ -1833,7 +1833,19 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
else { else {
label.hidden = true; label.hidden = true;
} }
var progressMeter = win.ZoteroPane.document.getElementById('zotero-pane-progressmeter') // This is the craziest thing. In Firefox 52.6.0, the very presence of this line
// causes Zotero on Linux to burn 5% CPU at idle, even if everything below it in
// the block is commented out. Same if the progressmeter itself is hidden="true".
// For some reason it also doesn't seem to work to set the progressmeter to
// 'determined' when hiding, which we're doing in lookup.js. So instead, create a new
// progressmeter each time and delete it in _hideWindowZoteroPaneOverlay().
//
//let progressMeter = win.ZoteroPane.document.getElementById('zotero-pane-progressmeter');
let doc = win.ZoteroPane.document;
let container = doc.getElementById('zotero-pane-progressmeter-container');
let progressMeter = doc.createElement('progressmeter');
progressMeter.id = 'zotero-pane-progressmeter';
progressMeter.setAttribute('mode', 'undetermined');
if (determinate) { if (determinate) {
progressMeter.mode = 'determined'; progressMeter.mode = 'determined';
progressMeter.value = 0; progressMeter.value = 0;
@ -1842,6 +1854,7 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
else { else {
progressMeter.mode = 'undetermined'; progressMeter.mode = 'undetermined';
} }
container.appendChild(progressMeter);
_showWindowZoteroPaneOverlay(win.ZoteroPane.document); _showWindowZoteroPaneOverlay(win.ZoteroPane.document);
win.ZoteroPane.document.getElementById('zotero-pane-overlay-deck').selectedIndex = 0; win.ZoteroPane.document.getElementById('zotero-pane-overlay-deck').selectedIndex = 0;
@ -1929,6 +1942,12 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
doc.getElementById('zotero-pane-tab-catcher-top').hidden = true; doc.getElementById('zotero-pane-tab-catcher-top').hidden = true;
doc.getElementById('zotero-pane-tab-catcher-bottom').hidden = true; doc.getElementById('zotero-pane-tab-catcher-bottom').hidden = true;
doc.getElementById('zotero-pane-overlay').hidden = true; doc.getElementById('zotero-pane-overlay').hidden = true;
// See note in showZoteroPaneProgressMeter()
let pm = doc.getElementById('zotero-pane-progressmeter');
if (pm) {
pm.parentNode.removeChild(pm);
}
} }

View file

@ -2256,10 +2256,10 @@ var ZoteroPane = new function()
return; return;
} }
var spinner = document.getElementById('zotero-tb-search-spinner'); var spinner = document.getElementById('zotero-tb-search-spinner');
spinner.style.visibility = 'visible'; spinner.style.display = 'inline';
var searchVal = search.value; var searchVal = search.value;
yield this.itemsView.setFilter('search', searchVal); yield this.itemsView.setFilter('search', searchVal);
spinner.style.visibility = 'hidden'; spinner.style.display = 'none';
if (runAdvanced) { if (runAdvanced) {
this.clearItemsPaneMessage(); this.clearItemsPaneMessage();
} }

View file

@ -170,7 +170,7 @@
<description>&zotero.lookup.description;</description> <description>&zotero.lookup.description;</description>
<vbox id="zotero-lookup-singleLine"> <vbox id="zotero-lookup-singleLine">
<stack> <stack>
<progressmeter id="zotero-lookup-progress" mode="undetermined" collapsed="true"/> <progressmeter id="zotero-lookup-progress" mode="determined"/>
<textbox id="zotero-lookup-textbox" <textbox id="zotero-lookup-textbox"
onkeypress="return Zotero_Lookup.onKeyPress(event, this)" onkeypress="return Zotero_Lookup.onKeyPress(event, this)"
oninput="Zotero_Lookup.onInput(event, this)" oninput="Zotero_Lookup.onInput(event, this)"
@ -182,7 +182,7 @@
<textbox id="zotero-lookup-multiline-textbox" onkeypress="return Zotero_Lookup.onKeyPress(event, this)" multiline="true" rows="5" wrap="off" flex="1"/> <textbox id="zotero-lookup-multiline-textbox" onkeypress="return Zotero_Lookup.onKeyPress(event, this)" multiline="true" rows="5" wrap="off" flex="1"/>
<hbox align="start" id="zotero-lookup-buttons" class="zotero-button-clear-image"> <hbox align="start" id="zotero-lookup-buttons" class="zotero-button-clear-image">
<button label="&zotero.lookup.button.search;" align="start" oncommand="Zotero_Lookup.accept(document.getElementById('zotero-lookup-multiline-textbox'))"/> <button label="&zotero.lookup.button.search;" align="start" oncommand="Zotero_Lookup.accept(document.getElementById('zotero-lookup-multiline-textbox'))"/>
<progressmeter id="zotero-lookup-multiline-progress" mode="undetermined" collapsed="true" flex="1"/> <progressmeter id="zotero-lookup-multiline-progress" mode="determined" flex="1"/>
</hbox> </hbox>
</vbox> </vbox>
</vbox> </vbox>
@ -207,7 +207,7 @@
<toolbarseparator/> <toolbarseparator/>
<toolbarbutton id="zotero-tb-advanced-search" class="zotero-tb-button" tooltiptext="&zotero.toolbar.advancedSearch;" command="cmd_zotero_advancedSearch"/> <toolbarbutton id="zotero-tb-advanced-search" class="zotero-tb-button" tooltiptext="&zotero.toolbar.advancedSearch;" command="cmd_zotero_advancedSearch"/>
<spacer flex="1"/> <spacer flex="1"/>
<image id="zotero-tb-search-spinner" class="zotero-spinner-14" style="visibility: hidden"/> <image id="zotero-tb-search-spinner" class="zotero-spinner-14" style="display: none"/>
<textbox id="zotero-tb-search" type="search" timeout="250" <textbox id="zotero-tb-search" type="search" timeout="250"
onkeypress="ZoteroPane_Local.handleSearchKeypress(this, event)" onkeypress="ZoteroPane_Local.handleSearchKeypress(this, event)"
oninput="ZoteroPane_Local.handleSearchInput(this, event)" oninput="ZoteroPane_Local.handleSearchInput(this, event)"
@ -611,9 +611,10 @@
<deck id="zotero-pane-overlay-deck" flex="1"> <deck id="zotero-pane-overlay-deck" flex="1">
<box id="zotero-pane-progress" flex="1" align="center" pack="center"> <box id="zotero-pane-progress" flex="1" align="center" pack="center">
<box style="background: white; border-radius: 1px; box-shadow: gray 4px 6px 4px;" width="300" height="30"> <box style="background: white; border-radius: 1px; box-shadow: gray 4px 6px 4px;" width="300" height="30">
<vbox style="padding:10px" flex="1"> <vbox id="zotero-pane-progressmeter-container" style="padding:10px" flex="1">
<label id="zotero-pane-progress-label"/> <label id="zotero-pane-progress-label"/>
<progressmeter id="zotero-pane-progressmeter" mode="undetermined"/> <!-- See note in Zotero.showZoteroPaneProgressMeter()
<progressmeter id="zotero-pane-progressmeter" mode="undetermined"/> -->
</vbox> </vbox>
</box> </box>
</box> </box>