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

Allow squashing history entries #10

Open
ds300 opened this issue Jan 20, 2023 · 2 comments
Open

Allow squashing history entries #10

ds300 opened this issue Jan 20, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@ds300
Copy link
Contributor

ds300 commented Jan 20, 2023

rationale

When updating things in the store, we make potentially many changes to different atoms. our history atom is updated once per .put and once per .remove call, but if nobody reads the history during a transaction we may be creating more history entries than we need. They can be trivially squashed, but we don't currently know when it's safe to do so.

proposal

First let's define the notion of a 'fresh read': the first read to happen after an atom was last changed.

Now let's say we keep track of the lastFreshReadEpoch for each atom and derivation.

On every fresh read (after the initial one?), before exposing the state or history of the derivable, we can squash down any history events since the lastFreshReadEpoch.

impact

This would be a fairly minor perf improvement for very niche use cases. In some situations it may be a big perf win, but I'm struggling to think of what those cases may look like.

@ds300 ds300 added the enhancement New feature or request label Jan 20, 2023
@judicaelandria
Copy link

judicaelandria commented Mar 6, 2023

In the case of Tldraw, I think it's not safe to squash history, you may always want to revisit them! I definitely agree that this is maybe a big perf win but not really safe! but maybe I am missing something in this context.

@ds300
Copy link
Contributor Author

ds300 commented Mar 6, 2023

I suspect you're thinking of the user undo/redo history? That would be important to preserve yeah. But this issue is just referring to the signal's internal diff history, which is only used for incremental recomputation, and doesn't need to be 'undone' at any point. I think it should be possible to squash it safely in some situations, but it's not a priority since it would add complexity and not much performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants