liblcf icon indicating copy to clipboard operation
liblcf copied to clipboard

Use small_vector<T,N> for EventCommand::parameters

Open mateofio opened this issue 7 years ago • 1 comments

EventCommands are pervasive and take up a good portion of total memory usage. Event commands have a dynamic list of parameters but most of them use few (< 10?) parameters. Many commands have a fixed size number of parameters. small_vector<T,N> is perfectly suited for this situation.

  1. Survery a bunch of games to find a good value for N.
  2. Write or import a small_vector implementation into liblcf.
  3. Change EventCommand::parameters and others if it makes sense.

Using small_vector will greatly improve cache locality when interpreting event streams. This should result in higher performance in Player.

It'll also result in dramatically fewer memory allocations, resulting in measurably higher lcf reading performance. Less allocations also means less memory overhead, which should slightly reduce memory usage of liblcf.

Small vector has the same interface as vector, so it can be an easy drop-in replacement.

Some example implementations are here:

  • https://github.com/facebook/folly/blob/master/folly/docs/small_vector.md
  • http://llvm.org/doxygen/SmallVector_8h_source.html

mateofio avatar Oct 05 '18 00:10 mateofio

iirc the only "long" commands are Show/Move Picture, Inn (item list) and Move event (the whole move route), we could parse through all games in our test set and calculate statistics about the parameter length to get the optimal result.

Ghabry avatar Oct 30 '18 09:10 Ghabry