Comments (7)
@dellbeat 久等了, 我用 System.Reflection.Emit
去调用 JsonDocument.GetRawdata
方法了, 交给JIT生成asm后就不用考虑平台差异了
更新至2.1.6即可
附性能测试结果:
| Method | Mean | Error | StdDev | Gen 0 | Allocated |
|------------------ |---------:|--------:|--------:|-------:|----------:|
| ParseByPtr | 589.4 ns | 2.52 ns | 2.36 ns | 0.0496 | 528 B |
| ParseByReflection | 754.6 ns | 2.96 ns | 2.62 ns | 0.0610 | 648 B |
| ParseByEmit | 591.5 ns | 3.36 ns | 2.98 ns | 0.0496 | 528 B |
from mirai-csharp.
和我用的奇技淫巧有关, 我会考虑加个检查的
Mirai-CSharp/Mirai-CSharp.HttpApi/Utility/Utils.cs
Lines 25 to 65 in 430f2f4
from mirai-csharp.
from mirai-csharp.
from mirai-csharp.
人有点晕, 找了半天没找到有什么黑科技能更加安全地调用 ReadOnlyMemory<byte> JsonDocument.GetRawValue(int, bool)
这个非公共方法的, 等我继续钻研一下
期间你可以把这一段改成下边这个凑合着用用
Mirai-CSharp/Mirai-CSharp.HttpApi/Utility/Utils.cs
Lines 25 to 31 in 430f2f4
private static readonly MethodInfo _method = typeof(JsonDocument).GetMethod("GetRawValue", BindingFlags.NonPublic | BindingFlags.Instance)!;
public static T Deserialize<T>(this JsonElement element, JsonSerializerOptions? options = null)
{
JsonDocument documentRef = Unsafe.As<JsonElement, JsonDocument>(ref element);
int idx = Unsafe.AddByteOffset(ref Unsafe.As<JsonElement, int>(ref element), new IntPtr(IntPtr.Size));
ReadOnlyMemory<byte> memory = (ReadOnlyMemory<byte>)_method.Invoke(documentRef, new object[] { idx, true })!;
return JsonSerializer.Deserialize<T>(memory.Span)!;
}
from mirai-csharp.
那大佬先钻研着
我这边收消息之前用自制ws先混过去了XD
from mirai-csharp.
from mirai-csharp.
Related Issues (20)
- 请教一下关于Linux系统缺库的问题 HOT 2
- 依赖注入无效 HOT 17
- 如何接收并回复群临时消息 HOT 13
- 添加对cq-http的支持 HOT 1
- 哪个,您好······我想请教 一个问题,关于linux发布的问题 HOT 6
- 不知道是不是有图片属性的原因,有一张图片上传的时候会报错 HOT 4
- 如何让Bot发送一条自定义转发消息? HOT 4
- GetUserProfileAsync失败(已找到解决办法,麻烦作者修复这个问题) HOT 1
- 更新一次README
- 2.1.9计划 HOT 2
- 示例代码 AddParser 报错 HOT 6
- p站图片消息撤回失败 HOT 18
- 发送好友消息中一条消息链里同时存在文字和图片,别人收不到 HOT 4
- 使用MemoryStream构建VoiceMessage手机端接收听不了 HOT 7
- [BUG] OtherClientMessag无法接收 HOT 4
- 关于Bot被禁言事件 HOT 1
- 关于图片上传产生的临时文件 HOT 2
- 部分用户发送ForwardMessage失败 HOT 14
- 请问支持发送amr格式的音频流吗? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mirai-csharp.