Merged
[performance]enhanced the process of ccu max delay to lowered the time complexity from o(mn) to o(m+n) #343
xieanranAdd on Jul 7
[performance]enhanced the process of ccu max delay to lowered the time complexity from o(mn) to o(m+n) #343
Merged
xieanranAdd on Jul 7
xieanran
xieanranCollaborators
Jul 7

PR 合入模板

注:经过自检不涉及的可标注“不涉及”或直接打勾,特殊情况请文字备注。不符合规范的 PR 不允许合入,请(后备)commit 注意。


1. 修改描述

  • 修改原因: ccu 寻找max delay慢,需要优化
  • 修改内容: 优化了 CCU 最大延迟通道查找算法,从 O(mn) 降至 O(m+n),新增一条 channelId=4 的测试数据
    后续优化方向:看看能不能压缩channel id,目前看虽然算法是o(m+n),已降至线性,其次可以看下能否优化匹配算法本身。

2. 功能验证

  • 功能自验
    image.png
  • 本地自验用例截图
  • 冒烟是否通过 (填入群链接的自验证报告中,如未通过,请说明原因:____________________ ,功能代码请主动申报添加冒烟)

3. 分支合并要求

  • 代码合并(请确保将 master 分支的最新代码同步合并至 poc 分支及 pre-research 分支,同时保证 poc 分支的代码也已正确合并到 pre-research 分支。)

3. 代码检视

  • 要求:

    • 合入代码超过 200 行,需三人以上会议检视。
    • 检视密度≥1个/100行。
    • 检视缺陷密度未达要求需提供说明。
    • 大于 1000 行代码原则上不允许合入,需进行备案。
  • 是否经过代码检视

  • 是否具备 UT 测试用例看护 (如不符合,请说明原因:____________________)

  • 检视意见数:____ 条 (请填写本次检视的意见总数,用于commit合入前审视)


4. 安全自检

Python、C++

  • 对外接口新增/删除/变更后,资料要同步新增/删除/变更,新增接口入参校验参考外部输入表格
  • 不允许私有的文件操作,需要使用公共模块的安全函数
  • 任务结束后需要删除临时文件,同时需要考虑任务失败后,临时文件没有残留
  • 数组访问需要校验越界场景,对除法需要做除零校验
  • 需要对递归方法做递归深度校验,正则表达式必须做 ReDoS 校验
  • 需要充分进行接口输入和返回值异常情况的校验
  • 日志打印不要出现拼写或语法错误,不要暴露代码细节和敏感信息

C++

  • 指针使用前需要判空
  • 数值计算校验溢出和反转
  • 不可存在内存泄漏(异常场景需要释放内存)
  • 类型转换不能出现数据截断
  • 拷贝字符串时,目的缓冲区至少比源缓冲区大 1
  • 拷贝内存时,目的缓冲区不小于源缓冲区
  • 内存释放后指针赋值为 nullptr

5. 变更知会

  • 资料修改
  • 变更通知(消息知会 + 邮件知会)

likedislike
Pull Request has been successfully merged by ascend-robot.
(Thank you for xieanran's contribution.)
atomgit-bot
atomgit-bot
Jul 7 Comments:

变更摘要

此 PR 优化了 CCU 最大延迟通道查找算法,将时间复杂度从 O(m×n) 降至 O(m+n)。核心思路是通过预构建前缀最大值索引(BuildChannelIndex),将原来每次查询时遍历全部通道数据改为对预排序数组进行二分查找。C++ 端新增 CCUChannelPrefixInfo 结构和 BuildChannelIndex 函数,并重构 GetMaxDelayChannel;Python 端同样采用按 channel_id 预分类字典替代原有的列表过滤方式,使查找操作从线性扫描优化为 O(1) 索引。

主要改动

  • 新增 CCUChannelPrefixInfo 结构与 BuildChannelIndex 函数:在 ccu_mission_processor.cpp 中引入前缀最大值索引结构,按 channelId 分组、按时间戳排序后,为每条记录预计算当前最大延迟(prefix max);BuildChannelIndexFormatWaitTimelineData 中仅调用一次,后续所有 GetMaxDelayChannel 查询共享该索引。
  • 重构 GetMaxDelayChannel 使用二分查找:将原来的两层嵌套遍历(hostData × channelData)改为对 CCUChannelIndexstd::lower_bound 二分查找,通过 recordIter->maxDelay 直接获取当前时间点前的最大延迟通道,避免了原先对全体 channel 数据的重复扫描。
  • Python 端 get_max_delay_channel_and_channel_delay 采用预分类字典channel_data 参数类型从 list 改为 dict,在 get_formatted_wait_data 中通过 defaultdict(list)channel_id 预分类通道数据,使最大延迟通道查找从 O(n) 过滤降为 O(1) 直接索引。
  • 单元测试补充边界用例:在 ccu_mission_processor_utest.cppBuildChannelData 中新增一条 channelId=4 的测试数据 {4, 9000, 0, 0, 999},用于覆盖同一 channelId 存在多条记录时前缀索引的正确性。
likedislike
Incorrect?
77 messages are collapsed here。 See more
ascend-robot
ascend-robotCollaborators
Jul 9 Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
chenhao_1209CollaboratorsJul 9Start code review1
analysis/viewer/ccu/ccu_mission_viewer.py
@@ -85,2 +95,4 @@
95+ 
96+ seq_channel = [channel for channel in within_channel if channel.timestamp < mission_data.end_time]
8597 if seq_channel:
8698 max_delay_channel = max(seq_channel, key=lambda x: x.avg_bw)
chenhao_1209Jul 9Comments:

【review】【设计】Python 端的 get_max_delay_channel_and_channel_delay 仍使用 max(seq_channel, key=lambda x: x.avg_bw) 计算最大延迟通道,但 avg_bw 是平均带宽,不是延迟(delay)。字段名 avg_bw 与语义 max_delay_channel 不符。,建议修改:应该使用 avg_delay 而非 avg_bw 来计算最大延迟通道

likedislike
chenhao_1209CollaboratorsJul 9Start code review1
analysis/csrc/domain/data_process/ai_task/ccu_mission_processor.cpp
@@ -116,1 +126,3 @@
116- maxDelay.channelDelay = channel.avgDelay;
126+ continue;
127+ }
128+ --recordIter;
chenhao_1209Jul 9Comments:

【review】【编码】调用位置对--recordIter的取值,是对 lower_bound 返回的前一个元素取值,但 lower_bound 返回的是 >= missionData.endTime 的第一个元素,因此 --recordIter 是 timestamp < endTime 的最大元素。但当 channelRecords 中有多个相同 timestamp 的记录,lower_bound 可能返回第一个 >= endTime 的元素,而 prefix 中该位置的 maxDelay 可能不是该 timestamp 下所有记录合并后的最大值。建议在 BuildChannelIndex 中处理相同 timestamp 的情况。

likedislike
xieanranxieanranCollaborators
Jul 9 Resolved final issue
ascend-robot
ascend-robotCollaborators
Jul 9 Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike