by PessimalDecimal · 1y ago · 0 comments
The explanation drifts into thinking of 2D byte arrays as 3D bit matrices, but in the end it was a 20-30x improvement in speed and binary size.
I was honestly surprised that C++ doesn't have anything built in for this, but at least it's trivial to write your own array type
At the same time, I don't completely understand how such a pivot would result in a speedup for random access. I suppose it would speed up sequential access, since the multiple array storage scheme might force many more cache line updates.
In the extreme case where all memory accesses of a immensely massively parallel program are deferred, the result is complete absence of cache misses [1].
[1] https://disneyanimation.com/technology/hyperion/
While our programs usually not ran at Hyperion scale, they still can benefit from accesses shared between processing of several requests.For one such example, consider speech recognition with the HCLG graph. That graph is created through composition of four WFST [2] graphs, the last one is Grammar, derived from SRILM n-gram language model. This HCLG graph has scale free property [3] due to all G FST states has to backoff to the order-0 model, and some states are visited exponentially often than others.
[2] https://en.wikipedia.org/wiki/Finite-state_transducer#Weighted_automata
[3] https://en.wikipedia.org/wiki/Scale-free_network
By sorting HCLG graph states by their fan-ins (number of states referring to a particular one), we sped recognition process up 5%. E.g., most referred state gets index 0, second most referred is 1, etc, and that's it.No code change, just preprocessing step that, I believe, lessen the pressure on the CPU's memory protection subsystem.
The speech recognition process with HCLG graph uses beam search [4], there are several (9-20) hundredths of states in the beam front to be evaluated. Most of them have outgoing arc to some of the most visited (fan-in) states. By having these states close to each other we incur less page faults exception handling during processing.
[4] https://en.wikipedia.org/wiki/Beam_search
Basically, we shared more MMU information between requests in beam front.PS
Fun fact: WFST created by OpenFST has "structure of arrays" layout. ;)
Perhaps someone can write similar logic in D programming and showcase how much more intuitive the programming will be since Dlang has first class arrays and its metaprogramming facility is second to none [1].
[1] D (programming language):