This commit optimizes in three ways:
1. For heavily used functions, allocate memory to avoid overhead
associated with map and array re-sizing.
2. Where appropriate, limit annotation and label retrievals to only the
desired keys.
3. Adjust annotation and label retrieval to avoid unnecessary temporary
object creation.