BetterDiscord-Plugins
BetterDiscord-Plugins copied to clipboard
[BetterVolume] Plugin Gradually Slows Down Text Box Right Click Context Menu
The context menu when right clicking in the text area to type a message will appear gradually slower and slower with this plugin enabled. From plugin start, right clicking in the text area will have the context menu appear at its usual speed as normal, however continuously doing so will have it appear slower and slower until it averages around 700ms response time. This seems to be because for some reason the plugin is running tasks that lock the appearance of the context menu until they complete.
Here is a graph of the performance capture with the plugin disabled:
Each column is a right click action.
Here is a graph of the performance capture with the plugin enabled, starting from when the context menu appears at its normal speed:
Right click task takes ~200ms average, much like it does normally.
Here is a graph of the performance capture with the plugin enabled, after about 20 or so seconds of it running:
Right click task takes ~600ms average. This maximizes around 750ms or so.

I've noticed that in each right click call the BetterVolume.plugin.js is referenced in the bottom up call stack, with the plugin taking an increasing amount of time to process whatever it's doing.

~~Seems like Discord made the arguments for the open context menu function in the textarea persistent in some way, probably bound. This causes the plugin to inject into the callback multiple times rather than once.~~
Every other context menu seems to behave normally.
Actually nevermind, the arguments are not persistent. This seems to be a bug on Discord's side which causes their callback to get called more and more often rather than once.
Okay, figured it out: the textarea sets enableSpellCheck: true in the options passed to openContextMenuLazy(), which causes that function to wrap the callback inside a listener to some "spellcheck" module instead of invoking it directly. The listener is supposed to remove itself after being called, however I can confirm that the removeListener() function is bugged and does in fact not remove any listeners. The spellcheck module seems to be a native node module, so I won't bother trying to reverse engineer what is going wrong there.
TL;DR It's Discord screwing up badly and on my side it's probably not avoidable to run into this bug without taking a completely different approach to lazy loaded modules.
Discord still hasn't fixed this bug. However, it should no longer be relevant since the plugins now use a different way of finding lazy loaded modules.