Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract IriConverter::getRouteName into RouteNameResolverInterface #721

Merged
merged 1 commit into from
Sep 5, 2016

Conversation

teohhanhui
Copy link
Contributor

@teohhanhui teohhanhui commented Sep 2, 2016

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR N/A

This allows caching of route name resolving, which should result in a significant performance gain (please verify).

@teohhanhui teohhanhui force-pushed the iri-converter-perf branch 4 times, most recently from aa1c689 to 9b1840a Compare September 2, 2016 09:39
@theofidry
Copy link
Contributor

Would it be possible to have a blackfire profiling on the demo app with it?

@teohhanhui
Copy link
Contributor Author

Does Blackfire offer anything for open source projects? The free plan only has 1-day data retention...

$routeName = $this->decorated->getRouteName($resourceClass, $collection);

if (isset($cacheItem)) {
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about an early return here to avoid having the try/catch nested?

@theofidry
Copy link
Contributor

The free plan only has 1-day data retention...

Oh, I wasn't aware they changed that.

Even if it's one day it's fine, we need it only for a quick review otherwise a screenshot of the result is enough.

<argument type="service" id="api_platform.router" />
</service>

<service id="api_platform.route_name_resolver.cached" class="ApiPlatform\Core\Bridge\Symfony\Routing\CachedRouteNameResolver" decorates="api_platform.route_name_resolver" decoration-priority="-10" public="false">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the decoration-priority attribute necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To convey the intention that this should run dead last, and so that any user-declared decorators would be correctly wrapped by default (decoration priority 0). It's good to have, and consistent with the decorated metadata factory services...

@teohhanhui
Copy link
Contributor Author

teohhanhui commented Sep 2, 2016

Profiling of GET /books for API Platform Standard Edition (based on the commit before @dunglas removed the fixtures).

blackfire

@teohhanhui
Copy link
Contributor Author

In our project for example, there are 409 calls to getRouteName. The performance impact is therefore quite significant:

Before (warm): 320ms (28%)
After (warm): 9.96 ms (1.76%)

@@ -20,7 +20,7 @@
use ApiPlatform\Core\Util\ClassInfoTrait;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\Routing\Exception\ExceptionInterface;
use Symfony\Component\Routing\Exception\ExceptionInterface as RoutingExceptionInterface;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because ExceptionInterface is not specific enough, especially considering we also have our own ExceptionInterface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SymfonyRoutingExceptionInterface then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theofidry That seems like overkill? 😛 Let's try to strike a balance...

@Simperfit
Copy link
Contributor

This is great ! @teohhanhui 👍

@teohhanhui
Copy link
Contributor Author

Comments addressed.

$cacheItemPoolProphecy->save($cacheItemProphecy)->willReturn(true)->shouldBeCalled();

$decoratedProphecy = $this->prophesize(RouteNameResolverInterface::class);
$decoratedProphecy->getRouteName('AppBundle\Entity\User', true)->willReturn('some_collection_route')->shouldBeCalled();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User::class?

{
$routeCollection = new RouteCollection();
$routeCollection->add('some_collection_route', new Route('/some/collection/path', [
'_api_resource_class' => 'AppBundle\Entity\User',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ::class constant can be used.

@dunglas
Copy link
Member

dunglas commented Sep 5, 2016

What do you think about removing the duplication rule in Scrutinizr? It seems to be mostly false positives: https://scrutinizer-ci.com/g/api-platform/core/inspections/2b149181-1f5f-49b2-bb94-65ca318c194c/issues/

@teohhanhui
Copy link
Contributor Author

@dunglas:

What do you think about removing the duplication rule in Scrutinizr? It seems to be mostly false positives

I don't think we should remove the rule. It can still help us catch some actual code duplication. No harm, right?

@dunglas dunglas merged commit fbf6e8c into api-platform:master Sep 5, 2016
@dunglas
Copy link
Member

dunglas commented Sep 5, 2016

Thanks!

@teohhanhui teohhanhui deleted the iri-converter-perf branch September 5, 2016 08:38
magarzon pushed a commit to magarzon/core that referenced this pull request Feb 12, 2017
Extract IriConverter::getRouteName into RouteNameResolverInterface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants