eclipse-ee4j / eclipse-ee4j/jersey

Jersey 2 Slow bootstrap performance

Open
#4,009 1 comment 2 reactions 0 assignees View on GitHub
performance
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

Jersey Version 2.26

For a certain test suite, I have to bootstrap a Jersey base web application per every Test class.
Recently I've migrated from Jersey 1 and noticed a performance degradation. It is roughly twice as slower than before.

Several profiling sessions discovered that during `ApplicationHandler` initialization, around 40% of time spent is in `MethodSelectingRouter.`

This is mostly due to the addition of `OptionsMethodProcessor` which enhance each resource model with two OPTION methods, especially this one:

methodList.add(new ModelProcessorUtil.Method(HttpMethod.OPTIONS,
MediaType.WILDCARD_TYPE, MediaType.WILDCARD_TYPE, GenericOptionsInflector.class));

Which further contribute to `MethodSelectingRouter.addAllConsumesProducesCombinations`:

Since that method can produce and consume everything , and we have dozens supported content type for each, this code:

for (MediaType consumes : effectiveInputTypes) {
for (MediaType produces : effectiveOutputTypes) {
acceptorSet.add(new ConsumesProducesAcceptor(
new CombinedMediaType.EffectiveMediaType(consumes, consumesFromWorkers),
new CombinedMediaType.EffectiveMediaType(produces, producesFromWorkers),
methodRouting));
}
}

Produces a cartesian product of thousands of `ConsumesProducesAcceptor` instances.
Those many calls to `acceptorSet.add` are slow because of `CombinedMediaType.hashCode()`

This also affects the sort operation in the constructor which is also slow:

for (final String httpMethod : httpMethods) {
Collections.sort(consumesProducesAcceptors.get(httpMethod), CONSUMES_PRODUCES_ACCEPTOR_COMPARATOR);
}

... and also effects the evaluation of dynamic features (two extra methods for evaluation).

An optional evaluation of `OptionsMethodProcessor` - for such scenario - is desired , if none exists (I couldn't find a method to "defuse" that model processor).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.