-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[dotnet] [bidi] Cache modules in the root BiDi #16655
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
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨No code suggestions found for the PR. |
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.
Pull request overview
This PR refactors the BiDi class to use lazy-loaded module properties instead of eager initialization in the constructor. The change aims to defer module creation until first use by leveraging the existing AsModule caching mechanism.
Key Changes:
- Removed eager module initialization from the constructor (10 modules previously initialized upfront)
- Converted module properties from auto-properties to expression-bodied properties that call
AsModule<T>() - Reduced initial memory allocation by deferring module creation until accessed
Comments suppressed due to low confidence (1)
dotnet/src/webdriver/BiDi/BiDi.cs:88
- The
GetOrAddcall uses the wrong overload, causingGetJsonOptions()andModule.Create<T>()to be evaluated on every property access, even when the module is already cached. This defeats the purpose of the lazy-loading optimization. Use the factory overload instead:return (T)_modules.GetOrAdd(typeof(T), _ => Module.Create<T>(this, Broker, GetJsonOptions()));
return (T)_modules.GetOrAdd(typeof(T), Module.Create<T>(this, Broker, GetJsonOptions()));
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Nice catch! |
|
Move forward, in any case we can revert it back. |
User description
Unify allocation of modules when needed only.
🔧 Implementation Notes
Just cache. For both internal modules and external.
💡 Additional Considerations
I believe that checking cached object in
ConcurrentDictionaryis faster than allocating new object. Didn't verify it.🔄 Types of changes
PR Type
Enhancement
Description
Replace eager module initialization with lazy-loaded cached properties
Remove redundant module assignments from constructor
Leverage AsModule caching for on-demand module instantiation
Simplify BiDi class initialization logic
Diagram Walkthrough
File Walkthrough
BiDi.cs
Convert modules to lazy-loaded cached propertiesdotnet/src/webdriver/BiDi/BiDi.cs
properties
AsModule()on access, leveraging internalcaching