Neodymium7 / BetterDiscordStuff

Neodymium's plugins and CSS Snippets for BetterDiscord
MIT License
34 stars 10 forks source link

[Enhancement] Icon search performance #68

Closed effleurager closed 2 months ago

effleurager commented 2 months ago

Is your feature request related to a problem? Please describe. Loading the VoiceActivity plugin takes upwards of 15 seconds on my machine, spending the vast majority of time iterating over Webpack modules for each requested icon. This makes using Discord at startup an unpleasant wait.

Describe the solution you'd like Replace individual search calls with a pattern matching any required icons, to reduce interation of all modules to a single-pass. The resulting subset can then be trivially searched.

Describe alternatives you've considered

Additional context Profile of plugin loading image

effleurager commented 2 months ago

Thanks for the phenomenally quick turnaround on this! 🤩

Screenshot_20240822-134415

I've been trying to figure out the massive speed-up, but the diff suggests it's something already solved within BetterDiscord?

Neodymium7 commented 2 months ago

Yeah, no problem! I had been wondering myself about what was increasing the load times so much, and I hadn't actually thought about fetching the icons, so thanks for letting me know that was a potential issue!

In case you're curious what I changed:

Ideally, the optimal way to get the icons would be by searching for a string (like an SVG path) within the exported function's toString. A while ago when Discord started transitioning to their new icon set, all of the SVG icons were wrapped in a common function to determine which icon set to use, so the functions that included the SVG paths weren't exported themselves. The best alternative I thought of was to instead search the source code of the entire module, which is very slow, especially when you're doing it for every single module, and then for each icon.

Recently, a Discord update slowed down module searching a lot, which seemed to exponentially affect my already slow search methods (i.e. your 15 second loading times). Now that Discord has completely moved over to their new icon set and removed the wrapper function, that slower source search method was unnecessary. So, all I did to fix the loading times was move back to the previous, much faster search method. You can see that change here. Kind of crazy how just a one line change can have such drastic results!

TL;DR I changed from a really, really slow module search method to a much better one for fetching the icons