Optimize RequestListener #59
Comments
The 25ms seem a little bit too high for me for just fetching a service. DIC in prod should be able to do that way faster. Did you measure those values in a "dev" or a "prod" environment? Do you have some op-code cache enabled, either APC or native PHP7 op-code cache? Anyways, there IS room for improvment. I think a major improvment would be if |
@scheb Yes, it is too high, that's why I'm posting. Other services are fetched way faster. It's from Blackfire profile done on prouduction with op-code cache enabled. Thanks. |
So, what exactly consumes those 25ms? |
@zerkms Fetching service from container: |
Right, but what exactly takes so long? 26ms is A LOT. Nothing but few objects are instantiated there. On my symfony projects some of entire requests (from the first request byte to the last response byte) take less than that. I would still suggest to find the real problem before trying to optimise it, since it looks suspicious. |
@zerkms Yes, I agree, still investigating it. Only services from this bundle are loading this slow. |
Here are the latest findings. Making @scheb I think requiring |
Release will be published as soon as Travis build greenlights the change. |
@scheb Awesome, thanks! 👍 |
Well, I checked code and I'm not convinced that it should have been implemented like that. The current solution mitigates the consequences but does not solve the root of the problems (since the roots haven't been detected). Adding Especially that - when My best guess would be that it's other dependencies that UPD: and after some debugging I'm even more confident that what I said above is true and that "the solution" solves nothing just hides the real problem somewhere else. Some candidates that do some heavy lifting are |
@zerkms I agree except that it does not solves nothing. It solves slowness on all pages that are not authentication. This is a huge win for me. I agree that it should be investigated further and optimize auth pages. |
@umpirsky well, Did you get instant improvement of performance of 26ms everywhere? So every page now loads 26ms faster? You should not have.
It's not possible - it is still instantiated. |
@zerkms No, because it's not used during request that does not trigger 2FA. So it's not instantiated. |
@umpirsky have you tried to confirm that with a debugger? https://github.com/scheb/two-factor-bundle/blob/master/Security/TwoFactor/EventListener/RequestListener.php#L84 this line is executed for every request that is not ignored using Otherwise the
needs some clarification. |
@zerkms Yes, that line is executed, but not the |
Have you tried to run a debugger and confirm what you say? I'm not in the office now so I cannot take a screenshot of a stack trace, not sure why you don't simply try it and see :-( Seriously, we are wasting time: performance optimisation is about precise stuff: everything must be proven, there must be no place for suggestions and guesses (and jeez - especially random changes, which that change surely is). I have made a statement that I have checked and confirmed with a debugger. It's not constructive if I spend dozens of comments more begging to revert a useless change (that not only makes nothing faster but slower for most of use cases this bundle was designed for). |
@zerkms You are right, I will check again when I find some time and post results here. Now, I only remember that moving this to lazy fixed the issue for me. |
It could not have - So I believe it is either placebo or some issues with capturing the performance metrics. |
Issue is still here, working on a fix... |
Looks like
RequestListener
adds some latency, and notonCoreRequest
as you'd expect, but just fetching the service from container can add ~25ms to each request.I tried to track down the dependency graph and it goes like this:
scheb_two_factor.security.request_listener
->scheb_two_factor.trusted_filter
->scheb_two_factor.provider_registry
->scheb_two_factor.security.google.provider
->scheb_two_factor.security.google.backup_code_validator
->scheb_two_factor.backup_code_validator
->scheb_two_factor.persister.doctrine
.If using lazy services and check
FlagManager.isNotAuthenticated()
earlier this can be optimized.I know
FlagManager
does not know about providers, but maybe it can be tweaked to pull a minimal set of dependencies ifFlagManager.isNotAuthenticated()
isfalse
.The text was updated successfully, but these errors were encountered: