-
Notifications
You must be signed in to change notification settings - Fork 493
JsonRpcMessage.Converter.Read optimization #639
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
Open
Scooletz
wants to merge
6
commits into
modelcontextprotocol:main
Choose a base branch
from
Scooletz:json-rpc-message-converter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+203
−27
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f6fc863
Add BenchmarkDotNet project for JSON-RPC message deserialization
Scooletz 2bceacf
fixed namespaces and ignores
Scooletz 7c01d9f
union based deserialization
Scooletz f1fbfcb
Union internalized
Scooletz ab67a87
Merge branch 'main' into json-rpc-message-converter
Scooletz f38ddd1
Merge branch 'main' into json-rpc-message-converter
eiriktsarpalis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
72 changes: 72 additions & 0 deletions
72
benchmarks/ModelContextProtocol.Benchmarks/JsonRpcMessageSerializationBenchmarks.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using BenchmarkDotNet.Attributes; | ||
using ModelContextProtocol.Protocol; | ||
|
||
namespace ModelContextProtocol.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class JsonRpcMessageSerializationBenchmarks | ||
{ | ||
private byte[] _requestJson = null!; | ||
private byte[] _notificationJson = null!; | ||
private byte[] _responseJson = null!; | ||
private byte[] _errorJson = null!; | ||
|
||
private JsonSerializerOptions _options = null!; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_options = McpJsonUtilities.DefaultOptions; | ||
|
||
_requestJson = JsonSerializer.SerializeToUtf8Bytes( | ||
new JsonRpcRequest | ||
{ | ||
Id = new RequestId("1"), | ||
Method = "test", | ||
Params = JsonValue.Create(1) | ||
}, | ||
_options); | ||
|
||
_notificationJson = JsonSerializer.SerializeToUtf8Bytes( | ||
new JsonRpcNotification | ||
{ | ||
Method = "notify", | ||
Params = JsonValue.Create(2) | ||
}, | ||
_options); | ||
|
||
_responseJson = JsonSerializer.SerializeToUtf8Bytes( | ||
new JsonRpcResponse | ||
{ | ||
Id = new RequestId("1"), | ||
Result = JsonValue.Create(3) | ||
}, | ||
_options); | ||
|
||
_errorJson = JsonSerializer.SerializeToUtf8Bytes( | ||
new JsonRpcError | ||
{ | ||
Id = new RequestId("1"), | ||
Error = new JsonRpcErrorDetail { Code = 42, Message = "oops" } | ||
}, | ||
_options); | ||
} | ||
|
||
[Benchmark] | ||
public JsonRpcMessage DeserializeRequest() => | ||
JsonSerializer.Deserialize<JsonRpcMessage>(_requestJson, _options)!; | ||
|
||
[Benchmark] | ||
public JsonRpcMessage DeserializeNotification() => | ||
JsonSerializer.Deserialize<JsonRpcMessage>(_notificationJson, _options)!; | ||
|
||
[Benchmark] | ||
public JsonRpcMessage DeserializeResponse() => | ||
JsonSerializer.Deserialize<JsonRpcMessage>(_responseJson, _options)!; | ||
|
||
[Benchmark] | ||
public JsonRpcMessage DeserializeError() => | ||
JsonSerializer.Deserialize<JsonRpcMessage>(_errorJson, _options)!; | ||
} |
19 changes: 19 additions & 0 deletions
19
benchmarks/ModelContextProtocol.Benchmarks/ModelContextProtocol.Benchmarks.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\ModelContextProtocol.Core\ModelContextProtocol.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using BenchmarkDotNet.Running; | ||
|
||
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); |
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
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.