Commit 0f6d854a authored by Rusty Russell's avatar Rusty Russell

tal: simplify.

All the effort trying to keep the header size down to 2 pointers turns
out to be wasted.  In addition, getting the parent of a tal pointer is
now much faster.

./samba-allocs talloc.dump --tal-size:
Before:
	Virtual size = 9633792, RSS = 3952640
After:
	Virtual size = 9793536, RSS = 3948544

And we're much faster now, esp. on free.

./samba-allocs talloc.dump --tal:
Before:
	Tal time:                2718068ns
	Tal_free time:           3360258ns
	Single tal_free time:    1667412ns
After:
	Tal time:                2788287ns
	Tal_free time:           2290167ns
	Single tal_free time:    1566998ns
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>


Header from folded patch 'tal-fix-set-destroying-bit.patch':

tal: fix destroying bit usage.

Actually looking at a destroying contexts' parent didn't work, and a couple
of places didn't filter out the destroying bit.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 932d65dd
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
* tal_free(X->name) would free X->name as expected, by tal_free(X) would * tal_free(X->name) would free X->name as expected, by tal_free(X) would
* free X and X->name. * free X and X->name.
* *
* With an overhead of approximately 2.1 pointers per object (vs. talloc's * With an overhead of approximately 4 pointers per object
* 12 pointers), it's a little slower in freeing single objects, though * (vs. talloc's 12 pointers), it uses dynamic allocation for
* comparable for allocation and freeing whole object trees). It does not * destructors and child lists, so those operations can fail. It does
* support talloc's references or failing destructors. * not support talloc's references or failing destructors.
* *
* Example: * Example:
* #include <stdio.h> * #include <stdio.h>
...@@ -92,7 +92,6 @@ int main(int argc, char *argv[]) ...@@ -92,7 +92,6 @@ int main(int argc, char *argv[])
if (strcmp(argv[1], "depends") == 0) { if (strcmp(argv[1], "depends") == 0) {
printf("ccan/compiler\n"); printf("ccan/compiler\n");
printf("ccan/hash\n");
printf("ccan/likely\n"); printf("ccan/likely\n");
printf("ccan/list\n"); printf("ccan/list\n");
printf("ccan/str\n"); printf("ccan/str\n");
......
...@@ -6,8 +6,8 @@ LDLIBS=-lrt ...@@ -6,8 +6,8 @@ LDLIBS=-lrt
all: speed samba-allocs all: speed samba-allocs
speed: speed.o tal.o talloc.o time.o hash.o list.o take.o speed: speed.o tal.o talloc.o time.o list.o take.o
samba-allocs: samba-allocs.o tal.o talloc.o time.o hash.o list.o take.o samba-allocs: samba-allocs.o tal.o talloc.o time.o list.o take.o
tal.o: ../tal.c tal.o: ../tal.c
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
...@@ -15,8 +15,6 @@ talloc.o: ../../talloc/talloc.c ...@@ -15,8 +15,6 @@ talloc.o: ../../talloc/talloc.c
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
time.o: ../../time/time.c time.o: ../../time/time.c
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
hash.o: ../../hash/hash.c
$(CC) $(CFLAGS) -c -o $@ $<
list.o: ../../list/list.c list.o: ../../list/list.c
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
take.o: ../../take/take.c take.o: ../../take/take.c
......
This diff is collapsed.
...@@ -40,7 +40,6 @@ int main(void) ...@@ -40,7 +40,6 @@ int main(void)
strcpy(c[0], "hello"); strcpy(c[0], "hello");
tal_free(c[0]); tal_free(c[0]);
ok1(tal_first(parent) == NULL); ok1(tal_first(parent) == NULL);
tal_free(parent); tal_free(parent);
return exit_status(); return exit_status();
......
...@@ -6,21 +6,14 @@ ...@@ -6,21 +6,14 @@
int main(void) int main(void)
{ {
char *p[NUM], *iter; char *p[NUM] = { NULL }, *iter;
int i; int i;
plan_tests(NUM + 1 + NUM); plan_tests(NUM + 1 + NUM);
/* Create a random tree, but make sure we get multiple /* Create a random tree */
* top-level groups! */
for (i = 0; i < NUM; i++) { for (i = 0; i < NUM; i++) {
p[i] = tal(NULL, char); p[i] = tal(p[rand() % (i + 1)], char);
*p[i] = '0';
if (next_group(&null_parent.c.group) != &null_parent.c.group)
break;
}
for (i++; i < NUM; i++) {
p[i] = tal(p[rand() % i], char);
*p[i] = '0'; *p[i] = '0';
} }
......
...@@ -9,7 +9,7 @@ int main(void) ...@@ -9,7 +9,7 @@ int main(void)
plan_tests(9); plan_tests(9);
p[0] = NULL; p[0] = tal(NULL, char);
for (i = 1; i < 5; i++) for (i = 1; i < 5; i++)
p[i] = tal(p[i-1], char); p[i] = tal(p[i-1], char);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment