Skip to content
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

1249: Cache Intercepted Workflow Instance #1250

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

steve-the-edwards
Copy link
Contributor

@steve-the-edwards steve-the-edwards commented Jan 20, 2025

We cache the instance of the workflow before and after it is intercepted.

We check for instance equality any time a new workflow instance is passed in (render() and snapshot()) and we update our cached instances when that happens. This will allow us to continue to use the same WorkflowNode with different instances of the workflow.

Closes #1249

@steve-the-edwards steve-the-edwards force-pushed the sedwards/cache-it-all branch 2 times, most recently from 1c12e26 to 1bf6f2f Compare January 21, 2025 15:55
@steve-the-edwards steve-the-edwards marked this pull request as ready for review January 21, 2025 16:07
@steve-the-edwards steve-the-edwards added the optimization Issues related to benchmarking and optimization label Jan 21, 2025
@steve-the-edwards steve-the-edwards changed the title 1249: Cache Interceptor Instance 1249: Cache Intercepted Workflow Instance Jan 21, 2025
rjrjr

This comment was marked as outdated.

@zach-klippenstein

This comment was marked as outdated.

@rjrjr

This comment was marked as outdated.

@rjrjr

This comment was marked as outdated.

@steve-the-edwards

This comment was marked as outdated.

@zach-klippenstein

This comment was marked as outdated.

@rjrjr

This comment was marked as outdated.

@steve-the-edwards

This comment was marked as outdated.

@rjrjr

This comment was marked as outdated.

@square square deleted a comment from rjrjr Jan 23, 2025
@@ -202,6 +205,18 @@ internal class WorkflowNode<PropsT, StateT, OutputT, RenderingT>(
coroutineContext.cancel(cause)
}

// Call this after we have been passed any workflow instance, in [render] or [snapshot]. It may
// have changed and we should check to see if we need to update our cached instances.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Make this a kdoc comment so it's visible directly at callsites.

if (workflow !== cachedWorkflowInstance) {
// instance has changed.
interceptedWorkflowInstance = interceptor.intercept(workflow, this)
cachedWorkflowInstance = workflow
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you update cachedWorkflowInstance first in init, but second here? Is there some case where intercept needs the cached workflow to not be updated yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope. Just a coincidence. I can unify the order so its not confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Change it if we have been passed a new workflow instance to the same node.
@steve-the-edwards steve-the-edwards merged commit 4345d22 into main Jan 28, 2025
31 checks passed
@steve-the-edwards steve-the-edwards deleted the sedwards/cache-it-all branch January 28, 2025 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Issues related to benchmarking and optimization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache Ids and interceptor instances
3 participants