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.
perf: optimize IsEquals and ToMap to reduce allocations #3402
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: develop
Are you sure you want to change the base?
perf: optimize IsEquals and ToMap to reduce allocations #3402
Changes from all commits
6a5d4c4File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
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.
paramCount单独加锁读一次,后面RangeParams又加锁遍历一次,多了一次锁操作。fixedCount只是容量估算,不影响逻辑;估多了也只是多分一点内存。protocol、host、port这些 key,后面的固定字段会覆盖它们,fixedCount仍然按新增 key 算,容量也会估大。建议就是保留容量估算,去掉无意义初始化,并确保
protocol/location行为不变。Uh oh!
There was an error while loading. Please reload this page.
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.
ToMap的多地址 port 解析语义被改了原逻辑对
127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183的port是2181,127.0.0.1确实不合理,PR 改成取最后一个
:后的2183。也不合理这里改成合理的逻辑,然后在pr简介里面说明
Check failure on line 1033 in common/url.go
Refactor this method to reduce its Cognitive Complexity from 35 to the 15 allowed.
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.
[P1] 这里把
host/port的排除逻辑挂在整条Location上了:只传host或只传port时,left.Location != right.Location也会直接落入“放行”分支,另一半地址差异被一并忽略。旧实现是按ToMap()删除单个 key 比较,两个字段的排除语义是独立的。请分别比较 host/port,或保留原来的按键删除语义。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.
IsEquals在只 excludehost或port时会漏比较另一半 locationPR 里当
left.Location != right.Location且只排除host或port其中一个时,代码直接“fall through”,但后面只比较 params,不再比较未被排除的 host/port。你试一下
Location: 10.0.0.1:20880vs10.0.0.2:20880,excludeport后 PR 返回true,base 返回false。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.
这里可以做个容量预估,len(left.params) 就有了
Uh oh!
There was an error while loading. Please reload this page.
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.
不用自己写benchmark 直接复用已有的benchmark 或者在benchmark文件里面添加你需要的benchmark
Uh oh!
There was an error while loading. Please reload this page.