I made the solana/spl-token-registry method to get token registry faster.
I am sure a lot of our apps still use the spl-token-registry to fetch the token list and build a map of token details.
The suggested usage is a little inefficient so I cleaned it up.
Here's how š
Here's the suggested usage for spl-token-registry.
- First, download the list. This checks against a CDN and has two fallback URLs.
- Loop the data and filter.
- Loop the same data again and make more variables.
Ok, now you can finally use the data.
š npmjs.com/package/@solana/spl-token-registry#usage
My version
- Only use the CDN, if not available, RIP.
- Only have one instance of the token list in memory and only loop over it one time.
- Use Reduce to do all in one filter and map generation.
note: I tested this with a for loop and it was slower than og
š The results?
Consistently saving half a second when processing the data after the request comes in š¤
Also, I bet we can't rely on all users computers and phones having the same processing power as my dev machine. I bet the discrepancy grows on slower machines.
I made my solution a Gist here, feel free to use! I'd make a PR to the registry repo but I think it's deprecated. Also didn't seem worth it since it does work fine as advertised. But if you want faster apps....šāļø
gist.github.com/qudo-code/4684c271e9be2412e3508b48ef18b3f3