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

Do not mark unchanged computed var deps as dirty #4488

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

benedikt-bartscher
Copy link
Contributor

@benedikt-bartscher benedikt-bartscher commented Dec 5, 2024

part of #4487

@benedikt-bartscher benedikt-bartscher changed the title wip #4487 [WIP] Do not mark unchanged var deps as dirty Dec 5, 2024
Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

one potentially issue i see with this approach is it makes it harder to manually mark a var as dirty, for example if internal change tracking is not working for a certain kind of object, a hackaround was always to assign it to itself to signal to the framework that it should be included in the delta. i know @adhami3310 uses this trick quite a bit.

@benedikt-bartscher
Copy link
Contributor Author

benedikt-bartscher commented Dec 5, 2024

@masenf I knew this comment was coming 😆

However, I have 2 arguments against it:

  • self.var = self.var is not really descriptive and needs a comment to explain what it's doing. self.dirty_vars.add("var"); self._mark_dirty() is pretty descriptive and doesn't need further explanation. We could add a helper which does both in one call.
  • Currently, there is no way for users to stop reflex from marking all vars which depend on a computed var as dirty, even if the computed var did not change (_mark_dirty_computed_vars). Maybe I can adjust this PR to only change the computed var behavior?

@benedikt-bartscher
Copy link
Contributor Author

benedikt-bartscher commented Dec 5, 2024

I just refactored one small repo to always check if the var has changed before assignment. Now I have a diff of 85 lines with repetitive

if self.var != new_var:
  self.var = new_var

@adhami3310
Copy link
Member

adhami3310 commented Dec 5, 2024

haven't looked into this too deeply but self.var = self.var is only used to let reflex know about a difference that internal mutability proxy didn't catch

@benedikt-bartscher
Copy link
Contributor Author

current implementation is not optimal, i have a better one coming
BTW, this PR is now only about unchanged computed vars. I will split #4487 into multiple PRs

@benedikt-bartscher benedikt-bartscher changed the title [WIP] Do not mark unchanged var deps as dirty [WIP] Do not mark unchanged computed var deps as dirty Dec 6, 2024
@benedikt-bartscher benedikt-bartscher changed the title [WIP] Do not mark unchanged computed var deps as dirty Do not mark unchanged computed var deps as dirty Dec 8, 2024
@benedikt-bartscher benedikt-bartscher marked this pull request as ready for review December 8, 2024 22:13
@benedikt-bartscher benedikt-bartscher marked this pull request as draft December 9, 2024 16:34
@benedikt-bartscher
Copy link
Contributor Author

need to recheck order of computed var computation

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.

3 participants