Comment out some of the requestIdleCallback to fix walkthrough crash

(closes #4533)

There are several issues here.. Here's a quick brain dump:

- the requestIdleCallbacks in map.js (scheduleRedraw) seem to be causing
crashiness in Firefox on fast zoom/unzoom, mousewheel, etc.. anything where
the view transform changes a lot and the redraws don't catch up.
(commented out, reverted back to lodash throttle)

- the requestIdleCallback worker queue in idle_worker.js seems to be causing
crashiness in Firefox and Chrome when exiting the walkthrough.  Something about
deferring the tile parsing as the user leaves the intro has a problem.
It might be an infinite `while` loop, not sure.
(commented out, reverted back to for loop)

- the requestIdleCallback in call_when_idle.js is only used to defer
tile loading in context.loadTiles() - this one seems fine, and actually
has maybe the biggest benefit for improving performance.
(left in)
This commit is contained in:
Bryan Housel
2017-11-15 22:21:40 -05:00
parent 2962f80821
commit 0c0ecdfcfc
2 changed files with 47 additions and 37 deletions
+19 -16
View File
@@ -1,5 +1,6 @@
import _compact from 'lodash-es/compact';
import _map from 'lodash-es/map';
import _throttle from 'lodash-es/throttle';
import _values from 'lodash-es/values';
import { set as d3_set } from 'd3-collection';
@@ -80,25 +81,27 @@ export function rendererMap(context) {
.on('zoom', zoomPan);
var _selection = d3_select(null);
var isRedrawScheduled = false;
var pendingRedrawCall;
function scheduleRedraw() {
// Only schedule the redraw if one has not already been set.
if (isRedrawScheduled) return;
isRedrawScheduled = true;
var that = this;
var args = arguments;
pendingRedrawCall = requestIdleCallback(function () {
// Reset the boolean so future redraws can be set.
isRedrawScheduled = false;
redraw.apply(that, args);
}, { timeout: 1400 });
}
var scheduleRedraw = _throttle(redraw, 750);
// var isRedrawScheduled = false;
// var pendingRedrawCall;
// function scheduleRedraw() {
// // Only schedule the redraw if one has not already been set.
// if (isRedrawScheduled) return;
// isRedrawScheduled = true;
// var that = this;
// var args = arguments;
// pendingRedrawCall = window.requestIdleCallback(function () {
// // Reset the boolean so future redraws can be set.
// isRedrawScheduled = false;
// redraw.apply(that, args);
// }, { timeout: 1400 });
// }
function cancelPendingRedraw() {
isRedrawScheduled = false;
window.cancelIdleCallback(pendingRedrawCall);
scheduleRedraw.cancel();
// isRedrawScheduled = false;
// window.cancelIdleCallback(pendingRedrawCall);
}
function map(selection) {
+28 -21
View File
@@ -1,27 +1,34 @@
export function utilIdleWorker(tasks, processor, callback) {
var processed = [];
var currentPos = 0;
var totalTasks = tasks.length;
function worker(deadline) {
while (deadline.timeRemaining() > 0 && currentPos < totalTasks) {
var result = processor(tasks[currentPos]);
// if falsy dont add to the processed list
if (result) processed.push(result);
currentPos++;
}
// more tasks are left, we might need more idleCallbacks
if (currentPos < totalTasks) {
return window.requestIdleCallback(function(deadline) {worker(deadline);});
}
// tasks are completed
return callback(processed);
var results = [], result;
for (var i = 0; i < tasks.length; i++) {
result = processor(tasks[i]);
if (result) results.push(result);
}
callback(results);
window.requestIdleCallback(function(deadline) {worker(deadline);});
// var processed = [];
// var currentPos = 0;
// var totalTasks = tasks.length;
// function worker(deadline) {
// while (deadline.timeRemaining() > 0 && currentPos < totalTasks) {
// var result = processor(tasks[currentPos]);
// // if falsy dont add to the processed list
// if (result) processed.push(result);
// currentPos++;
// }
// // more tasks are left, we might need more idleCallbacks
// if (currentPos < totalTasks) {
// return window.requestIdleCallback(function(deadline) {worker(deadline);});
// }
// // tasks are completed
// return callback(processed);
// }
// window.requestIdleCallback(function(deadline) {worker(deadline);});
}
// shim