NetLogo / Tortoise

Compiler and runtime engine for NetLogo models that runs in JavaScript 🐢
https://netlogoweb.org
Other
56 stars 27 forks source link

STOP: an expensive primitive in NLW #216

Closed CIVITAS-John closed 3 years ago

CIVITAS-John commented 4 years ago

Hi all,

I wonder the rationale behind the current implementation of STOP in NetLogo - if we are throwing, catching, and returning StopInterrupts, why should we do throwing and catching after all? It is much more expensive than simply returning a constant of a StopInterrupt object, both in CPU time and in memory consumption. On my model, it took 7% of the whole overhead and is the single largest overhead in the bottom-up view of Chrome's profiler.

It also leads to a further paradox when designing models:

Whenever you are using TO, if you want to use STOP and keep performance intact, you have to use TO-REPORT. Yet semantically, NetLogo does not allow calling a TO-REPORT without making use of the result (which is also a bit unintuitive to me, yet acceptable).

Yes, STOPs are preventable by restructuring the code in a certain way. Yet I wonder if there is a way we can improve it.

Thanks!

Best, John Chen

LaCuneta commented 3 years ago

This was done as part of this commit.