Reproduce
- Use the Java hamster-simulator
- Save the attached territory on the file system
- Execute a hamster-program, which loads this territory
loadTerritoryFromResourceFile("de.unistuttgart.hamster.territories/territory50x50.ter");
Symptom: The initialization of the territory is slow, it takes a few seconds.
Assumption: With bigger territories, the time increases quadratically.
Reason
The editor commands like addWallToTile
are generated with a graph pattern matching, which makes no used of efficient Tile search.
In the sample territory, nearly for each tile one wall is placed. This leads to a quadratic algorithm, since for each tile, each other tile has to be searched in the worst case, until the tile with a given location is found.
Solution Proposal
For the two-dimensional tile collection, an indexed access in the generated code should fix the performance issue. An idea could be to determine that a Tile
object shall be matched by a x
and y
coordinate in the QVTo logic.
Then a special ReferenceCondition
will be inserted, which is generated as a special getter call on the underlying Stage.
Also, the Stage
class itself has to be extended with a special indexed-based getter for obtaining Tile
objects.