Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vilinet opened this issue Aug 8, 2020 · 1 comment

Comments

@vilinet
Copy link

vilinet commented Aug 8, 2020

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) {
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();
@adam-arold
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants