-
-
Notifications
You must be signed in to change notification settings - Fork 50
Significantly improve the performance of `Collection<FutureType>.flatten #199
Conversation
…ten`. This further halves the runtime in vapor/template-kit#50 from 0.1s to 50ms.
I just noticed that this is essentially reverting 439d6dc#diff-945d1a38da3eef0446f42a82a64b7ead, however all tests still pass. This PR should not be affected by the issue described in #184 because we are ensuring that each element is acted upon on the same event loop. In addition, the 3x performance gain from this PR is too important to pass up, given that @adtrevor, would you mind taking a look at this PR? |
The |
@MrMage Everything looks correct to me! :) |
See #199 (comment) :-) |
@MrMage I guess we posted at about the same time 😄. Sounds good! |
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.
This LGTM, thanks for looking into this.
Just to double check, would it be possible for us to use whenAllSucceeded
like we are doing for Vapor 4 in NIOKit?
https://github.com/vapor/nio-kit/blob/master/Sources/NIOKit/EventLoop/EventLoop%2BFlatten.swift#L12
If not, then let's merge this.
No idea about the performance of Or will this |
@MrMage Core is being remove from Vapor 4, so you would go with the second option. But in reality, we won't be updating Core to NIO 2 because Vapor 3 uses NIO 1. |
Thanks for the info! That makes sense. I think we should benchmark NIOKit's |
Update: no need for changes in |
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.
Thanks @MrMage !
Hey @MrMage, you just merged a pull request, have a coin! You now have 19 coins. |
This further halves the runtime in vapor/template-kit#50 from 0.1s to 50ms (Release mode), because submitting several blocks to the run loop for every single array element can be fairly inefficient.
I'd expect this to tremendously speed up template rendering as well (results forthcoming).
Example Profile result before this optimization:
And afterwards: