-
Notifications
You must be signed in to change notification settings - Fork 444
refactor: move message handling internals to use async/await
#1656
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
base: master
Are you sure you want to change the base?
Conversation
4f03851 to
e761fa1
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1656 +/- ##
==========================================
- Coverage 79.92% 79.16% -0.77%
==========================================
Files 90 90
Lines 4887 5030 +143
Branches 920 938 +18
==========================================
+ Hits 3906 3982 +76
- Misses 676 741 +65
- Partials 305 307 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@MichaelSun90 @mShan0 Mind taking a look? I only moved the |
c37096d to
39cbe28
Compare
39cbe28 to
bac1f77
Compare
|
@claude Can you do a thorough review of these changes? |
|
Claude finished @arthurschreiber's task in 2m 8s —— View job Thorough Code ReviewI've completed a comprehensive review of this PR. Overall, this is a well-designed refactoring with solid performance improvements and cleaner abstractions. However, there are some issues that need attention before merging. 🔴 Critical Issues1. Debug Console Statements Left in Production CodeLocation: console.log('looking up addresses for ', options.host);
console.log('lookup failed', err, process.hrtime(startTime));
console.log('looked up addresses for', options.host, process.hrtime(startTime));Issue: These debug console.log statements should not be in production code. They should either:
Impact: High - pollutes console output in production environments 2. Missing Semicolon (Syntax Issue)Location: const message = MessageIO.readMessage(socket, this.debug) // <-- Missing semicolon
const iterator = message[Symbol.asyncIterator]();Issue: Missing semicolon could cause ASI (Automatic Semicolon Insertion) issues. While JavaScript will likely handle this, it's inconsistent with the codebase style. Impact: Medium - could cause linting failures, inconsistent with code style
|
This introduces some initial refactoring around
MessageIO/IncomingMessageStream/OutgoingMessageStream.Namely, the goal is to completely remove
IncomingMessageStream/OutgoingMessageStream/Messageand replace them with two straightforward functions instead:MessageIO.readMessageto read the contents of a message as a stream using anAsyncIterable<Buffer>from aReadablestream.MessageIO.writeMessageto write a stream of buffers (generated synchronously via aIterable<Buffer>or asynchronously via aAsyncIterable<Buffer>) to aWritablestream.Both these new methods are much simpler compared to the previous
IncomingMessageStream/OutgoingMessageStreamimplementation, both from a logical complexity as well as an implementation complexity point.They're also both significantly faster than the current implementations. I added benchmarks that try to compare either implementation (benchmarks run using Node.js v18.20.4):
The current implementation spends a lot of time setting up new stream objects for each incoming and outgoing message (via the
Messageclass that inherits fromPassThroughtransform stream), and that causes quite a dent in performance, especially when v8 optimizations haven't kicked in yet.