Skip to content

DRAIN_EXCLUSIVE_ACTIONS implementation #1355

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

steve-the-edwards
Copy link
Contributor

Add an option to get the next action that is mutually exclusive to the dirty nodes. Then we can apply as many of those actions as possible.

Add tests for this as well and ensure existing tests can run with this runtime config on.

@steve-the-edwards steve-the-edwards force-pushed the sedwards/dea-2-for-real branch 4 times, most recently from b276a5b to eefc6d8 Compare June 20, 2025 20:56
@steve-the-edwards steve-the-edwards marked this pull request as ready for review June 20, 2025 20:57
Copy link
Collaborator

@zach-klippenstein zach-klippenstein left a comment

Choose a reason for hiding this comment

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

I don't understand the interaction between conflation and drainExclusive. It looks like we run the drainExclusive loop first, then render, then conflate, drainExclusive, and render, etc. Wouldn't we want to continuously interleave drainExclusive and conflation passes? Or is that what we're doing and I just can't read code?

): Unit = Unit

public sealed interface RuntimeLoopOutcome
public sealed interface RuntimeUpdate
Copy link
Collaborator

Choose a reason for hiding this comment

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

At the risk of over-optimizing, this could be a value class to avoid allocating RenderingProduced objects every pass even when they're ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice. will take a look at doing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd have to talk more with you about what you are thinking. I am not sure we even need to report the rendering itself to the interceptor. I can start by just removing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, that object is already allocated (probably why I was not worried originally). So we could start by just making RenderingProduced a value class I think I was confused originally because this comment was on the RuntimeUpdate sealed interface

Copy link
Contributor Author

@steve-the-edwards steve-the-edwards Jul 4, 2025

Choose a reason for hiding this comment

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

I made RenderingProduced a value class now. The others are just objects, so this should all be quite fast / have minimal allocations.

}

@Test
fun `for_drain_exclusive_and_render_only_when_state_changes_we_handle_multiple_actions_in_one_render_but_we_do_pass_rendering_if_state_changed_earlier`() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: You shouldn't need the backticks here, you're not using spaces or other illegal characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's actually because this is KMP code that runs on js as well, IIRC. For some reason the kotlin-js compiler can't handle long names that don't have ticks? Or maybe that's why I had to add the _. Now I can't remember. But it was something with kotlin-js.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out I was just remembering wrong or had copied this forward when not needed. Removed now!

@steve-the-edwards steve-the-edwards force-pushed the sedwards/dea-2-for-real branch from e6b2344 to 1551901 Compare June 24, 2025 14:18
@steve-the-edwards steve-the-edwards requested a review from a team as a code owner July 3, 2025 14:23
@steve-the-edwards steve-the-edwards force-pushed the sedwards/dea-2 branch 2 times, most recently from 5b45b9a to 44397aa Compare July 3, 2025 19:24
@steve-the-edwards steve-the-edwards force-pushed the sedwards/dea-2-for-real branch 2 times, most recently from 9a60fe3 to 0acd80d Compare July 3, 2025 19:44
@steve-the-edwards steve-the-edwards force-pushed the sedwards/dea-2-for-real branch from 0acd80d to 4d41e92 Compare July 3, 2025 19:47
@steve-the-edwards
Copy link
Contributor Author

I don't understand the interaction between conflation and drainExclusive. It looks like we run the drainExclusive loop first, then render, then conflate, drainExclusive, and render, etc. Wouldn't we want to continuously interleave drainExclusive and conflation passes? Or is that what we're doing and I just can't read code?

the main loop (after the first synchronous render) is:

  1. awaitAndApplyAction() for the first available action
  2. DEA loop: Drain any exclusive actions immediately available - synchronously for any actions already queued (no suspend here).
  3. render()
  4. CSR loop: Drain any other actions immediately available; render() after each one.
  5. pass updated rendering down the StateFlow.

No interleaving is necessary from what I can tell. The exclusive actions for DEA are just a subset of the actions that can be applied without rendering at all.

Base automatically changed from sedwards/dea-2 to main July 3, 2025 20:56
@steve-the-edwards steve-the-edwards force-pushed the sedwards/dea-2-for-real branch from 4d41e92 to b0dfc9c Compare July 3, 2025 20:56
@steve-the-edwards steve-the-edwards force-pushed the sedwards/dea-2-for-real branch from b0dfc9c to 3635e7d Compare July 4, 2025 14:38
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants