Skip to content
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

Reduce nextTick calls to prevent nextTick throttling #41

Closed
wants to merge 1 commit into from
Closed

Reduce nextTick calls to prevent nextTick throttling #41

wants to merge 1 commit into from

Conversation

Tschuck
Copy link

@Tschuck Tschuck commented May 9, 2018

With frequently called nextTick functions, it may be possible that the browser throttles the calls and the callback is only called after a long time. This delays the application. The pull request should reduce the number of nextTick calls and counteract this behavior.

View eth-lightwallet issue for a more detailed problem description.

@dchest
Copy link
Owner

dchest commented May 9, 2018

Interesting. But why not use interruptStep for throttling?

interruptStep — (optional) the amount of loop cycles to execute before the next setImmediate/setTimeout (defaults to 0)

@Tschuck
Copy link
Author

Tschuck commented May 9, 2018

It's not a problem with the blocking of the browser, so we need to throttle the calculation. The problem is, that the throttling using nextTick will stop the browser responding to the nextTick call. Our current value of interruptStep is set to 200.

So i think its not a problem with setTimeout / setImmediate, but with the nextTick. Each run of the calculateAsync function, runs the nextTick function 3 times. After a huge amount of nextTick, the browser will throttle the nextTick requests of the application.

Or did i misinterpret something?

@dchest
Copy link
Owner

dchest commented May 9, 2018

I think what causes this is that browsers throttle setTimeout (which is what nextTick is, unless the browser implements setImmediate). Initially setTimeout responds quickly, but if fired too much too quickly, perhaps it's throttled? Do you use a setImmediate shim, such as https://github.com/YuzuJS/setImmediate? If not, can you try reproducing with it? If yes, can you try reproducing without it? :)

@dchest
Copy link
Owner

dchest commented May 9, 2018

BTW, what are other parameters (I think 200 for interruptStep is too small, so it causes a lot of nextTick very quickly)?

@Tschuck
Copy link
Author

Tschuck commented May 15, 2018

I missed the prefill of nextTick and setTimeout, i was a little confused...^^

Thanks for the interruptStep tip. I tried some tests with higher values from 1000 - 2000 and ended up with 10 - 20 setTimeouts, so everything seems to work as expected.

I will remove the pull request and make the changes to the lightwallet library.

Thanks for your support and sorry for the confusion :)

@Tschuck Tschuck closed this May 15, 2018
@dchest
Copy link
Owner

dchest commented May 15, 2018

Awesome, thanks for figuring it out and posting here!

BTW, I also have a separate project with scrypt that automatically adjusts the time for next async:

https://www.stablelib.com/modules/_scrypt_scrypt_.html (see deriveKeyNonBlocking)
(source: https://github.com/StableLib/stablelib/tree/master/packages/scrypt)

npm install @stablelib/scrypt

Maybe it will work well for such situations.

@Tschuck
Copy link
Author

Tschuck commented May 15, 2018

A automatic calculation would be awesome. Sadly I am a bit limited in my time for testing this at the moment.

I have made a pull request in the eth-lightwallet library. I'll put in the alternative as a hint for a improvement.

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants