Speeding up array search after passing?

I have a large int array of 123 MB in size, and it is mainly used as follows:

 private static int[] data = new int[32487834]; static int eval(int[] c) { int p = data[c[0]]; p = data[p + c[1]]; p = data[p + c[2]]; p = data[p + c[3]]; p = data[p + c[4]]; p = data[p + c[5]]; return data[p + c[6]]; } 

eval() is called a lot (~ 50B times) with different c , and I would like to know if (and how) could speed it up.

I already use an insecure function with a fixed array that uses all processors. This is a C # port appraiser of RayW's TwoPlusTwo 7 maps . The C ++ version is slightly faster.

Can a GPU be used to speed this up?

+8
performance c # gpu lookup
source share
1 answer
  • The cache of the array reference to a local variable. Access to static fields is usually slower than local ones for several reasons (one of them is that the field can change, so it needs to be reloaded all the time). JIT can optimize locals much more freely).
  • Do not use an array as an argument to a method. Difficult code 7 integer indices. This reduces the allocation of arrays, checking the direction and constraints on the binding.
  • Use unsafe code to index into an array. This will eliminate the border check. Use GCHandle to fix the array and cache the pointer in a static field (not just use a fixed block). I believe that it has certain (small) overhead associated with entering it. Not sure).
  • As an alternative to fixing the array, allocate a 123 MB array using VirtualAlloc and use huge pages. This reduces TLB omissions.

These are all hardcore low-level optimizations. They apply only in case of maximum performance.

I think we're pretty much at the limit here when it comes to optimizing this feature. We can probably be better off if you show the caller so that they can be optimized as a whole.

+2
source share

All Articles