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

Memoize pool price calculation #1036

Merged
merged 4 commits into from
Nov 22, 2022
Merged

Memoize pool price calculation #1036

merged 4 commits into from
Nov 22, 2022

Conversation

jonator
Copy link
Member

@jonator jonator commented Nov 22, 2022

It seems faster for less assets, but enabling all assets to be calculated from pools is still a bit too much.

@vercel
Copy link

vercel bot commented Nov 22, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
osmosis-frontend ✅ Ready (Inspect) Visit Preview Nov 22, 2022 at 3:30PM (UTC)
osmosis-frontend-legacy ✅ Ready (Inspect) Visit Preview Nov 22, 2022 at 3:30PM (UTC)
osmosis-frontend-v13-chain ✅ Ready (Inspect) Visit Preview Nov 22, 2022 at 3:30PM (UTC)
osmosis-frontier ✅ Ready (Inspect) Visit Preview Nov 22, 2022 at 3:30PM (UTC)
osmosis-testnet ✅ Ready (Inspect) Visit Preview Nov 22, 2022 at 3:30PM (UTC)

Comment on lines +52 to +56
readonly getPrice = computedFn(
(coinId: string, vsCurrency?: string): number | undefined => {
if (!vsCurrency) {
vsCurrency = this.defaultVsCurrency;
}
Copy link
Member

Choose a reason for hiding this comment

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

So computedFn is just memoizing this, were we calling this function repeatedly a lot before?

Am in support of making it memoized / computed!

Copy link
Member Author

@jonator jonator Nov 22, 2022

Choose a reason for hiding this comment

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

Yeah basically everything computed on pools is memoized, for some reason this wasn't. So if given the same input, it will return a cached output, which is an absolute need with how often components get rendered as data loads and populates observable properties. However, with all asset prices being computed from pool weights, the one-time (due to memo) recursion still causes quite a delay.

Copy link
Member Author

Choose a reason for hiding this comment

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

A global ⌘⇧F on computedFn will come up with a lot of results

@jonator
Copy link
Member Author

jonator commented Nov 22, 2022

@JeremyParish69 thoughts on performance with all assets? We can revert some major ones on coingecko if not satisfactory.

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