mixite icon indicating copy to clipboard operation
mixite copied to clipboard

Just an idea: Api is very restricted and so it cause a lot performance problem

Open vilinet opened this issue 3 years ago • 1 comments

I see this code base were left behind but i still want to raise this issue, maybe if someone has issue with performance can learn from it.

Would be great functions for be able to avoid creating a Hexagon and using instead CubeCoordinate would improve performance drasticly.

For example one of the mostly used function is the getNeighboursOf.

Firstly i am ok with the current one if you really need the list of hexagon neighbours. I am writing about the cases when you do not need the hexagon(the most cases as they likely wont change position once they are created, if they move you just change the projection and so theri coordinate wont be affected)

So here are my results with using only CubeCoord:

getNeighboursOf on 100x100 grid(sure the grid size does not matter for neighbours, only maybe for looking up time in the storage)

Using hexagons: Avg Duration: 2.991 seconds

Using CubeCoord only: Avg Duration: 0.139 seconds

So roughly 20x improvent and so it could be improved even further beyond. It also uses the user's collection to avoid object creation, it is nice and much more fitting for a game.

The code: override fun getNeighborsOf(coordinate: CubeCoordinate, outputCollection: HashSet<CubeCoordinate>) { for (i in NEIGHBORS.indices) { val cube = getNeighborCoordinateByIndex(coordinate, i) if(hexagonDataStorage.containsCoordinate(cube)){ outputCollection.add(cube) } } }

Test: long start = System.currentTimeMillis();

    for(int i=0; i<1000000; i++) {
        arr.clear();
        grid.getNeighborsOf(hexagons[18].getCubeCoordinate(), arr);
    }

    long end = System.currentTimeMillis();

vilinet avatar Aug 08 '20 16:08 vilinet

Hi @vilinet . The project is not left behind, it is just considered more or less complete apart from some graph algorithms. For those we're going to work on a more abstract graph library that can be used with Mixite.

Can you elaborate a bit on the performance bottleneck? What is your use case? What are you trying to achieve? Maybe there is a simple solution already present in the library.

adam-arold avatar Aug 13 '20 09:08 adam-arold