f846ec41eb
Traditionally the hcreate() function creates a hash table that uses chaining, using a fixed user-provided size. The problem with this approach is that this often either wastes memory (table too big) or yields bad performance (table too small). For applications it may not always be easy to estimate the right hash table size. A fixed number only increases performance compared to a linked list by a constant factor. This problem can be solved easily by dynamically resizing the hash table. If the size of the hash table is at least doubled, this has no negative on the running time complexity. If a dynamically sized hash table is used, we can also switch to using open addressing instead of chaining, which has the advantage of just using a single allocation for the entire table, instead of allocating many small objects. Finally, a problem with the existing implementation is that its deterministic algorithm for hashing makes it possible to come up with fixed patterns to trigger an excessive number of collisions. We can easily solve this by using FNV-1a as a hashing algorithm in combination with a randomly generated offset basis. Measurements have shown that this implementation is about 20-25% faster than the existing implementation (even if the existing implementation is given an excessive number of buckets). Though it allocates more memory through malloc() than the old implementation (between 4-8 pointers per used entry instead of 3), process memory use is similar to the old implementation as if the estimated size was underestimated by a factor 10. This is due to the fact that malloc() needs to perform less bookkeeping. Reviewed by: jilles, pfg Obtained from: https://github.com/NuxiNL/cloudlibc Differential Revision: https://reviews.freebsd.org/D4644 |
||
---|---|---|
.. | ||
jemalloc | ||
_Exit.c | ||
a64l.3 | ||
a64l.c | ||
abort.3 | ||
abort.c | ||
abs.3 | ||
abs.c | ||
alloca.3 | ||
at_quick_exit.3 | ||
atexit.3 | ||
atexit.c | ||
atexit.h | ||
atof.3 | ||
atof.c | ||
atoi.3 | ||
atoi.c | ||
atol.3 | ||
atol.c | ||
atoll.c | ||
bsearch_b.c | ||
bsearch.3 | ||
bsearch.c | ||
div.3 | ||
div.c | ||
exit.3 | ||
exit.c | ||
getenv.3 | ||
getenv.c | ||
getopt_long.3 | ||
getopt_long.c | ||
getopt.3 | ||
getopt.c | ||
getsubopt.3 | ||
getsubopt.c | ||
hcreate_r.c | ||
hcreate.3 | ||
hcreate.c | ||
hdestroy_r.c | ||
heapsort_b.c | ||
heapsort.c | ||
hsearch_r.c | ||
hsearch.h | ||
imaxabs.3 | ||
imaxabs.c | ||
imaxdiv.3 | ||
imaxdiv.c | ||
insque.3 | ||
insque.c | ||
l64a.c | ||
labs.3 | ||
labs.c | ||
ldiv.3 | ||
ldiv.c | ||
llabs.3 | ||
llabs.c | ||
lldiv.3 | ||
lldiv.c | ||
lsearch.3 | ||
lsearch.c | ||
Makefile.inc | ||
memory.3 | ||
merge.c | ||
mergesort_b.c | ||
ptsname.3 | ||
ptsname.c | ||
qsort_r.c | ||
qsort.3 | ||
qsort.c | ||
quick_exit.3 | ||
quick_exit.c | ||
radixsort.3 | ||
radixsort.c | ||
rand.3 | ||
rand.c | ||
random.3 | ||
random.c | ||
reallocarray.3 | ||
reallocarray.c | ||
reallocf.3 | ||
reallocf.c | ||
realpath.3 | ||
realpath.c | ||
remque.c | ||
strfmon.3 | ||
strfmon.c | ||
strtod.3 | ||
strtoimax.c | ||
strtol.3 | ||
strtol.c | ||
strtoll.c | ||
strtonum.3 | ||
strtonum.c | ||
strtoq.c | ||
strtoul.3 | ||
strtoul.c | ||
strtoull.c | ||
strtoumax.c | ||
strtouq.c | ||
Symbol.map | ||
system.3 | ||
system.c | ||
tdelete.c | ||
tfind.c | ||
tsearch_path.h | ||
tsearch.3 | ||
tsearch.c | ||
twalk.c |