Open ToonTalk opened 10 years ago
I googled for a bit, but it does not seem directly clear to me how setTimeout would affect browser timeouts? Could you maybe point me to some description of this, or create a demo model which shows how it could?
It seems that a zero timeout has a 4 millisecond overhead these days. https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers.setTimeout#Notes
The same page refers to a way to get a zero timeout: http://dbaron.org/log/20100309-faster-timeouts
But even with a zero timeout it often requires the code to be rewritten.
For example the implementation of @agents.create might need to repeat
repeated until the desired number of agents are created.
Step is even more of a problem to break up especially since it is user-defined.
If there was a way to implement "for agent in @agents ..." such that it does 1000 agents and then timeout until all agents have run that might be a solution. But the body of the for loop might be quick or not, so not clear how many to do at once.
Perhaps this problem is just too hard to fix given the other constraints.
Possibly workers is another solution where the model (but not the animation or interface) is in a web worker: https://developer.mozilla.org/en/docs/Web/Guide/Performance/Using_web_workers
Thanks for giving some more background. It indeed seems to be a relatively hard problem to fix.
This, plus the fact that that:
...makes this a low priority issue for now.
When I edit the Template Model to have 25000 agents it took over a minute to start and during that time the browser tab was unresponsive. (5000 agents was OK.) I got a couple browser messages asking if I wanted to kill the process.
I think appropriate use of setTimeout with a second argument of 0 milliseconds could resolve this by letting the browser get some cycles sometimes.