ccan/tal: always include a length field.
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 27 Jul 2018 04:29:18 +0000 (13:59 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 27 Jul 2018 04:29:18 +0000 (13:59 +0930)
commit1651e25ee7cf7a24692e7ffa0c6fc9a47218eb6d
tree3e6c6c5c6c5a18476556c0949a9530675c34f35f
parent38ec541c4fd76d971a4959e31cd2a9ff113237ca
ccan/tal: always include a length field.

The current semantics of tal_count() / tal_bytelen() are to return 0
for anything not allocated using tal_arr*.  This is because we tried
to save a native-length word in the header, but produces an awkward
API.

(To make it worse, defining CCAN_TAL_DEBUG turns length to always on,
and we enable that for c-lightning developer mode, which hides bugs!).

However, for c-lightning, just over half of allocations want a length:
these use 3 words each, so we're actually worse off overall.

The answer is to always have a length field in the header.  This also
simplfies the tal code.

samba-allocs stats before:
Tal time: 1237102-1305755(1.251e+06+/-2.1e+04)ns
Tal_free time: 1346871-1514514(1.37844e+06+/-5.2e+04)ns

After:
Tal time: 1115180-1180633(1.1351e+06+/-2.1e+04)ns
Tal_free time: 1334381-1465933(1.39148e+06+/-4.7e+04)ns

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/tal/benchmark/samba-allocs.c
ccan/tal/tal.c
ccan/tal/tal.h
ccan/tal/test/run-count.c