-
Notifications
You must be signed in to change notification settings - Fork 652
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
Reduce allocations when notify promises related to pending writes. #308
Conversation
Noticed this wile benchmarking... |
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.
removing allocations is great! thanks!
/// - returns: A closure that the caller _needs_ to run which will fulfill the promises of the writes and a `OneWriteOperationResult` which indicates if we could write everything or not. | ||
public mutating func didWrite(itemCount: Int, result writeResult: IOResult<Int>) -> (() -> Void, OneWriteOperationResult) { | ||
/// - returns: An array of promises (that needs to be notified) of the writes and a `OneWriteOperationResult` which indicates if we could write everything or not. | ||
public mutating func didWrite(itemCount: Int, result writeResult: IOResult<Int>) -> ([EventLoopPromise<Void>], OneWriteOperationResult) { |
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.
couldn't we actually return one EventLoopPromise<Void>
and cascade
all others into that?
/// - returns: A closure that the caller _needs_ to run which will fulfill the promises of the writes and a `OneWriteOperationResult` which indicates if we could write everything or not. | ||
public mutating func didWrite(itemCount: Int, result writeResult: IOResult<Int>) -> (() -> Void, OneWriteOperationResult) { | ||
/// - returns: An array of promises (that needs to be notified) of the writes and a `OneWriteOperationResult` which indicates if we could write everything or not. | ||
public mutating func didWrite(itemCount: Int, result writeResult: IOResult<Int>) -> ([EventLoopPromise<Void>], OneWriteOperationResult) { | ||
var promises: [EventLoopPromise<Void>] = [] |
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.
we could save this whole array if we return one EventLoopPromise
85703a2
to
ce55605
Compare
@weissi PTAL again.. |
Also when running our allocation tests this reduce the number of allocations per req by 2. Also it improves other benchmarks (like echo)... Before:
With the PR:
|
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, like this version much better, thank you!
Here are also the alloc differences with our test: master:
With this PR:
|
public mutating func didWrite(itemCount: Int, result writeResult: IOResult<Int>) -> (() -> Void, OneWriteOperationResult) { | ||
var promises: [EventLoopPromise<Void>] = [] | ||
let fulfillPromises = { promises.forEach { $0.succeed(result: ()) } } | ||
/// - returns: The promises, or nil, that cascades to all promises (that needs to be notified) of the writes and a `OneWriteOperationResult` which indicates if we could write everything or not. |
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.
Let's reword this: - returns: A tuple of a promise and a
OneWriteResult. The promise is the first promise that needs to be notified of the write result. This promise will cascade the result to all other promises that need notifying. If no promises need to be notified, will be
nil. The write result will indicate whether we were able to write everything or not.
abe4743
to
3cb2ef9
Compare
@Lukasa addressed PTAL again |
Motivation: We returned an callback which needed to be executed by the caller. This will cause extra allocations and is not needed. We can just return a EventLoopPromise which will cascade the notification. Modification: Not return a closure but promise. Result: Less allocations.
3cb2ef9
to
c85888f
Compare
Go ahead and merge when ready. |
Motivation: