-
Notifications
You must be signed in to change notification settings - Fork 129
chore(rivetkit): debounce ws message ack #3345
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
Pull Request Review: Debounce WebSocket Message AcknowledgmentsSummaryThis PR implements debouncing for WebSocket message acknowledgments by batching acks and flushing them on a 1-second interval. This is a good optimization to reduce the number of ack messages sent to the gateway. Code Quality & Best PracticesPositive:
Issues:
Performance ConsiderationsGood:
Considerations:
Security ConcernsLow Risk:
Consideration:
Test CoverageMissing:
Recommendation: Add unit tests covering the new debouncing logic, especially edge cases like:
Additional Suggestions
VerdictApproach: ✅ Good - Debouncing is the right solution for this problem Implementation: Priority:
Great work on identifying and addressing the performance issue with WebSocket acks! The debouncing approach is solid, just needs the serialization bug fixed. |
05654a6 to
a16734e
Compare
PR Review: Debounce WebSocket Message AcknowledgmentsSummaryThis PR implements debouncing for WebSocket message acknowledgments to reduce network overhead and improve performance by batching acks instead of sending them immediately for each message. Code Quality & Best PracticesPositive:
Issues Found: 🔴 Critical: Type Mismatch BugLocation: The // Current (WRONG):
#wsAckQueue: Map<string, number> = new Map();
// Should be:
#wsAckQueue: Map<string, bigint> = new Map();Impact: This could cause runtime type coercion issues and incorrect comparisons. TypeScript should catch this, but the comparison on line 588 ( 🟡 Medium: Inefficient ArrayBuffer SerializationLocation: Converting ArrayBuffer to a comma-separated string and back is inefficient: const requestIdStr = requestIdStr.split(",").map((x) => Number.parseInt(x))Suggestion: Use a more efficient key generation: // Use the existing idToStr utility that's already imported
const requestIdStr = idToStr(requestIdBuf);This would be more consistent with line 499 where Performance ConsiderationsGood:
Concern:
websocket.addEventListener("message", (event: RivetMessageEvent) => {
// Cache requestId string conversion
const requestIdStr = requestId; // Already converted on line 499
// ...Security ConcernsMedium Priority:
Potential Bugs
Test CoverageMissing:
Recommended Tests:
Action ItemsMust Fix Before Merge:
Should Fix:
Nice to Have:
Overall AssessmentThe core debouncing approach is sound and should improve performance. However, the type mismatch bug is critical and must be fixed before merging. With the suggested fixes, this will be a solid performance improvement. Recommendation: Request changes for critical bug fix, then approve. |
34d8908 to
5ad7f89
Compare
a16734e to
7973ad8
Compare
Pull Request Review: Debounce WebSocket Message AcknowledgmentsSummaryThis PR implements debouncing for WebSocket message acknowledgments to reduce the number of ack messages sent to the gateway. Instead of sending an ack for every message immediately, acks are batched and flushed every 1 second. Code Quality & Best PracticesPositive Observations:
Concerns:
Performance ConsiderationsGood:
Concerns:
Potential Bugs
Security ConsiderationsNo major security concerns identified. The debouncing logic doesn't introduce new attack vectors. Test CoverageMissing:
Recommendation: Add unit tests or integration tests, especially for the critical path of message acknowledgment. Suggested Changes- #wsAckQueue: Map<string, number> = new Map();
+ #wsAckQueue: Map<string, bigint> = new Map();
websocket.addEventListener("message", (event: RivetMessageEvent) => {
wsHandlerPromise.then((x) => x.onMessage?.(event, wsContext));
invariant(event.rivetRequestId, "missing rivetRequestId");
invariant(event.rivetMessageIndex, "missing rivetMessageIndex");
// Track only the highest seen message index per request
- // Convert ArrayBuffer to string for Map key
+ const requestId = idToStr(event.rivetRequestId);
const currentMax = this.#wsAckQueue.get(requestId) ?? -1n;Questions
Overall AssessmentThe approach is sound and addresses a real performance concern. However, there appear to be critical type mismatches and a missing variable declaration that need to be fixed before merging. Once these issues are resolved and tests are added, this will be a solid improvement. Recommendation: Request changes - fix type issues and add test coverage. |
rivetkit-typescript/packages/rivetkit/src/drivers/engine/actor-driver.ts
Outdated
Show resolved
Hide resolved
rivetkit-typescript/packages/rivetkit/src/drivers/engine/actor-driver.ts
Outdated
Show resolved
Hide resolved
5ad7f89 to
8e33967
Compare
7973ad8 to
635c1c0
Compare
635c1c0 to
75c97ad
Compare
Code Review: WebSocket Message Acknowledgment DebouncingI've reviewed this PR and have the following feedback: Positive Changes
Issues & Concerns1. Type Mismatch:
|
Code Review: WebSocket Message Acknowledgment DebouncingI've reviewed this PR which adds debouncing for WebSocket message acknowledgments. Overall, the approach is sound and addresses the issue of reducing buffered messages on the gateway. However, I've identified several critical issues that need to be addressed: Critical Issues1. Type Mismatch:
|
75c97ad to
2baa4b7
Compare
Pull Request Review: WebSocket Message Acknowledgment DebouncingSummaryThis PR implements debouncing for WebSocket message acknowledgments to reduce network overhead by batching acks and sending only the highest message index per request. The implementation adds a 1-second flush interval and properly handles cleanup on shutdown. Code Quality ✅Strengths:
Minor Concerns:
Potential Bugs 🐛
Performance Considerations ⚡Positive impacts:
Considerations:
Security Concerns 🔒No significant security concerns identified. The implementation:
Test Coverage 📋Missing test coverage:
Consider adding tests in a file like RecommendationsHigh Priority:
Medium Priority:
Low Priority:
Overall AssessmentThis is a solid implementation that addresses a real performance concern. The code is clean and well-integrated with the existing architecture. The main gaps are around test coverage and some minor improvements to observability. With the suggested fixes, this PR will be production-ready. Recommendation: Approve with minor changes ✅ Great work on improving WebSocket performance! |
Merge activity
|

No description provided.