eclipse-ee4j / eclipse-ee4j/jersey

Resource scanning inefficient for a root resource class with large number of resource methods

Open
#3,314 4 comments 0 reactions 0 assignees View on GitHub
Component: core Priority: Minor resource_loading resources server Type: Bug
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

We have a root resource class that is provided as an interface to a legacy API. This class contains a large number (approximately 500), of autogenerated methods that are exposed as REST endpoints.

Loading our Servlet Application takes about 1 second without this class included in our list of endpoints (though we have approximately 300 other REST endpoints in much smaller classes), but about 30 seconds with this class included.

Using visualvm as a profiler, I was able to determine that the hotspot was in org.glassfish.jersey.server.model.Resource.mergeResources(List resources. There is a nested loop in this method that is iterating over this list (which is a linkedlist, but probably shouldn't be), and this seems to be causing the performance issue for us. I am unsure if making the linked list an arrayList would solve the problem, or if it would be necessary to rework the way the resources are merged in the case of a large list.
#### Environment
Jetty 9, Java 7
#### Affected Versions
[2.22.1]

Contributor guide

Open the contributing guide

Research direction

Start at org.glassfish.jersey.server.model.Resource.mergeResources(List resources), identified as the profiling hotspot during Servlet Application loading. Reproduce the startup slowdown with a root resource class containing many autogenerated REST methods, then investigate resource merging and compare startup performance. Done means large resource classes scan substantially faster without changing endpoint registration.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.