postgres icon indicating copy to clipboard operation
postgres copied to clipboard

Micro-optimizate memory usage in CatCacheCopyKeys

Open tristan957 opened this issue 2 years ago • 3 comments

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

tristan957 avatar May 30 '23 19:05 tristan957

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.

tristan957 avatar May 30 '23 22:05 tristan957

It seems like using enums might test this code out, not sure though.

tristan957 avatar May 30 '23 22:05 tristan957

Status: nice side project which might yield an upstream patch.

Needs more tests, numbers, and the actual patch.

andreasscherbaum avatar Apr 24 '24 16:04 andreasscherbaum