Micro-optimizate memory usage in CatCacheCopyKeys
CatCacheCopyKeys has this:
/*
* XXX: memory and lookup performance could possibly be improved by
* storing all keys in one allocation.
*/
That seems like a good idea. We'd like to reduce backend memory usage. This is a very small part of it, but it's also a very localized change.
Also, this function often deals with the 'name' type. 'name' is a fixed-width type, 64 bytes wide (NAMEDATALEN to be precise). However, it's always null-terminated, and the functions in catcache.c like nameeqfast and namehashfast treat it as a C string. So we don't really need to alloc and copy the whole 64 bytes, we could call strlen() here and leave out the trailing zeros.
Tasks:
- Create a test case that shows the benefit. Something that creates a lot of catcache entries, and measure the memory usage.
- Do the above optimizations
I believe I have the optimization for the string case done. Being unfamiliar with this portion of code, I don't necessarily understand how best to test it.
It seems like using enums might test this code out, not sure though.
Status: nice side project which might yield an upstream patch.
Needs more tests, numbers, and the actual patch.