-
Notifications
You must be signed in to change notification settings - Fork 26
Implementing a Desktop Compiler Optimization
Jeremy B edited this page Feb 22, 2018
·
15 revisions
We have an existing ticket to implement the desktop compiler's optimizations in Tortoise. This is a brief overview on the process to follow to implement one of them.
For reference, a few example optimizations that have been done already and can be used as reference include "Nsums", "Nsums4", and "OtherWith".
- Make sure to understand what you're testing in NetLogo code. A lot of these optimizations take combinations of primitives that can be more efficient when they're processed together.
- Like
any? turtles with [ color = red ]would normally runturtles with [ color = red ]creating an agent set of red turtles followed by anany?check on that result, but they can be combined to save some time by reportingtruewhen the first turtlewiththe condition is found.
- Like
- Create a simple language test for it in
Tortoise.txtin Tortoise so you can quickly test it usingnetLogoWeb/testOnly *Commands -- -z Tortoiseusing thesbtconsole.- This is just a fast, easy-to-run test for implementation purposes, it shouldn't be checked in with any commits.
- Add the optimization in the proper
DockingFixtures.scalasection (Command or Reporter), matched against theNetLogorepoOptimizations.scala, so it'll be used in all other tests, too. - Find the optimized prim version in the NetLogo repository. This will be the logic we'd like to duplicate.
- Example: The
_anywithclass in_anywith.scala. But make sure to look at the version fromheadlessand notnetlogo-gui.
- Example: The
- In Tortoise, add the matching prim in
Prims.scala.- This is where the compiled prim is translated into the CoffeeScript code that will actually be run by the engine.
- In Tortoise, add the optimized code in the appropriate place in the engine, depending on the prim and optimization.
- For
_anywith, this applies to agent sets, so we'd look to an agent set class to implement it.
- For
- Run tests, work on it until it passes.
- Run a broader set of tests (
netLogoWeb/test:fastandnetLogoWeb/test *Reportersare good ones), make sure they all still pass. - Publish the Tortoise artifacts locally and use them in Galapagos to test a model using the now optimized primitives. You should be able to use a web developer console to actually step through your optimized code.
* means already implemented.
- AnyOther*
- AnyOtherWith
- AnyWith1
- AnyWith2
- AnyWith3
- AnyWith4
- AnyWith5
- CountOther*
- CountOtherWith
- CountWith*
- Nsum*
- Nsum4*
- OneOfWith*
- OtherWith*
- PatchAt
- RandomConst
- With*
- WithOther*