Skip to content

Suboptimal performance of ControllerLinkBuilder.linkTo(…) #511

Closed
@nwoolls

Description

@nwoolls

Hi there. I'm trying out this framework and running into performance issues out of the gate.

For instance, I have a simple method where I add 3 resource links to each result in an array. There are 537 (but it could be more) items. This takes 20 seconds just to add the resource links to the array. Additionally, making subsequent calls to the method seems to have a compounding penalty on performance. Obviously this is unacceptable. I think I must be missing something.

20310 milliseconds to add 3 Spring HATEOAS links to 537 items
53933 milliseconds to add 3 Spring HATEOAS links to 537 items
89763 milliseconds to add 3 Spring HATEOAS links to 537 items

I see references to using the EntityLinks class but this has its own limitations (it seems, requiring one controller-per-model).

Am I hopefully overlooking something simple here? Here is the code in question:

long startTime = System.currentTimeMillis();

for (final MyEntity result : results) {
    final MyLocation location = result.getLocation();
    final String primaryId = location.getStoreId();
    final String secondaryId = location.getSettingId();

    result.add(linkTo(
            methodOn(MyController.class)
            .methodNumber1(primaryId, secondaryId))
            .withSelfRel());

    result.add(linkTo(
            methodOn(MyController.class)
            .methodNumber2(primaryId))
            .withRel(REL_FIRST));

    result.add(linkTo(
            methodOn(MyController.class)
            .methodNumber3(primaryId, secondaryId))
            .withRel(REL_SECOND));
}

long duration = (System.currentTimeMillis() - startTime);

System.err.println(String.format("%d milliseconds to add 3 Spring HATEOAS links to %d items",
        duration, results.size()));

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions