-
Notifications
You must be signed in to change notification settings - Fork 644
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
Adopt NIOThrowingAsyncSequenceProducer
#2879
Conversation
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.
In general this looks good to me. Have you run some benchmarks between the two to make sure we still have the same performance?
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 looks good! I left a couple of small comments which need addressing.
@@ -135,52 +136,85 @@ extension DirectoryEntries.Batched.AsyncIterator: Sendable {} | |||
// MARK: - Internal | |||
|
|||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | |||
extension BufferedStream where Element == [DirectoryEntry] { | |||
extension NIOThrowingAsyncSequenceProducer where Element == [DirectoryEntry], Failure == Error, |
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.
nit
extension NIOThrowingAsyncSequenceProducer where Element == [DirectoryEntry], Failure == Error, | |
extension NIOThrowingAsyncSequenceProducer where Element == [DirectoryEntry], Failure == (any Error), |
switch self.state { | ||
case let .idle(handle, _): | ||
return handle.threadPool | ||
case let .open(threadPool, _, _): | ||
return threadPool | ||
case .openPausedProducing(let threadPool, let source, let array): | ||
self.state = .modifying |
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.
.modifying
isn't required here because we aren't modifying any of the state held in the openPausedProducing
case
internal mutating func pauseProducing() { | ||
switch self.state { | ||
case .open(let nIOThreadPool, let source, let array): | ||
self.state = .modifying |
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.
same here, no need to do .modifying
case .done: | ||
return nil | ||
case .modifying: | ||
fatalError() | ||
} | ||
} | ||
|
||
internal mutating func pauseProducing() { | ||
switch self.state { | ||
case .open(let nIOThreadPool, let source, let array): |
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.
nit: threadPool
init(range: FileChunks.ChunkRange, handle: SystemFileHandle, length: Int64) { | ||
|
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.
nit: no blank lines at the start of funcs
init(range: FileChunks.ChunkRange, handle: SystemFileHandle, length: Int64) { | |
init(range: FileChunks.ChunkRange, handle: SystemFileHandle, length: Int64) { |
let state: ProducerState = switch range { | ||
case .entireFile: | ||
.init(handle: handle, range: nil) | ||
case .partial(let partialRange): | ||
.init(handle: handle, range: partialRange) | ||
} |
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.
Hmm, I don't think our minimum Swift version is new enough to support this? Also the indentation is way off for the body of each case.
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.
(Also I really don't like this syntax but maybe I'm just a curmudgeon...)
|
||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | ||
extension ProducerState.Producing { | ||
mutating func updateRange(count: Int) -> Bool { |
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.
It's not obvious how the range is updated without looking at the implementation, also the return value is quite misleading: if updateRange(count: blah) { ... }
looks a whole lot like "if the range was updated then ...".
Would probably be clearer if you call this didReadBytes(_ count: Int)
and documented the return value (you could use an enum for the return type but that's probably overkill)
I would be surprised if there was a substantial difference. You'd think the syscalls would dominate here but it's worth doing some validation nonetheless. |
7d74670
to
41fe2de
Compare
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.
Looks good modulo some failing CI!
case .produceMore: | ||
self.produceMore() | ||
case .stopProducing: | ||
self.state.withLockedValue { state in state.pauseProducing()} |
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.
self.state.withLockedValue { state in state.pauseProducing()} | |
self.state.withLockedValue { state in state.pauseProducing() } |
41fe2de
to
b61146f
Compare
Motivation: Adopt `NIOThrowingAsyncSequenceProducer` in NIOFileSystem to reduce code duplication. Modifications: Adopt `NIOThrowingAsyncSequenceProducer` in NIOFileSystem `DirectoryEntryProducer` and `FileChunkProducer` Result: No functional changes. Internal changes reduce code duplication.
b61146f
to
eac6c2a
Compare
Performance-wise there doesn’t seem to be much of a difference. I tested listing the files on disk, exercising the For the existing code: For the new code: |
### Motivation: Adopt `NIOThrowingAsyncSequenceProducer` in NIOFileSystem to reduce code duplication. ### Modifications: Adopt `NIOThrowingAsyncSequenceProducer` in NIOFileSystem `DirectoryEntryProducer` and `FileChunkProducer` ### Result: No functional changes. Internal changes reduce code duplication.
This pull consistently causes hanging I'll see if I can track it down and file an issue. |
Motivation:
Adopt
NIOThrowingAsyncSequenceProducer
in NIOFileSystem to reduce code duplication.Modifications:
Adopt
NIOThrowingAsyncSequenceProducer
in NIOFileSystemDirectoryEntryProducer
andFileChunkProducer
Result:
No functional changes. Internal changes reduce code duplication.