-
Notifications
You must be signed in to change notification settings - Fork 10.5k
FIX recursive_will_execute performance (simple ~300x performance increase} #2852
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 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -194,8 +194,12 @@ def recursive_execute(server, prompt, outputs, current_item, extra_data, execute | |
|
|
||
| return (True, None, None) | ||
|
|
||
| def recursive_will_execute(prompt, outputs, current_item): | ||
| def recursive_will_execute(prompt, outputs, current_item, memo={}): | ||
| unique_id = current_item | ||
|
|
||
| if unique_id in memo: | ||
| return memo[unique_id] | ||
|
|
||
| inputs = prompt[unique_id]['inputs'] | ||
| will_execute = [] | ||
| if unique_id in outputs: | ||
|
|
@@ -207,9 +211,10 @@ def recursive_will_execute(prompt, outputs, current_item): | |
| input_unique_id = input_data[0] | ||
| output_index = input_data[1] | ||
| if input_unique_id not in outputs: | ||
| will_execute += recursive_will_execute(prompt, outputs, input_unique_id) | ||
| will_execute += recursive_will_execute(prompt, outputs, input_unique_id, memo) | ||
|
|
||
| return will_execute + [unique_id] | ||
| memo[unique_id] = will_execute + [unique_id] | ||
| return memo[unique_id] | ||
|
|
||
| def recursive_output_delete_if_changed(prompt, old_prompt, outputs, current_item): | ||
| unique_id = current_item | ||
|
|
@@ -377,7 +382,8 @@ def execute(self, prompt, prompt_id, extra_data={}, execute_outputs=[]): | |
|
|
||
| while len(to_execute) > 0: | ||
| #always execute the output that depends on the least amount of unexecuted nodes first | ||
| to_execute = sorted(list(map(lambda a: (len(recursive_will_execute(prompt, self.outputs, a[-1])), a[-1]), to_execute))) | ||
| memo = {} | ||
|
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. memo should be created outside the lambda so it is reused for entire sorting algorithm |
||
| to_execute = sorted(list(map(lambda a: (len(recursive_will_execute(prompt, self.outputs, a[-1], memo)), a[-1]), to_execute))) | ||
| output_node_id = to_execute.pop(0)[-1] | ||
|
|
||
| # This call shouldn't raise anything if there's an error deep in | ||
|
|
||
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.
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.
This should be backwards compatible with any external callers of this function.