You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Suboptimal performance of ControllerLinkBuilder.linkTo(…) #511
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:
To be clear this seems related to the use of ControllerLinkBuilder. If I create links manually (without the benefit of static typing for route building) the problem goes away.
That's interesting and definitely needs to be fixed. Do you have that sample code in a project somewhere that we could profile it?
I suspect the proxy and the proxy class creation necessary to be the culprits here. We could try to more aggressively cache those, I guess. But still, a project to try those experiments on would be very welcome. :)
484 milliseconds to add 3 Spring HATEOAS links to 500 items
144 milliseconds to add 3 Spring HATEOAS links to 500 items
120 milliseconds to add 3 Spring HATEOAS links to 500 items
116 milliseconds to add 3 Spring HATEOAS links to 500 items
98 milliseconds to add 3 Spring HATEOAS links to 500 items
Any chance that your preparing call cause the delay?
Thanks for the feedback. I will work on creating a sample that reproduces the issue.
I am certain that it is the code adding the links (specifically the calls to linkTo() and methodOn()) that causes the delay. I changed that code to create Link objects manually instead of using the methods on ControllerLinkBuilder and the problem goes away:
I've just pushed a couple of improvements that a profiling session unveiled feasible. The core culprit however is an issue in core Spring Framework which causes the synthesized annotations on method parameters to undergo a repeated equals(…) comparison which is quite costly.
You can see the numbers drop significantly if you copy Spring's TypeDescriptor into your project and comment out the annotation related code in its equals(…) method. I've filed a ticket for that and another one that turned out to be the next hotspot after our improvements made for this ticket here.
I am resolving this one as fixed as we essentially have to rely on Spring Framework to fix that issue downstream.
changed the title [-]Poor performance simply adding links to results (addl 20-90s)[/-][+]Suboptimal performance of ControllerLinkBuilder.linkTo(…)[/+]on Nov 21, 2016
Activity
nwoolls commentedon Nov 20, 2016
To be clear this seems related to the use of
ControllerLinkBuilder. If I create links manually (without the benefit of static typing for route building) the problem goes away.odrotbohm commentedon Nov 20, 2016
That's interesting and definitely needs to be fixed. Do you have that sample code in a project somewhere that we could profile it?
I suspect the proxy and the proxy class creation necessary to be the culprits here. We could try to more aggressively cache those, I guess. But still, a project to try those experiments on would be very welcome. :)
odrotbohm commentedon Nov 20, 2016
I just gave this a spin and cannot reproduce your numbers at all:
Yields:
Any chance that your preparing call cause the delay?
nwoolls commentedon Nov 20, 2016
Thanks for the feedback. I will work on creating a sample that reproduces the issue.
I am certain that it is the code adding the links (specifically the calls to
linkTo()andmethodOn()) that causes the delay. I changed that code to createLinkobjects manually instead of using the methods onControllerLinkBuilderand the problem goes away:However I'd much rather use the strongly typed methods of
ControllerLinkBuilder. I'll post back once I have a sample.nwoolls commentedon Nov 20, 2016
Hope this helps - let me know if you need anything else:
#511 - Performance improvements in link building.
odrotbohm commentedon Nov 21, 2016
I've just pushed a couple of improvements that a profiling session unveiled feasible. The core culprit however is an issue in core Spring Framework which causes the synthesized annotations on method parameters to undergo a repeated
equals(…)comparison which is quite costly.You can see the numbers drop significantly if you copy Spring's
TypeDescriptorinto your project and comment out the annotation related code in itsequals(…)method. I've filed a ticket for that and another one that turned out to be the next hotspot after our improvements made for this ticket here.I am resolving this one as fixed as we essentially have to rely on Spring Framework to fix that issue downstream.
[-]Poor performance simply adding links to results (addl 20-90s)[/-][+]Suboptimal performance of ControllerLinkBuilder.linkTo(…)[/+]#511 - Caching UriTemplate instances for discovered mappings now.