MessageDescriptor's FindFieldByName function was identified to be one of the
hot functions called at Uber. It builds a fully qualified name for a given
field name, and looks it up in the symbol map it keeps. The fully qualified
name here is currently created by using fmt.Sprintf.
However, using fmt.Sprintf for simple string concatenation turned out to be
performing much worse than using '+' operator because fmt.Sprintf does more
processing for parsing verbs and generally makes more allocations.
This PR updates MessageDescriptor.FindFieldByName to use string concatenation
for building the fully qualified name for looking up the field, instead of
using fmt.Sprintf.
Below is the result of benchmarks added in this PR:
Benchmarks are done by calling MessageDescriptor's FindFieldByName function
with names of varying lengths. Considering a reasonable length of a field's name
is shorter than 100 characters, this PR should improve the performance of this
function by more than 50% on average.
MessageDescriptor's FindFieldByName function was identified to be one of the hot functions called at Uber. It builds a fully qualified name for a given field name, and looks it up in the symbol map it keeps. The fully qualified name here is currently created by using fmt.Sprintf.
However, using fmt.Sprintf for simple string concatenation turned out to be performing much worse than using '+' operator because fmt.Sprintf does more processing for parsing verbs and generally makes more allocations.
This PR updates MessageDescriptor.FindFieldByName to use string concatenation for building the fully qualified name for looking up the field, instead of using fmt.Sprintf.
Below is the result of benchmarks added in this PR:
Benchmarks are done by calling MessageDescriptor's FindFieldByName function with names of varying lengths. Considering a reasonable length of a field's name is shorter than 100 characters, this PR should improve the performance of this function by more than 50% on average.