-
-
Notifications
You must be signed in to change notification settings - Fork 167
Improved middleware runner performance #236
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
Improved middleware runner performance #236
Conversation
|
Not strictly related to this PR, but the runner could need a test that it can be run multiple times without internally modifying the middleware stack. This might be avoiding regressions when refactoring. $runner = new MiddlewareRunner([
$this->expectCallableExactly(2),
$this->expectCallableExactly(2)
]);
$runner(new ServerRequest('GET', 'https://example.com/'));
$runner(new ServerRequest('GET', 'https://example.com/')); |
|
@jsor could you PR that, so we can add that test before merging this PR? |
|
@WyriHaximus damn, i failed trying to offload work 😄 Here it is: #237 |
|
@jsor You can try 😝 . Cheers 👍 |
0b5f9a6 to
a5c32a8
Compare
clue
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is currently failing, otherwise LGTM 👍
Can you give some numbers on how this is "improved"?
|
@clue yeah only 5.3 test is failing at the moment. Current master is more over 3 times slower than this PR. Also only only has all the middlewares in memory once and no extra references to them like the current master has saving memory. (Depending on how many middlewares you have and how many requests you're handling at that moment that adds up.) |
a5c32a8 to
298cdcf
Compare
|
@jsor @clue fixed PHP 5.3 support and it seems that doubled the performance |
src/MiddlewareRunner.php
Outdated
| return new Promise\Promise(function ($resolve, $reject) use ($middleware, $request, $func, &$cancel, &$position) { | ||
| $position++; | ||
| try { | ||
| $cancel = $middleware( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, this should be $response insteand of $cancel.
298cdcf to
260463f
Compare
|
@jsor Good point, changed it 👍 |
e3ed6ea to
110cef9
Compare
…ead of creating a new instance of itself for each middleware ran
110cef9 to
70b7a48
Compare
clue
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, let's get this in! 📈 🎉
This middleware runner is faster and uses less RAM the more middleware added because it doesn't creates new instances of it self while iterating over all the middleware.