proginosko / LeechBlockNG

LeechBlock NG (Next Generation) for Firefox is a simple productivity tool designed to block those time-wasting sites that can suck the life out of your working day. All you need to do is specify which sites to block and when to block them.
https://www.proginosko.com/leechblock/
Mozilla Public License 2.0
719 stars 66 forks source link

LeechBlock doesn't get along well with Firefox's GC #124

Open benburrill opened 5 years ago

benburrill commented 5 years ago

I've been having memory issues for a while now where Firefox's memory usage steadily rises (a couple MB/s), sometimes falling back on its own, but disturbingly often it just keeps on rising seemingly forever. Disabling LeechBlock stops the memory from rising.

To deal with this, whenever my computer starts getting slow, I go to about:memory, clear the GC, and then turn swap on and off again. This is annoying, but it's better for my productivity than disabling LeechBlock!

When measuring memory in about:memory, the problem shows up as structured-clone-holder and I think the problem is likely related to this Firefox issue. Specificially, I believe this problem is because LeechBlock sends messages to tabs every second to update the time remaining, creating those structured-clone-holders at such a frequency that Firefox's GC can't keep up. However, I don't really see why the background script needs to be responsible for the countdown. The tabs can maintain their own timer which can be updated by the background script whenever you switch to the tab, but for the most part the tabs can just do the count-down on their own.

I'm using Firefox 70 on Linux.

martinxyz commented 4 years ago

Just to confirm, this is a problem for me, too.

With a couple of tabs open, I'm measuring a growth of ~7MB per minute of the "WebExtensions" process. Firefox is just sitting in the background. Disabling LeechBlockNG stops the leak. (Measured without restarting Firefox. Firefox 71 on Linux. With some other extensions also running.)

image

benburrill commented 4 years ago

The workaround I've settled on is turning on the "Process only active tabs" setting. This completely (or at least to the extent that I can notice) fixes the problem. However, depending on your block settings, this may not be the behavior you want. I somewhat recently changed my block settings to be entirely delay-based, and "Process only active tabs" works flawlessly with that since there is no need to update any other tabs.

Of course the issue still exists and needs to be fixed, but for my purposes LeechBlock thankfully works sensibly again.

martinxyz commented 4 years ago

Great workaround, thank you. I've also settled on delay-based blocking long ago. At first it felt like cheating to get around the block just by standing up and doing some quick other task. Until I realized what a positive change this was :-)

proginosko commented 4 years ago

I wonder if this is a Linux-specific issue. I'm using FF on Win10 and I haven't encountered any LB memory-usage issues. Even with a lot of tabs open, LB usage remains constant at around 550KB.

benburrill commented 4 years ago

Yeah, I figure it is Linux-specific. The Firefox issue I linked was also reported by a Linux user. I have not tried to reproduce on another OS though.

martinxyz commented 4 years ago

More testing:

Code exploration:

rakyi commented 3 days ago

I'm seeing this issue in Firefox 132.0.2 on macOS 15.1, but I observed it also in the past on older versions. I usually have at least a few dozen tabs open across 1–3 windows.