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

**URL:** <https://discourse.julialang.org/t/help-needed-for-improving-the-performance-of-a-simple-table-lookup-function-hashing-in-a-chess-engine/88590>\
**Category:** New to Julia\
**Created:** [October 11, 2022, 6:16pm UTC](https://discourse.julialang.org/t/help-needed-for-improving-the-performance-of-a-simple-table-lookup-function-hashing-in-a-chess-engine/88590 "2022-10-11T18:16:01Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 12, 2022, 12:09pm UTC](https://discourse.julialang.org/t/help-needed-for-improving-the-performance-of-a-simple-table-lookup-function-hashing-in-a-chess-engine/88590/21 "2022-10-12T12:09:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fins/32/43444_2.png) [@fins](https://discourse.julialang.org/u/fins)\
**Post date:** [October 12, 2022, 12:33pm UTC](https://discourse.julialang.org/t/help-needed-for-improving-the-performance-of-a-simple-table-lookup-function-hashing-in-a-chess-engine/88590/22 "2022-10-12T12:33:43Z")

</div>

> 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. 😅

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](https://en.wikipedia.org/wiki/Perfect_hash_function#Minimal_perfect_hash_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). 🤔

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). 😅

---

<div class="post-metadata">

**Author:** ![fins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fins/32/43444_2.png) [@fins](https://discourse.julialang.org/u/fins)\
**Post date:** [October 12, 2022, 12:47pm UTC](https://discourse.julialang.org/t/help-needed-for-improving-the-performance-of-a-simple-table-lookup-function-hashing-in-a-chess-engine/88590/23 "2022-10-12T12:47:39Z")

</div>

> 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.

[Previous page](https://discourse.julialang.org/t/help-needed-for-improving-the-performance-of-a-simple-table-lookup-function-hashing-in-a-chess-engine/88590.md?page=1)
