HATEOAS Reference and Method Performance

We use HATEOAS for a great effect, however we look at performance and get very poor results from link building, namely code that looks like this

resource.add(linkTo(methodOn(SomeController.class).findAll())).withSelfRel()); 

Results (I'm not so worried about size, but recorded below)

 Enabled links - ~438ms - 201 kb Disable links - ~193ms - 84.6 kb 

The size is explained by the fact that we set 8 links to the resource, so we expect the size, but not the speed slows down.

Approximately 232 ms is spent building links of approximately 2 ms to the object I am returning (100 objects in this particular test)

Is there any way to speed this up? Can we get a preview of the URI for the whole request in a call toResources , and then use it in toResource ?

+5
source share
1 answer

I looked at the code around linkTo(methodOn()) and it seems like AOP magic. The generated proxy is generated every time you call the On method for the target interface.

I feel this is great for testing when you want to avoid hard URI encodings. EntityLinks provides an alternative that should be much more efficient. But this is not as strong as ControllerLinkBuilder .

An alternative is to use the Helper class in conjunction with EntityLinks . Spring-restbucks projects have a good example - the PaymentLinks class .

But honestly, it's hard to compete with the convenience provided by ControllerLinkBuiler.

EDIT: Please see my answer here for a more detailed comparison of link builder performance.

+1
source

Source: https://habr.com/ru/post/1207387/


All Articles