mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 13:38:26 +02:00
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:
+19
-16
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user