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

Questions about YourKit Java Profiler
Post Reply
robbo
Posts: 3
Joined: Tue Nov 18, 2014 12:58 pm

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

Post by robbo »

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?
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

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

Post by Anton Katilin »

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.
Post Reply