NetLogo/Galapagos — pull request #113 by qiemem (2014-01-09 17:45:28+00:00)
Title: Optimize AgentModel.update for V8

V8 wasn't optimizing the forIn loops in AgentModel.update. This replaces those forIns with regular for loops over Object.keys. The bodies of the loops have been moved to (inlineable) functions, which I think further allows optimization. Percent of total time for AgentModel.update decreased from 15% to 10% on climate change (with a bunch of CO2) on my machine, using latest Chrome Canary.

Note that I think this is a bad optimization in general. Object.keys is often slower than forIns. This is just a special case.

Also, Chrome still complains about forIns in AgentModel.update, but there aren't any left... not sure what that's about.

Note: A javascript forIn is equal to a coffeescript `for ... of ...` construct. Coffeescript's `for ... in ...` is compiled to a regular for loop.