[WIP]CSharp模块性能优化 #62
Open
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.
@yndu13 您好,该项目涉及到阿里云SDK,希望能为本项目做一点贡献,提升.NET SDK的质量。
以下是PR具体内容。其中“可选的优化”因改动较大并未实现,属个人意见供贵方参考。
StringUtils
重写查找子字符串数量的实现,实现0内存分配下更好的性能表现
可选的优化:该方法仅用于
StringUtils.SubStringCount(node[0].OuterXml, realName) > 1)
,那么判断字符串大于1即可停止查找。XmlUtil
将字典的
ContainsKey
修改为TryGetValue
,减少多余的Hash查找在条件允许的情况下,指定初始化的字典Capacity,减少底层扩容带来的性能损耗和内存浪费
使用
string.IsNullOrWhiteSpace
替换string.IsNullOrEmpty
和string.Trim
,减少特定情况下的内存分配使用Linq
First()
替换ToList()[0]
,减少内存分配使用
GetCustomAttribute<T>
泛型重载方法,精简代码可选的优化:
mapObj
方法里较多的if-else
判断propertyType
,一方面时间复杂度会随着分支数呈现O(n)级别的上升,另一方面会影响CPU的指令预测并增加Cache Miss。或许可采用如下实现: