-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MessageChannel
implementation to improve performance
#4
Comments
You're right. My use-case for making this was not in hot code, so the |
Here is the examples of I think it would be enough if you just add the implementation via In this case your implementation will be really simple (in comparison with others) and work well in most of cases. Also: Stuk/jszip#619 (comment) |
MessageChannel
implementation to improve performance
I agree. That's a good plan. I don't have time to work on this right now. Contributions are of course welcome. In the meantime, I added a note to the readme. |
Still not fixed? export const setImmediate = /*#__PURE__*/ (function() {
const {port1, port2} = new MessageChannel();
const queue = [];
port1.onmessage = function() {
const callback = queue.shift();
callback();
};
return function(callback) {
port2.postMessage(null);
queue.push(callback);
};
})(); This implementation is only for browsers, to use it in Node.js it requires to call UPD. For me it works fine, but it probably requires to add |
I don't know why @Stuk still not changed *Since the performance is terrible. It works up to 50 times slower because of this library. |
I'm sorry, but why not? "use strict";
module.exports = /*#__PURE__*/ (function() {
require("setimmediate");
return setImmediate;
}()); It's better to do a wrapper for the other properly working library, than misname People specially use this library to get In any case "setimmediate" library adds UPD. It should be OK: "use strict";
module.exports = typeof setImmediate === "function" ? setImmediate : require("./setImmediate-edited.js").setImmediate; But it requires to modify the original file a bit: Replace this: attachTo.setImmediate = setImmediate;
attachTo.clearImmediate = clearImmediate; with module.exports = {setImmediate, clearImmediate}; Optionally remove that (as a useless code): // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
attachTo = attachTo && attachTo.setTimeout ? attachTo : global; |
The description says that it is "Simple
setImmediate
module".And people use it (over 2kk installations). They think that it's simple and good one, but in fact it's simple and slow one. But there is no any note about it. A lot of people do not check the code of modules that they install, they expect that the creator spent time to investigate the problem to create the best decision, but it is not about this repo. The word "simple" is not the correct description, but "simple and naive", or "simple and slow" are.
Using this code in the browser leads to a performance hit. It's a fact. For some cases the impact is significant.
For example: Stuk/jszip#617
Here is the example of using of the properly created
setImmediate
:https://jphpsf.github.io/setImmediate-shim-demo/
296ms (
setImmediate
) vs 12617ms (setTimeout
=== your implementation)Node.js has
setImmediate
. Using your implementation in the browser is the same thing as usingsetTimeout
, but with the misleading name.The text was updated successfully, but these errors were encountered: