[rb] render WebSocket debug log lines lazily - #18033
Merged
titusfortner merged 2 commits intoSep 15, 2026
Merged
Conversation
WebSocketConnection#send_cmd and #process_frame build the "WebSocket -> ..." and "WebSocket <- ..." strings before handing them to WebDriver.logger.debug, so every frame pays a deep Hash#inspect even though the logger discards the line at its default level. A BiDi session receives one frame per network event, so a page with many assets renders each of them for nothing; profiling a Firefox BiDi worker showed the inspect at about 3% of on-CPU time. Pass the frame to the logger as a block instead. Logger#debug already documents the block as appended to the message and only yields once the level check has passed, so the output at debug level is unchanged.
Contributor
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Member
|
/agentic_review |
Contributor
Code Review by Qodo
1. WebSocket debug lines gain an extra gap
|
Contributor
Member
|
@ikraamg thank you! |
This was referenced Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Related Issues
None filed; the reproduction below shows the cost directly.
💥 What does this PR do?
WebSocketConnection#send_cmdand#process_framebuild the"WebSocket -> …"/"WebSocket <- …"strings before callingWebDriver.logger.debug, so every frame pays a deepHash#inspecteven though the logger discards the line at its default level. A BiDi session gets one frame per network event, so a page with many assets renders each of them for nothing.This passes the frame to the logger as a block instead.
Logger#debugalready documents the block as "appended to the end of the provided template" anddiscard_or_logonly yields once the level check has passed, so output at debug level is unchanged.Standalone reproduction against selenium-webdriver 4.48.0 on Ruby 4.0.6, feeding a 4.3 KB
network.responseCompletedframe throughprocess_frame5,000 times at the default logger level:On a production Firefox BiDi worker (rbspy, 90 s, 100 Hz), the
Hash#inspectunderprocess_framewas about 3% of on-CPU time on the listener thread; after this change it no longer appears.Reproduction script
🔧 Implementation Notes
The alternative was
return msg unless WebDriver.logger.debug?-style guards at each call site, but the logger's block form exists for exactly this and keeps theid: :wsfiltering in one place. The three new unit examples usedescribed_class.allocatelike the rest of the spec; two of them fail on trunk.🤖 AI assistance
💡 Additional Considerations
None. No public API or
.rbschange.🔄 Types of changes