ndr: Use resizing array instead of linked lists (breaking ABI)
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 23 Feb 2017 22:58:33 +0000 (11:58 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 2 Mar 2017 07:38:21 +0000 (08:38 +0100)
commit70923b7521786d59b76e651d566bbd61fea024cc
tree135804f414227a9a69e36c9c6b7c7326c2a07a40
parent4bd8e63165e180565bda5dcf978ee0d38d3fa13d
ndr: Use resizing array instead of linked lists (breaking ABI)

The ndr token code keeps a temporary store of tokens which are
referred to a small number of times (often once) before being
discarded. The access patterns are somewhat stack-like, with recently
placed tokens being accessed most often.

The old code kept these tokens in a linked list, which we replace with
a self-resizing array.

This keeps everything roughly the same in big-O terms, but makes it
all faster in practice by vastly reducing the amount of tallocing and
pointer-chasing.

The peak memory use is strictly reduced. On a 64 bit machine each core
token struct fits in 16 bytes (after padding) while the two pointers
used by the DLIST add another 16 bytes, so the overall list allocation
is the same as the peak 2n array allocation -- except in the list case
it is dwarfed by the talloc and malloc metadata overhead.

Before settling on the resized arrays, we tried red-black trees, which
are bound to be better for large ndr structures. As it happens, we
don't deal with large structures (the size of replication clumps is
limited to 400 objects) and the asymptotic benefits of the trees are
not realised in practice.

With luck you should find graphs comparing the performance of these
various techniques at:

https://www.samba.org/~dbagnall/perf-tests/ndr-token/

This necessarily breaks the ABI because the linked list implementation
was publicly exposed.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Thu Mar  2 08:38:22 CET 2017 on sn-devel-144
librpc/ABI/ndr-0.1.0.sigs [new file with mode: 0644]
librpc/ndr/libndr.h
librpc/ndr/ndr.c
librpc/wscript_build