Fully featured low overhead profiler for Java EE and Java SE platforms.
Ultimate profiling and monitoring solution for Gradle, Maven, Ant, JUnit and TestNG.
Easy to use performance and memory profiler for .NET framework.

Lot of CPU time spent in java.util.ArrayList.size()

Moderators: Vladimir Kondratyev, Anton Katilin

Lot of CPU time spent in java.util.ArrayList.size()

Postby robbo » Fri Nov 21, 2014 3:21 pm

With CPU sampling Yourkit snapshots report a lot of CPU time of a thread (call tree by thread) spent in java.util.ArrayList.size(). This is a tiny method that should be extremely fast. Yet CPU time of several seconds is being recorded, while bigger methods further up the stack report less own time. What can be the explanation for this?
robbo
 
Posts: 3
Joined: Tue Nov 18, 2014 12:58 pm

Re: Lot of CPU time spent in java.util.ArrayList.size()

Postby Anton Katilin » Fri Nov 21, 2014 5:00 pm

Sampling is approximate by its nature:
http://www.yourkit.com/docs/java/help/cpu_intro.jsp

It is based on stacks reported by JVM. JVM does not necessarily report the actual running method at the moment of sample, but, for its own optimization purposes, the nearest "safe point" method instead.

General rule: don't assume sampling will accurately measure anything sorter than the sampling period which is 20 ms by default and can be specified in the CPU sampling settings:
http://www.yourkit.com/docs/java/help/s ... ttings.jsp

It's a bad idea to measure ArrayList.size() with sampling. You may simply ignore that part of the stack in the profiling results. Instead, pay attention at the ArrayList.size()'s callers and their callers and so on.
Anton Katilin
 
Posts: 5675
Joined: Wed Aug 11, 2004 8:37 am


Return to Java Profiler

Who is online

Users browsing this forum: Baidu [Spider] and 9 guests

cron