-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[dotnet] [bidi] Deserialize message fast instead of defer it #16403
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: trunk
Are you sure you want to change the base?
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 ✨Explore these optional code suggestions:
|
Finally, no Gen2 and Gen1 allocations. |
|
||
private readonly ConcurrentDictionary<long, CommandInfo> _pendingCommands = new(); | ||
private readonly BlockingCollection<MessageEvent> _pendingEvents = []; | ||
private readonly ConcurrentDictionary<long, CommandInfo<EmptyResult>> _pendingCommands = new(); |
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.
CommandInfo<T>
always seems to be CommandInfo<EmptyResult>
. It does not need to be generic.
class CommandInfo(long id, TaskCompletionSource<EmptyResult> taskCompletionSource, JsonTypeInfo jsonResultTypeInfo)
{
public long Id { get; } = id;
public TaskCompletionSource<EmptyResult> TaskCompletionSource { get; } = taskCompletionSource;
public JsonTypeInfo JsonResultTypeInfo { get; } = jsonResultTypeInfo;
}
|
||
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; } = contexts; | ||
|
||
public abstract ValueTask InvokeAsync(object args); |
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.
We can make this slightly more strongly-typed.
public abstract ValueTask InvokeAsync(object args); | |
public abstract ValueTask InvokeAsync(EventArgs args); |
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.
Two tiny comments, in general I really like this change! One more leap towards great performance.
User description
Review after #16402
💥 What does this PR do?
As soon as we received remote message just deserialize it. It also improves memory consumption because of unnecessary
JsonElement
object.Before:
After:
🔄 Types of changes
PR Type
Enhancement
Description
Optimize BiDi message deserialization for better performance
Replace deferred JsonElement with immediate type-specific deserialization
Reduce memory allocation by ~33% in node location operations
Improve screenshot capture performance by ~2ms
Diagram Walkthrough
File Walkthrough
Broker.cs
Core broker deserialization optimization
dotnet/src/webdriver/BiDi/Communication/Broker.cs
events
JsonElement
type info
BrowsingContextModule.cs
BrowsingContext event subscription updates
dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs
NetworkModule.cs
Network event subscription updates
dotnet/src/webdriver/BiDi/Network/NetworkModule.cs
ScriptModule.cs
Script event subscription updates
dotnet/src/webdriver/BiDi/Script/ScriptModule.cs
LogModule.cs
Log event subscription updates
dotnet/src/webdriver/BiDi/Log/LogModule.cs