lightning: please refactor and optimize the function `SplitAndScatterRegionByRanges`
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
Hi,
Could you please refactor and optimize the function `SplitAndScatterRegionByRanges`,
**please refactor**: Long functions(almost 300 rows) and a high level of nesting( recommend to control the depth of {} to 3) increase the maintenance cost of the entire function, making it difficult for our reviewers(users) to understand.
https://github.com/pingcap/tidb/blob/1bf82bbaaa71a86a5b3245e7b902e92deba78ce6/br/pkg/lightning/backend/local/localhelper.go#L137-L400
**please optimize**: I noticed that there is room for improvement in certain areas. for example the following part, I think the ranges and regions are both sorted, binary search enlarge the complex with O(M*logN), while O(N+M) is enough and easier to understand. https://github.com/pingcap/tidb/blob/1bf82bbaaa71a86a5b3245e7b902e92deba78ce6/br/pkg/lightning/backend/local/localhelper.go#L203-L218
Contributor guide
Assessment
This issue has not been assessed yet.