Currently attribute trimming always transforms the attributes map into a vector and sorts it by size. If the attributes don't need to be trimmed, this is wasted effort. It may be cheaper to check the size of the collection once in the beginning and immediately return if the attributes fit within the remaining budget.