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

perf: blazingly fast #7799

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open

Conversation

gomesalexandre
Copy link
Contributor

@gomesalexandre gomesalexandre commented Sep 24, 2024

Description

Attempt 1 at redux perf. improvements

Issue (if applicable)

Risk

High Risk PRs Require 2 approvals

What protocols, transaction types, wallets or contract interactions might be affected by this PR?

High - touches state. Getting this wrong could brick state, and we'd have to revert this and do a nuke of the whole state.

Testing

  • Ensure app state still looks good
  • Ensure rehydration (i.e refresh with persisted state) is still happy

Engineering

  • ^
  • Migrations are still happy
    NOTE: Ensure you check for slice state after rehydration (i.e {rehydrated: true} for the slice/s you're migrating) to ensure redux-persist rehydrated with your migration:
    Screenshot 2024-09-24 at 22 27 36
    Screenshot 2024-09-24 at 22 27 26

Operations

  • 🏁 My feature is behind a flag and doesn't require operations testing (yet)

Screenshots (if applicable)

https://jam.dev/c/6fee8b7a-97d8-48b0-b420-b04f3ef008b4

@@ -54,8 +43,6 @@ const apiMiddleware = [

const subscriptionMiddleware = createSubscriptionMiddleware()

const persistedReducer = persistReducer(persistConfig, reducer)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

doesn't persist root anymore

@gomesalexandre gomesalexandre changed the title perf: split persistReducers per slice perf: blazingly fast Sep 24, 2024
84: clearAssets,
85: clearAssets,
86: clearAssets,
87: clearWalletConnectWalletsMetadata,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Converted to the single slice migration format, but since it was a one off, not to the list of "uncomment me"

Copy link
Member

Choose a reason for hiding this comment

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

LOVE this

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, makes a lot of sense

@gomesalexandre gomesalexandre marked this pull request as ready for review September 24, 2024 20:34
@gomesalexandre gomesalexandre requested a review from a team as a code owner September 24, 2024 20:34
Copy link
Member

@woodenfurniture woodenfurniture left a comment

Choose a reason for hiding this comment

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

Code wise very sane, will do second pass of runtime testing before giving final stamp

...state,
opportunities: initialState,
}
return initialState as OpportunitiesState & PersistPartial
Copy link
Member

Choose a reason for hiding this comment

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

[self note]: Test individual migrations to ensure these changes to what's intended (i.e not nuking all cache)

wallet: {
...state.wallet,
ids: updatedWalletIds,
byId: updatedWalletById,
Copy link
Member

Choose a reason for hiding this comment

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

[comment]: wow now this is 1 level shallower i can see this being faster

84: clearAssets,
85: clearAssets,
86: clearAssets,
87: clearWalletConnectWalletsMetadata,
Copy link
Member

Choose a reason for hiding this comment

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

LOVE this

ignoredActions: [PERSIST, PURGE],
},
// funnily enough, the checks that should check for perf. issues are actually slowing down the app
// https://github.com/reduxjs/redux-toolkit/issues/415
Copy link
Member

Choose a reason for hiding this comment

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

[suggestion]: Comment why disabling this doesnt reduce safety so we dont have a panik moment later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

export const clearSnapshotMigrations = {
// Uncomment me when introducing the first migration for this slice
// 0: clearSnapshot,
} as unknown as Omit<MigrationManifest, '_persist'>
Copy link
Member

Choose a reason for hiding this comment

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

[blocking question]: What is the default version and should we have it here so the first migration doesnt fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should not - that will be automagically injected by redux-persist (tested with 0th migrations)

Copy link
Contributor Author

@gomesalexandre gomesalexandre Sep 24, 2024

Choose a reason for hiding this comment

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

i.e no migration:

image

0th migration (don't mind the non-empty slice, devtools acting up and I lost the REHYDRATE event):

image

const localWalletSlicePersistConfig = {
key: 'localWalletSlice',
storage: localforage,
}
Copy link
Member

Choose a reason for hiding this comment

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

[question]: Should we comment why there is no migration for this slice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -89,5 +167,5 @@ export const apiReducers = {
[abiApi.reducerPath]: abiApi.reducer,
}

export const reducer = combineReducers({ ...sliceReducers, ...apiReducers })
export const reducer = combineReducers(Object.assign({}, sliceReducers, apiReducers))
Copy link
Member

Choose a reason for hiding this comment

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

🐐

Copy link
Contributor

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

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

LGTM. Tested a couple of migrations and they worked as expected / properly rehydrated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants