Here
http://www.postgresql.org/message-id/24278.1352922571@sss.pgh.pa.us there was some talk about init_sequence being a bottleneck when many sequences are used in a single backend.
The attached I think implements what was talked about in the above link which for me seems to double the speed of a currval() loop over 30000 sequences. It goes from about 7 seconds to 3.5 on my laptop.
I thought I would post the patch early to see if this is actually wanted before I do too much more work on it.
My implementation maintains using the linear list for sequences up to a defined threshold (currently 32) then it moves everything over to a hashtable and free's off the list.
A more complete solution would contain regression tests to exercise the hash table code.
I know there is a desire to move sequences over to a single table still, but I see this as a separate patch and storing current values in a hash table for each backend should still be a win even if/when the single table stuff gets implemented.
Regards
David Rowley