Bug in talloc_asprintf_append()

tridge at samba.org tridge at samba.org
Fri Sep 14 22:22:11 GMT 2007


Jeremy,

 > Do you have existing uses of talloc_asprintf_append()
 > that depend on no strlen calls ? Where are they ?

This function came from Samba4, and we depend on the no strlen
behaviour in several places there.

The reason it matters is that talloc_asprintf_append() was originally
added for use in places where we build up strings in a loop. For
example, its used to construct ldap entries and the schema. These
strings can be very large. With a strlen() call the time was O(n^2) in
the length of the string, whereas without the strlen() the time is
O(n) in the length of the string. That made a huge difference as n is
sometimes many thousands. At one stage this was the top of the list in
many profiles.

I don't mind it being renamed, as long as we have the original
functionality available somewhere.

This will also affect the performance of Samba3 to some extent. See
for example the msdfs.c code (where its used in a loop), the
pdb_ldap.c code (another loop) net_conf.c (yet, another loop).

In fact, it looks like using talloc_asprintf_append() in a loop to
build a string is more common in Samba3 than using it as a one-off. So
by adding that strlen() you are potentially adding quite a high cost
to those loops. The average loop count is probably quite low in most
of the places in Samba3, but its still an awful lots of CPU cycles
wasted.

So at the very least all those functions that use it in a loop should
be changed to use the varient that doesn't do the strlen(). This is a
case where talloc wins us a lot of cycles by knowing the length of a
piece of allocated memory, I don't think we should throw that away.

Cheers, Tridge


More information about the samba-technical mailing list