Help needed for improving the performance of a simple table-lookup-function (~hashing) in a chess-engine

this won’t be relevant for him for a bit. a lot of indexing in chess is with magic numbers they relate to bit boards. the compiler will never figure those out on it’s own.

Unless I missed it, I don’t think you shared code where you access array elements.

The whole thread is literally only about optimizing the access to array (-like) -datastructures and the initialization of those structures. :sweat_smile:

But I can see, how that might not correlate much with everyone’s expected pattern of accessing array-structures. I’m just not iterating over them in any regular manner, like some stride, etc. Rather my arrays are basically look-up-tables, where individual elements are accessed in a non-predictable pattern.
Ofc, it is not really unpredictable, but in this particular case, the prediction would involve mimicking a significant portion of the chess-engine, to predict, which move(s) will be explored, next.

Just think of the arrays as hashtables (the access to HASHT_SLIDE_ROOK can actually be understood in terms of implementing a minimal perfect hashing function, in this case).

But your point about being careful with accessing arrays, especially in the context of @inbound - fiddling is still much appreciated. I’ve adopted the i in eachindex(array)-variant, as in my engine, the index-values are usually needed, since they encode some kind of semantics and are not just meaningless enumerations.

I still have to get used to the start-index=1, in julia, though.

It is one (small!) detail, I really dislike, since so many techniques in computer-science are rooted in bit-representations of integers (and are based on bit-manipulation), which simply start at 0 or where 0 is even the natural terminal state, of some finite-state-machine, which is based solely on bit-operations. Starting at 1 for indexing arrays forces me to add a constant ‘+1’ literally every single time, I’m doing bit-fiddling to access indexed-datastructures (like in this thread). :thinking:

I love the “rest” of the syntax, though, and gladly live with the 1-based arrays, for now - being aware, that there are alternative packages, which I might explore at a later time, also aware, that those might have side-effects, possibly related to how I implement my iterations of arrays (the topic you posted about). :sweat_smile:

this won’t be relevant for him for a bit. a lot of indexing in chess is with magic numbers they relate to bit boards. the compiler will never figure those out on it’s own.

Well, I stil have “regular” iterations over arrays, not just for initializations of those and have used eachindex(), exclusively, to limit code refactoring, in case I might switch to 0-based-structures.

1 Like