Skip to content

[dotnet] [bidi] Eliminate BiDi context on hot path - #18069

Merged
nvborisenko merged 1 commit into
SeleniumHQ:trunkfrom
nvborisenko:bidi-eliminate-scope
Sep 23, 2026
Merged

nvborisenko merged 1 commit into
SeleniumHQ:trunkfrom
nvborisenko:bidi-eliminate-scope

Conversation

@nvborisenko

Copy link
Copy Markdown
Member

Improve performance and memoty allocation.

💥 What does this PR do?

This pull request refactors the BiDiContext class and streamlines its usage across the BiDi WebDriver implementation. The main goal is to simplify context management by making BiDiContext a static class that directly holds the IBiDi instance, eliminating unnecessary object wrapping. Additionally, the pull request cleans up redundant context scoping in several methods and ensures correct usage of the new context pattern.

Refactoring and simplification of BiDi context management:

  • Converted BiDiContext from a sealed class to a static class, storing the IBiDi instance directly in the AsyncLocal, and removed the unnecessary BiDiContext wrapper object. (dotnet/src/webdriver/BiDi/BiDiContext.cs)
  • Updated the IdentifiableConverter to use the new static BiDiContext.Current directly, instead of accessing .BiDi from a context object. (dotnet/src/webdriver/BiDi/Json/Converters/IdentifiableConverter.cs)

Cleanup and correct scoping in BiDi broker:

  • Removed redundant usage of BiDiContext.Use in ExecuteAsync and ProcessReceivedMessage, as the context is now managed at a higher level. (dotnet/src/webdriver/BiDi/Broker.cs) [1] [2] [3]
  • Ensured that BiDiContext.Use is invoked once at the start of ProcessMessagesAsync, so all message processing occurs within the correct context scope. (dotnet/src/webdriver/BiDi/Broker.cs)

🔧 Implementation Notes

🤖 AI assistance

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s):
    • What was generated:
    • I reviewed all AI output and can explain the change

🔄 Types of changes

  • Cleanup (formatting, renaming)

@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

All reviewed changes are coherent, with no unresolved issues.

Review effort: Balanced
Findings: None

What changed in this PR

Refactors .NET BiDi context handling to reduce hot-path allocations while preserving message-processing context.

Changes:

  • Stores IBiDi directly in AsyncLocal.
  • Consolidates broker context scoping.
  • Updates identifiable-object deserialization.
File Description
dotnet/​src/​webdriver/​BiDi/​Json/​Converters/​IdentifiableConverter.cs Uses the current IBiDi directly.
dotnet/​src/​webdriver/​BiDi/​Broker.cs Applies context once around message processing.
dotnet/​src/​webdriver/​BiDi/​BiDiContext.cs Simplifies context storage and restoration.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@nvborisenko
nvborisenko merged commit 7c76fa0 into SeleniumHQ:trunk Sep 23, 2026
27 checks passed
@nvborisenko
nvborisenko deleted the bidi-eliminate-scope branch September 23, 2026 16:39
This was referenced Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-dotnet .NET Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants