-
Notifications
You must be signed in to change notification settings - Fork 2.9k
perf: Optimize the performance of the comparator #5198
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c4e2c8b
perf: Optimize the compare
wangliang181230 e2fe120
perf: 避免 `判断器` 执行所有条件分支
wangliang181230 ee96680
perf: 判断器,添加日志
wangliang181230 a41a379
小调整
wangliang181230 71cff93
小调整
wangliang181230 7e357b7
clean import
wangliang181230 1eab9c0
clean import
wangliang181230 96cde90
clean import
wangliang181230 eefae54
add import
wangliang181230 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,31 +6,78 @@ | |
| @date:2024/6/7 14:43 | ||
| @desc: | ||
| """ | ||
| from typing import List | ||
|
|
||
| from .contain_compare import * | ||
| from .contain_compare import ContainCompare | ||
| from .end_with import EndWithCompare | ||
| from .equal_compare import * | ||
| from .ge_compare import * | ||
| from .gt_compare import * | ||
| from .is_not_null_compare import * | ||
| from .equal_compare import EqualCompare | ||
| from .ge_compare import GECompare | ||
| from .gt_compare import GTCompare | ||
| from .is_not_null_compare import IsNotNullCompare | ||
| from .is_not_true import IsNotTrueCompare | ||
| from .is_null_compare import * | ||
| from .is_null_compare import IsNullCompare | ||
| from .is_true import IsTrueCompare | ||
| from .le_compare import * | ||
| from .len_equal_compare import * | ||
| from .len_ge_compare import * | ||
| from .len_gt_compare import * | ||
| from .len_le_compare import * | ||
| from .len_lt_compare import * | ||
| from .lt_compare import * | ||
| from .not_contain_compare import * | ||
| from .not_equal_compare import * | ||
| from .le_compare import LECompare | ||
| from .len_equal_compare import LenEqualCompare | ||
| from .len_ge_compare import LenGECompare | ||
| from .len_gt_compare import LenGTCompare | ||
| from .len_le_compare import LenLECompare | ||
| from .len_lt_compare import LenLTCompare | ||
| from .lt_compare import LTCompare | ||
| from .not_contain_compare import NotContainCompare | ||
| from .not_equal_compare import NotEqualCompare | ||
| from .regex_compare import RegexCompare | ||
| from .start_with import StartWithCompare | ||
| from .wildcard_compare import WildcardCompare | ||
|
|
||
| compare_handle_list = [GECompare(), GTCompare(), ContainCompare(), EqualCompare(), LTCompare(), LECompare(), | ||
| LenLECompare(), LenGECompare(), LenEqualCompare(), LenGTCompare(), LenLTCompare(), | ||
| IsNullCompare(), | ||
| IsNotNullCompare(), NotContainCompare(), NotEqualCompare(), IsTrueCompare(), IsNotTrueCompare(), StartWithCompare(), | ||
| EndWithCompare(), RegexCompare(), WildcardCompare()] | ||
| _compare_handler_dict = { | ||
| 'is_null': IsNullCompare(), | ||
| 'is_not_null': IsNotNullCompare(), | ||
| 'contain': ContainCompare(), | ||
| 'not_contain': NotContainCompare(), | ||
| 'eq': EqualCompare(), | ||
| 'not_eq': NotEqualCompare(), | ||
| 'ge': GECompare(), | ||
| 'gt': GTCompare(), | ||
| 'le': LECompare(), | ||
| 'lt': LTCompare(), | ||
| 'len_eq': LenEqualCompare(), | ||
| 'len_ge': LenGECompare(), | ||
| 'len_gt': LenGTCompare(), | ||
| 'len_le': LenLECompare(), | ||
| 'len_lt': LenLTCompare(), | ||
| 'is_true': IsTrueCompare(), | ||
| 'is_not_true': IsNotTrueCompare(), | ||
| 'start_with': StartWithCompare(), | ||
| 'end_with': EndWithCompare(), | ||
| 'regex': RegexCompare(), | ||
| 'wildcard': WildcardCompare(), | ||
| } | ||
|
|
||
|
|
||
| def _compare(source_value, compare, target_value): | ||
| 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) | ||
|
|
||
|
|
||
| def _assertion(workflow_manage, field_list: List[str], compare: str, value): | ||
| try: | ||
| value = workflow_manage.generate_prompt(value) | ||
| except Exception: | ||
| pass | ||
| field_value = None | ||
| try: | ||
| field_value = workflow_manage.get_reference_field(field_list[0], field_list[1:]) | ||
| except Exception: | ||
| pass | ||
| return _compare(field_value, compare, value) | ||
|
|
||
|
|
||
| def do_assertion(workflow_manage, condition, condition_list): | ||
| b = False if condition == 'and' else True | ||
| 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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 性能提升2:不使用 |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,13 +7,8 @@ | |
| @desc: | ||
| """ | ||
| from abc import abstractmethod | ||
| from typing import List | ||
|
|
||
|
|
||
| class Compare: | ||
| @abstractmethod | ||
| def support(self, node_id, fields: List[str], source_value, compare, target_value): | ||
| pass | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 直接通过 dict 的 key 进行匹配获取,不再需要 support 方法,所有实现类的该方法全部删除。 |
||
|
|
||
| @abstractmethod | ||
| def compare(self, source_value, compare, target_value): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
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.
性能提升1:处理器列表由
list改成dict,直接获取处理器,性能更高。