Search code examples
javaprofilingjprofiler

How to understand and optimize high self time of a factory method


I profiled cpu usage of a use case and looked into the the biggest call time contributors in the call tree. There I stumbled upon a method with a quite high self time. See here:

Call tree

I checked the method and found the following code

    @Override
    public IArticleDataProvider getArticleDataProvider() {
        return new ArticleDataProvider();
    }

The method does nothing else, but instantiation. The call tree shows, that the instantiation itself isn't slow - no black magic -, so how can I make sense out of this 117ms delay? I rerun my usage and the second time it was within micro seconds as expected. Also the clinit wasn't needed anymore, which makes sense. I'm aware that single samples are not a good benchmark for performance, only a starting point for deeper dives, but is this something to be expected while profiling? At least it yells for a spot in outlier detection. This sounds like more than just a jvm warmup issue, right? Are there more factors to be taken into account here?

This is my first real case using java profiling. I've attended a couple of talks about java profiling and read some guides prior. I'm thankful for all feedback


Solution

  • It looks simply like the time needed for class loading. That time is not included in the node, the latter is only the invocation of the static initializer.