Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HATEOAS Link and Method performance

We are using HATEOAS to great effect however we have been looking at performance and getting very poor results from the building of the links, namely code which looks like this

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

Results (I am not as concerned about the size but recorded below anyway)

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

The size is due to us putting out 8 links per resource so we expected the size, but not the speed slow down.

Approximately 232ms is spent on constructing links roughly 2ms per object I return (100 objects in this particular test)

Is there anyway to speed this up? Can we get the URI upfront for all request in the toResources call for example and then flavor it in the toResource?

like image 226
Richard Holt Avatar asked Nov 21 '14 10:11

Richard Holt


1 Answers

I had a look at the code around linkTo(methodOn()) and it looks like a lot of AOP magic. A proxy is generated is generated every time you call methodOn for the target interface.

My feeling is that this is great for testing when you want to avoid hard-coding URIs. EntityLinks provides an alternative which should be much more efficient. But it is not as powerful as ControllerLinkBuilder.

An alternative is to use a Helper class in combination with EntityLinks. The spring-restbucks projects contains a nice example - the PaymentLinks class.

But to be honest - it is hard to compete with the convenience provided by ControllerLinkBuiler.

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

like image 78
Mathias Dpunkt Avatar answered Sep 26 '22 00:09

Mathias Dpunkt