Skip to content

perf: Optimize the performance of the comparator#5198

Merged
shaohuzhang1 merged 9 commits into
1Panel-dev:v2from
wangliang181230:PR/perf-compare
Apr 29, 2026
Merged

perf: Optimize the performance of the comparator#5198
shaohuzhang1 merged 9 commits into
1Panel-dev:v2from
wangliang181230:PR/perf-compare

Conversation

@wangliang181230

@wangliang181230 wangliang181230 commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it?

perf: Optimize the performance of the comparator

Summary of your change

优化 比较器 的性能:

  1. 比较器 list 改为 dict,然后直接 get 来获取判断处理器。

    做过此优化后,Compare.support 方法不再需要了,接口以及所有实现类中,删除该方法。

  2. 不使用 allany,避免不需要执行的判断条件也执行了,浪费性能

    同时,封装了 do_assertion 方法,供其他地方使用。

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

@f2c-ci-robot

f2c-ci-robot Bot commented Apr 28, 2026

Copy link
Copy Markdown

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.

Details

Instructions 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.

@f2c-ci-robot

f2c-ci-robot Bot commented Apr 28, 2026

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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

@wangliang181230 wangliang181230 Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

性能提升2:不使用 allany 函数,避免所有判断条件都会执行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)

@wangliang181230 wangliang181230 Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

性能提升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')},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix style

class Compare:
@abstractmethod
def support(self, node_id, fields: List[str], source_value, compare, target_value):
pass

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接通过 dict 的 key 进行匹配获取,不再需要 support 方法,所有实现类的该方法全部删除。

@wangliang181230 wangliang181230 changed the title perf: Optimize the performance of the Conditional Branch perf: Optimize the performance of the Conditional Branch node Apr 29, 2026
@wangliang181230 wangliang181230 changed the title perf: Optimize the performance of the Conditional Branch node perf: Optimize the performance of the comparator Apr 29, 2026
@shaohuzhang1 shaohuzhang1 merged commit dfedc24 into 1Panel-dev:v2 Apr 29, 2026
1 of 3 checks passed
@wangliang181230 wangliang181230 deleted the PR/perf-compare branch April 29, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants