noHero123 / silverfish

rewrote uai
63 stars 87 forks source link

Playfield constructor performance #2

Open ChristophWeigert opened 10 years ago

ChristophWeigert commented 10 years ago

he biggest performance issue is the Playfield constructor. dont know if i can change this with adding something like preallocating 5000 (or so) boards, and just override the existing old/unused playfields in the posmoves-List. (like: int i = getNextFreeSpace(posmoves); posmoves[i].deepCopy(p); posmoves[i].doAction(a);

instead of

Playfield pf = new Playfield(p); pf.doAction(a); )

ChristophWeigert commented 10 years ago

Changed all foreach loops to for loops.

Should be a little performance boost. Can you try this commit?

https://github.com/Giswald/silverfish/commit/76b8c5fea4e6bf5266f43f0c1930b5e4be03e0be

dfreelan commented 10 years ago

I have used a profiler before on this code, and I can verify the constructor is a huge part of it.

To confirm your hypothesis further, if I disable to time it takes to do memory allocation from the profiler, the ctor is no longer the limiting factor. Rather the board evaluation.

So I think you are exactly correct, and the boards should be preallocated. However, modifying the AI structure written is probably easier said than done.

As soon as I feel comfortable where I am in school i'll have my own AI to work on where i'll likely do exactly that :)

( i probably won't touch the existing ai though)

dfreelan commented 10 years ago

oh and another note, iterator seemed only to be a performance block when memory allocation was not accounted for.

So I think you won't notice much of a difference until you get rid of the real bottle neck, playfield ctor

dfreelan commented 10 years ago

ALSO: sorry i keep writing things you probably keep getting emails.

when doing performance, make sure it's still correct by comparing a before and after of the board result. I wrote something as a benchmark in the other repo botmaker and I were using.... we should pull that over here

noHero123 commented 9 years ago

@Giswald added you to https://github.com/noHero123/consoleversion