aragon / aragon.js

(Aragon 1) A monorepo of JavaScript libraries for interacting with Aragon
https://aragon.org
GNU Affero General Public License v3.0
82 stars 58 forks source link

State caching - app state #294

Closed 2color closed 5 years ago

2color commented 5 years ago

Background

When interacting with the Aragon client, there are a couple of factors that make the initial load very slow. This is primarily because we fetch logs/events from a fixed point (a certain block number) in the past.

The initial load of the voting app for the Aragon Network Vote #2 takes around 2 minutes in the best case.

Currently, the reduced state used for rendering is cached but all past events are fetched from the beginning. That means that while the second load will render fast, if any changes – like a vote cast – happened between the first load and second load, it will take around 2 minutes for them to be visible to the user.

Goal

Proposal

Currently

Next steps

Potential challenges

Some of the changes are breaking API changes. This will require refactoring of the app scripts to adhere to the new API. This can be time consuming and introduce new bugs. Additionally the documentation should be updated.

Expected outcomes

sohkai commented 5 years ago

Some notes to the above, for reference when writing documentation.


For sake of simplicity in determining a safe block reorg point, we are simply caching the "last safe block header" once when the store() function is used (usually when an application's WebWorker script loads, which is immediately after load for the Aragon client), rather than incrementally over time.

This shouldn't impact performance very much, because most users won't have a pinned tab open over a long duration (e.g. months), to the point where incremental caching would have been useful.


Right now, developers are expected to write their store() reducers in a way that is "semi-idempotent" on seeing the same events, over and over again. I mention "semi" here, because reduced caches often use external contract state (not included in the events), that may be changed outside of what is available in the event parameters.

In the worst case, as it is now, each time the client starts, each reducer is fed all events over its lifetime and will see data that was already cached.

In the improved caching scenario as outlined above, reducers will still need to abide by this "semi-idempotent" assumption, but they will just see a lot less duplicated history on reruns.

sohkai commented 5 years ago

Completed by #297, docs will be updated as @aragon/api@2 stabilizes with #330.