perf: Optimize the performance of the comparator#5198
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| for row in condition_list: | ||
| if _assertion(workflow_manage, row.get('field'), row.get('compare'), row.get('value')) is b: | ||
| return b | ||
| return not b |
There was a problem hiding this comment.
性能提升2:不使用 all 和 any 函数,避免所有判断条件都会执行compare,性能较差。
| compare_handler = _compare_handler_dict.get(compare) | ||
| if compare_handler is None: | ||
| raise RuntimeError(f"Unknown compare handler '{compare}'") | ||
| return compare_handler.compare(source_value, compare, target_value) |
There was a problem hiding this comment.
性能提升1:处理器列表由 list 改成 dict,直接获取处理器,性能更高。
| { value: 'regex', label: t('workflow.compare.regex') }, | ||
| { value: 'wildcard', label: t('workflow.compare.wildcard') }, | ||
| {value: 'regex', label: t('workflow.compare.regex')}, | ||
| {value: 'wildcard', label: t('workflow.compare.wildcard')}, |
| class Compare: | ||
| @abstractmethod | ||
| def support(self, node_id, fields: List[str], source_value, compare, target_value): | ||
| pass |
There was a problem hiding this comment.
直接通过 dict 的 key 进行匹配获取,不再需要 support 方法,所有实现类的该方法全部删除。
Conditional BranchConditional Branch node
Conditional Branch node
What this PR does / why we need it?
perf: Optimize the performance of the comparator
Summary of your change
优化
比较器的性能:list改为dict,然后直接get来获取判断处理器。all和any,避免不需要执行的判断条件也执行了,浪费性能Please indicate you've done the following: