vanta / fauxbar

Automatically exported from code.google.com/p/fauxbar
0 stars 0 forks source link

Implement HTML5 Web Workers to handle resource usage better? #82

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
http://www.html5rocks.com/en/tutorials/workers/basics/
http://www.codediesel.com/javascript/introducing-html5-web-workers/
http://en.wikipedia.org/wiki/Web_Workers
http://www.sitepoint.com/javascript-threading-html5-web-workers/

Upon first glance, if I'm understanding this correctly, you can turn a 
JavaScript file into a separate process/thread with limited permissions, and 
use message passing to get things done. Workers could be created and destroyed 
as needed. Because they sit in their own processes, they don't freeze up other 
scripts.

Sounds like this would:
- Let scores be calculated without freezing the rest of Fauxbar
- Let memory-intensive operations be loaded and unloaded, clearing their memory 
usage when done (no more need for Fauxbar Memory Helper?)

Original issue reported on code.google.com by fauxbar....@gmail.com on 11 Dec 2011 at 2:15

GoogleCodeExporter commented 9 years ago
Giving this a go.

Not 100% sure bit I think three Web Workers would suffice:

Worker #1 for indexing everything, would solve issue #15, as scores could be 
calculated without needing to worry about freezing Fauxbar (though this would 
still only be done when the computer becomes idle, but it'd be okay if the user 
started using Fauxbar again mid-index). Would only need to be created when 
performing entire reindexes.

Worker #2 for background functions, like capturing screenshots and listening 
for Chrome events.

Worker #3 for helping out Fauxbar's main page and UI. Main page would use 
chrome.getBackgroundPage() and access the worker from there. Assuming the 
initial call to chrome.getBackgroundPage() is lag-free, might not need to load 
as many scripts when the page loads (maybe). Would also make things easier to 
debug (WebKit doesn't do a very good job of debugging Ajax-loaded scripts).

All in all, when the computer becomes idle after a minute, Workers could be 
destroyed and recreated, resetting memory, without needing a second extension 
to do so. This does not resolve the problem of memory increasing for whatever 
reason, but would reset it in a much nicer way than Fauxbar Memory Helper.

Original comment by fauxbar....@gmail.com on 12 Dec 2011 at 1:20

GoogleCodeExporter commented 9 years ago
Having played with this a little now, it seems SharedWorkers don't log any 
errors yet :/
http://code.google.com/p/chromium/issues/detail?id=36577
http://code.google.com/p/chromium/issues/detail?id=105001
http://code.google.com/p/chromium/issues/detail?id=105004

Dedicated workers seemed okay, however these don't appear to create their own 
process in Chrome's task manager, so measuring success of memory usage would be 
too hard.

A dedicated worker for indexing is still a good idea, but a low priority.

Merging this into issue #2. A good learning experience nonetheless.

Original comment by fauxbar....@gmail.com on 12 Dec 2011 at 4:05