-
Notifications
You must be signed in to change notification settings - Fork 399
Memory management fix | Adding max number of active threads #2
base: solution
Are you sure you want to change the base?
Conversation
}; | ||
}; | ||
|
||
var QRCodeManager = function(element) { | ||
this.numActiveThreads = 0; | ||
this.maxThreads = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an arbitrary number - good question hehe
A better approach could be:
this.maxThreads = window.navigator.hardwareConcurrency || 4;
https://developer.mozilla.org/en-US/docs/Web/API/NavigatorConcurrentHardware/hardwareConcurrency
I'll update the PR tonight
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome!
qrCodeManager.showDialog(url); | ||
} | ||
}); | ||
if (qrCodeManager.numActiveThreads < qrCodeManager.maxThreads) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if numActiveThreads is over maxThreads? does the frame get dropped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The consequence is: The worker won't be called.
On my i5
it takes about 10ms for the worker to respond back, at the worst case scenario we'll have a "10ms lag", **
2.5ms
** on the best case, not noticeable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool cool. thanks
hey @cameronwp
I had to bump node-sass version to get the
solution
branch to work, not sure why tho.