Closed nicktelford closed 9 months ago
JmxScraper#scrapeBean() uses ObjectName#toString() twice per-MBean attribute to check the MBean name against several special-cases.
JmxScraper#scrapeBean()
ObjectName#toString()
ObjectName#toString() is quite expensive, because it allocates a new char[] and copies the name data into it, on each call.
char[]
Consequently, when there are a large number of number of MBean attributes, these calls compound and can create performance problems.
Caching the result of ObjectName#toString() outside this loop ensures we only call it once per-MBean.
See attached flame graph for an illustration of the allocations caused by these ObjectName#toString() calls:
@nicktelford Good catch! Thanks for the PR. I'll merge it
JmxScraper#scrapeBean()
usesObjectName#toString()
twice per-MBean attribute to check the MBean name against several special-cases.ObjectName#toString()
is quite expensive, because it allocates a newchar[]
and copies the name data into it, on each call.Consequently, when there are a large number of number of MBean attributes, these calls compound and can create performance problems.
Caching the result of
ObjectName#toString()
outside this loop ensures we only call it once per-MBean.