Saturday, December 31, 2011

Tweaking performance of Rescape

As I attempt to make an official beta release of Rescape, I've been struggling mightily with getting the software to work under the Windows version of Sketchup because it's harder to work with external libraries than it is on OS X. I've also had performance problems under both versions of the software, so I decided to farm out some of the processing work to external processes because Sketchup doesn't handling running multiple threads very well, meaning that the user is blocked from doing anything while other processing is going on. You can think of a thread as running something like a timer that springs up in your application after 30 seconds while you're doing other things, whereas an external process is running a wholly different program outside of Sketchup. I opted to launch an external process that processes all the shortest path between ways, so that a complex street map like this will be processed while the user stares at the map and plays around with the Rescape tools:

With all the paths processed in the background, by the time the user is ready to draw surfaces on the map, the shortest paths will likely already be calculated. Thus when the user moves the cursor from one street to another, the shortest path along the streets will already be calculated, allowing the path to draw quickly:
Previously I would get the spinning beach ball on the Mac for upwards of ten seconds as Rescape tried to calculate this shortest path, because it had to process potentially hundreds of other possible paths to find the shortest one. (Shortest path solving is an infamously hard problem in computing, because the magnitude of operations required can reach the cube of the number of path segments, so 100 path segments can on the order of 1,000,000 operations.)

Since laying out components along the street is the main thing Rescape does, it's essential that it be as speedy as possible. The goal is to be able to lay out a lot of things quickly, and make models like this that require tracks, vehicles, buildings, bollards, etc to be laid out along the road:

No comments: