I have an application that calls a web worker after clicking a button. Computations are transferred to the employee in order to reduce the user interface and make it responsive to user actions during the calculations.
Everything is going well, and after about 0.8-1.5 seconds, the worker sends a response. In work.onmessage, I do all the necessary DOM actions. But after that, the GC appears and practically blocks the user interface for 2 or more seconds, depending on the processor. This really baffles me, because user interface locking is what I want to prevent.
Here's a screenshot of the timeline / memory console tab tab: http://i.imgur.com/zUoHa.jpg
As you can see, GC events occur immediately after all manipulations with the DOM. In fact, there is only one repaint event (using DocumentFragment).
js main code:
var sortWorker = new Worker('js/contactsorter.js'); sortWorker.onmessage = function(e) { var messages = []; e.data.forEach(function(userDoc) { var contactSection = _drawContact(userDoc); messages.push(contactSection); }); meta.append(messages);
contactsorter.js (worker):
onmessage = function(e) { var uid, output = [], usersStat = {};
Is there a way to avoid these GC events in this place or not?
UPD: it seems to me that the time of the GC (s) depends on the amount of data that was sent to the employee. UPD2: after shutting down and loading, GC events occur only twice, thereby blocking the user interface in less than a second. Hm?
Dmitrii Sorin
source share