You never can tell

In my first experiences of making an ABM, I’ve been surprised by how slowly a seemingly simple Java program can run. This led me to look at how to profile a running Java application to see where it’s spending most of its time.

Oracle’s frankly-amazing Java VisualVM allows you to do just that and the results, in my case, were highly unexpected.

Despite running an ABM with, as I thought, fairly high levels of structural complexity (i.e. agents all have their own worldview, including little imaginary copies of all the other agents they know about, which get updated as and when an indenpendent and omniscient ‘GamesMaster’ allows), the program turned out to be spending the vast, vast majority of its time working out which spaces are neighbours to which others. This is clearly absurd and now I’m off to tweak the algorithm. A faster model should result…

First ever profiler output

Profiler output showing huge overheads in checking neighbouring spaces