Skip to content

Instantly share code, notes, and snippets.

@RubenKelevra
Last active June 25, 2024 23:11
Show Gist options
  • Save RubenKelevra/fd66c2f856d703260ecdf0379c4f59db to your computer and use it in GitHub Desktop.
Save RubenKelevra/fd66c2f856d703260ecdf0379c4f59db to your computer and use it in GitHub Desktop.
Make Firefox fast again

Recommended Extentions:

uBlock Origin

https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/

Settings

Make sure the following options are off:

  • Disable pre-fetching

Rationale: Not doing this will significantly slow down navigation, as Firefox won't prefetch any content before clicking.

JSLibCache

https://addons.mozilla.org/en-US/firefox/addon/jslibcache/

Settings

Make sure the following options are on:

  • Allow header modification

Rationale: Otherwise many Javascript libraries won't be fetched from local storage - as they have parameters on their URLs in the HTML code. This isn't going to break any website.`

Make sure to copy the uBlock rules provided, to your uBlock settings, to avoid uBlock interfering:

  1. Go to the uBlock rules
  2. copy them
  3. Open uBlock's Dashboard
  4. Go to the My rules tab
  5. Paste them & hit Save, then Commit

Cache Longer

https://addons.mozilla.org/en-US/firefox/addon/cache-longer/

Set and forget.

Rationale: Increases the time items will be stored in the browser cache. This increasing the chance that network ressources won't need to be fetched. As NVMe/SSD storage is cheap and lightning fast compared to network requests, this has the potential to improve load times significantly.

Recommended Browser settings

Normal Browser settings

  1. Go to about:preferences#privacy
  2. Select Custom
  3. deactivate all filters in this section
  4. Scroll down to Security -> Deceptive Content and Dangerous Software Protection
  5. Disable Block dangerous and deceptive content

Rationale: Those filters use a lot of CPU time to process, and are not very helpful - except for newbies. The Dangerous Software filters may actually even block downloads the user want to fetch, that's why it is recommended to disable these.

about:config settings

General tweaks

network.captive-portal-service.enabled = false # don't try to find captive portals
network.notify.checkForProxies = false # don't try to find proxies

Browser cache

browser.cache.disk.capacity = 8192000 # Increase cache size on disk to 8 GB
browser.cache.disk.smart_size.enabled = false # force a fixed max cache size on disk
browser.cache.frecency_half_life_hours = 18 # lower cache sweep intervals
browser.cache.max_shutdown_io_lag = 16 # let the browser finish more io on shutdown
browser.cache.memory.capacity = 2097152 # fixed maximum 2 GB in memory cache
browser.cache.memory.max_entry_size = 327680 # maximum size of in memory cached objects
browser.cache.disk.metadata_memory_limit = 15360 # increase size (in KB) of "Intermediate memory caching of frequently used metadata (a.k.a. disk cache memory pool)"

GFX rendering tweaks:

gfx.canvas.accelerated = true
gfx.canvas.accelerated.cache-items = 32768	
gfx.canvas.accelerated.cache-size	= 4096	
layers.acceleration.force-enabled = false
gfx.content.skia-font-cache-size = 80	
gfx.webrender.all = true	
gfx.webrender.compositor = true	
gfx.webrender.compositor.force-enabled = true	
gfx.webrender.enabled = true	
gfx.webrender.precache-shaders = true	
gfx.webrender.program-binary-disk = true
gfx.webrender.software.opengl = true
image.mem.decode_bytes_at_a_time = 65536	
image.mem.shared.unmap.min_expiration_ms = 120000	
layers.gpu-process.enabled = true
layers.gpu-process.force-enabled = true
image.cache.size = 10485760
media.memory_cache_max_size = 1048576	
media.memory_caches_combined_limit_kb = 3145728
media.hardware-video-decoding.force-enabled = true
media.ffmpeg.vaapi.enabled = true

Increase predictive network operations

network.dns.disablePrefetchFromHTTPS = false
network.dnsCacheEntries = 20000
network.dnsCacheExpiration = 3600
network.dnsCacheExpirationGracePeriod = 240
network.predictor.enable-hover-on-ssl = true
network.predictor.enable-prefetch = true
network.predictor.preconnect-min-confidence = 20
network.predictor.prefetch-force-valid-for = 3600
network.predictor.prefetch-min-confidence = 30
network.predictor.prefetch-rolling-load-count = 120
network.predictor.preresolve-min-confidence = 10

Faster SSL

network.ssl_tokens_cache_capacity = 32768 # more TLS token caching (fast reconnects)

Disable network seperations

fission.autostart = false # disable enhanced protection between threads/processes of the browser (which uses LOADS of memory to do)
privacy.partition.network_state	= false # don't seperate the network state (e.g. the cache) by top level domains)

Reduce the number of processes

dom.ipc.processCount = 1
dom.ipc.processCount.webIsolated = 1

Rationale: By default Firefox launches as many processes as you got CPU cores. This is highly counter productive, as this leads to much more memory usage as necessary. In addition switching tabs may now result not only in having to load the content back from the swap into memory, but also swapped in duplicated libraries etc.

Finishing touches:

  • Restart firefox

Go to about:support then scroll down to "Places Database" and select "Verify Integrity". This will rewrite the database.

Scroll up again and select "Clear startup cache" on the right side.

  • Restart firefox

Nice to have extensions

I don't care about cookies

https://addons.mozilla.org/en-US/firefox/addon/i-dont-care-about-cookies/

Set and forget.

Bypass Paywalls Clean

https://addons.mozilla.org/en-US/firefox/addon/bypass-paywalls-clean/

Automatically bypass some paywalls.

Downside: Needs often new permissions, if an update adds a site to the supported list. - You'll get notified with an ! mark on your "hamburger menu" icon.

Consent-O-Matic

https://addons.mozilla.org/en-US/firefox/addon/consent-o-matic/

Set and forget.

Cookie AutoDelete

https://addons.mozilla.org/en-US/firefox/addon/cookie-autodelete/

Go to settings and make sure the following are off:

  • Show Notification After Automatic Cleanup
  • Enable Support for Container Tabs

SponsorBlock - Skip Sponsorships on YouTube

https://addons.mozilla.org/en-US/firefox/addon/sponsorblock/

Configure skip categories to your likings.

Changelog

2023-07-07

  • add browser.cache.disk.metadata_memory_limit
  • Remove "cache cleaning" from finishing touches (as it's not really necessary and confuses people)

2023-04-15

  • set layers.acceleration.force-enabled to false (as it may increase CPU usage)

2023-02-26

  • Remove uBlock Origin's Disable hyperlink auditing unckecking recommendation (no idea why I've added that)
  • Organize Settings for Add-Ons under headlines
  • Improve explanation of how to apply JSLibCache's uBlock rules
  • Add Rationale to some settings, to avoid that people have to google
  • Fix browser.cache.frecency_half_life_hours
  • Minor changes/fixes to formatting
  • Reduce process counter down to one
@yokoffing
Copy link

@RubenKelevra You have browser.cache.memory.max_entry_size for the maximum size of in memory cached objects, but you don't list browser.cache.disk.max_entry_size for the disk cache. Is there a reason for that?

@RubenKelevra
Copy link
Author

@yokoffing yeah. Rationale is that you want to avoid putting a limit on what's beeing able to be cached for a short time in memory. Say if you're watching a video it can be cached in memory.

But the default max size for the disk seems fine to me. It's not like you want to write a 2 GB video to disk cause you maybe watch it again a second time - as you usually don't need the first bit of data anyway, as you continue at the last position you stopped playing.

So to avoid that large media files push out a lot of small files, which have a much bigger impact on loading times (because they need to be fetched and latency is the issue here) it makes sense to have a barrier here.

@yokoffing
Copy link

@RubenKelevra I don't see the memory cache or disk cache greatly affected on about:cache when using YouTube, but I may not be inspecting closely enough.

The media cache media.cache_size is 512000 by default and separate from the disk cache (and not on your list, but the size is probably fine).

You do have prefs for the media memory cache media.memory_cache, but there's not a way to force it for Normal Windows. For Private Windows there's browser.privatebrowsing.forceMediaMemoryCache. If you enable that setting, then watching videos in Private Windows does show an increase in the memory cache on about:cache , ironically.

I don't know what triggers media cache vs. media memory cache for regular browsing.

From monitoring about:cache: I still have plenty of disk storage left, though it is growing substantially (558877 KiB), and the memory cache is hardly ever used for regular browsing (982 KiB).

I've never maxed out my disk cache, so idk what happens when this occurs. I assume Firefox gets rid of the oldest or least used cache files first to make room for newer ones.

@RubenKelevra
Copy link
Author

@yokoffing Youtube is using DASH not regular http files and thus is handled differently regarding caching.

@RubenKelevra
Copy link
Author

I've never maxed out my disk cache, so idk what happens when this occurs. I assume Firefox gets rid of the oldest or least used cache files first to make room for newer ones.

You can't max it out if the items reach their maximum age before. So if say an CSS file got an max age of 2h, Firefox will likely swipe it soon after. So even if e.g. an image got the somewhat new "stale-while-revalidate" it may just not be there anymore to show up.

As most websites use version numbers on most resources anyway I recommend using the cache longer add-on. It allows Firefox to keep items much longer on disk. So "stale-while-revalidate" and regular revalidate will avoid having to fetch it, and caching without revalidation can just use the cached ressource from disk.

@yokoffing
Copy link

You can't max it out if the items reach their maximum age before

Right, but with using Cache Longer, where items stay in cache for 6 months, I imagine one would hit the threshold with everyday use? I haven't tested long enough to see for myself.

@HenryTheVacuum
Copy link

dom.ipc.processPriorityManager.backgroundUsesEcoQoS set it to false

Disables ‘Efficiency mode’ for Firefox on Windows 11 for laptops.

@RubenKelevra
Copy link
Author

This is just tested on Linux.

@Hyperi0n1337
Copy link

Something I've configured keeps deleting all my userscripts upon browser restart.

I think it's an about:config setting I've changed but I don't exactly know which. Any ideas what might be causing it? Whenever I restart nightly or when it has to restart to apply updates all my violentmonkey scripts get cleared. All my extensions however, are intact, like ublock etc.

Anyone know what might be the problem?

I tried another tampermonkey too and I'm getting the same issue. But ublock for example is fine, and I'm not sure about this inconsistency.

@trimechee
Copy link

Hello @RubenKelevra @yokoffing , thank you for these extraordinary high-flying tricks and this interesting instructive discussion :)

I find an article from a Japanese site that sheds light on this debate on the recommended value of "browser.cache.disk.max_entry_size":

preserve ssd in firefox:

https://kanasys.com/tech/892

basically, the japanese article advises to set 128 to browser.cache.disk.max_entry_size to avoid the cache of youtube videos which can wear out the ssd....

@RubenKelevra
Copy link
Author

I don't think wearing SSDs out is an fair point to consider anymore.

I mean just a case study, but still: I got an 80 GB Intel SSD in one of my older daily drivers, which is now 10 years old. The small size should have made wearing it out very likely, but it never happened.

I've checked, I'm at 2% reserve sector use - and I wasn't kind to it in any way.

With the large sizes of SSDs these days, this issue is basically gone, for normal consumer use.

@trimechee
Copy link

Thank you @RubenKelevra for these important explanations :)

I asked an important question on your Twitter, I copied the question: "I want to completely deactivate disk cache because I have a slow HDD, I hesitate to set the value 0 or the value 1 for "browser.cache.disk. max_entry_size", I fear that set the value 0 to browser.cache. disk.max_entry_size will cause the opposite effect and cause unlimited disk cache usage.....

I have a 6 year old HDD and I have deactivated the Windows 10 defragmentation service and so it is important that I can deactivate the Firefox disk cache for faster navigation, so what do you think please? I have to set the value "0" or "1" for browser.cache.disk.max_entry_size to completely disable the disk cache?

@iam-py-test
Copy link

browser.cache.disk.enable may be a more reliable way to turn off the cache, but I could be wrong...

@RubenKelevra
Copy link
Author

Hey @trimechee,

disabling the cache isn't a good practice. Even older hard drives are consirable more responsive than the average webserver, in serving a lot of small files. For larger files, the bandwidth from your hard drive is usually faster than your internet connection.

Hard drive is like 100 Megabyte/s while an internet connection may be 100 Megabit/s - which is 8 times slower, even if the webserver can utilize the full bandwidth.

You can test the impact, while you haven't turned off the cache:

Open a web page you usually visit and note the loading time.

Then press Ctrl+F5 to refresh the web page while ignoring everything in the cache.

The web page usually loads 3-5 times slower on the refresh.


In addition there's also the option to move the profile folder to a different disk or an SD-Card (needs to be "A1" or "A2" rated), which is probably the cheapest option, if you got an SD-Card slot on your computer. This frees up the bandwidth from your hard drive and since random access is faster from a flash memory compared to spinning rust, you should see an improvement in access times.

Hope this helps!

@trimechee
Copy link

@RubenKelevra Ohhh very important and valuable advices and explanations ! I am very grateful to you, thank you very much for your kindness and great help :)

@peter-kehl
Copy link

Thank you @RubenKelevra.

  1. Suggest replacing the now-Avast-owned extension (which I've used for long, too) with https://addons.mozilla.org/en-US/firefox/addon/istilldontcareaboutcookies/ https://github.com/OhMyGuus/I-Still-Dont-Care-About-Cookies.
  2. https://addons.mozilla.org/en-US/firefox/addon/bypass-paywalls-clean/ doesn't exist anymore. Any replacement, please?
  3. How do your GFX increases work for various kinds of GPU, or how do they fit different GPU memory?
  4. Any references/tips on where I could find which rendered my 5+ years old built-in Intel graphics could work best for? Or for more modern GPUs?

@xd003
Copy link

xd003 commented Dec 7, 2023

Does all of these setttings work on Firefox android too ?

@DoulosTrieste
Copy link

Thank you @RubenKelevra.

1. Suggest replacing the now-Avast-owned extension (which I've used for long, too) with https://addons.mozilla.org/en-US/firefox/addon/istilldontcareaboutcookies/ https://github.com/OhMyGuus/I-Still-Dont-Care-About-Cookies.

2. https://addons.mozilla.org/en-US/firefox/addon/bypass-paywalls-clean/ doesn't exist anymore. Any replacement, please?

3. How do your GFX increases work for various kinds of GPU, or how do they fit different GPU memory?

4. Any references/tips on where I could find which rendered my 5+ years old built-in Intel graphics could work best for? Or for more modern GPUs?
  1. https://gitlab.com/magnolia1234/bypass-paywalls-firefox-clean/-/releases

@rtzon59
Copy link

rtzon59 commented Jan 2, 2024

which one of the adjustments causes this text font/size change? followed your instructions and now texts look different now
Adsız
boths instances site zoom at default 100% along with its text settings in the options all are at default

@amteza
Copy link

amteza commented Jan 2, 2024

which one of the adjustments causes this text font/size change? followed your instructions and now texts look different now Adsız boths instances site zoom at default 100% along with its text settings in the options all are at default

It's the JSLibCache extension. Disable Block unknown Google fonts in the extension and you are good to go.

@amteza
Copy link

amteza commented Jan 2, 2024

BTW, if anyone prefers to use AdGuard in place of uBlock, these are the rules to be added under User rules:

@@||fonts.googleapis.com^$document
@@||ajax.googleapis.com^$document
@@||cdnjs.cloudflare.com^$document
@@||cdn.jsdelivr.net^$document
@@||code.jquery.com^$document
@@||unpkg.com^$document
@@||ajax.cloudflare.com^$document
@@||cdn.ampproject.org^$document
@@||ajax.proxy.ustclug.org^$document
@@||sdn.geekzu.org^$document

@rtzon59
Copy link

rtzon59 commented Jan 3, 2024

which one of the adjustments causes this text font/size change? followed your instructions and now texts look different now Adsız boths instances site zoom at default 100% along with its text settings in the options all are at default

It's the JSLibCache extension. Disable Block unknown Google fonts in the extension and you are good to go.

i disabled block unknown google fonts but it didn't make a difference (refreshed page or restarted the browser) but when i disable entire jslibcache extension it works... what else i can do with this extension?

@joshuataylor
Copy link

Super awesome guide, been using these tips for a few weeks.

As always with a page of random tweaks.. Don't blindly apply everything, understand what you're doing. :-)

I ended up not tuning as much memory, instead opting for disk access, as it's just as fast for me and uses less memory.

You might see issues when using the addon Cache Longer, I've had issues with random caching issues due to sites actually expiring certain parts and those being cached, or something weird like that with certain sites.

It would be actually really cool now I think of it to have what dnsmasq has which ismin-cache-ttl, where you can set the minimum time things should be DNS cached for. Many places use absurdly low times, and for me DNS resolution is kinda slow due to latency (I'm in a fairly remote city).

Caching stuff is great, as it's not the download speed (for me), but the latency/request cycle etc.

@Breakingbad53
Copy link

Thank you!

@CoolOppo
Copy link

I used GPT-4 to generate a user.js version:

// General tweaks
user_pref("network.captive-portal-service.enabled", false);
user_pref("network.notify.checkForProxies", false);

// Browser cache
user_pref("browser.cache.disk.capacity", 8192000);
user_pref("browser.cache.disk.smart_size.enabled", false);
user_pref("browser.cache.frecency_half_life_hours", 18);
user_pref("browser.cache.max_shutdown_io_lag", 16);
user_pref("browser.cache.memory.capacity", 2097152);
user_pref("browser.cache.memory.max_entry_size", 327680);
user_pref("browser.cache.disk.metadata_memory_limit", 15360);

// GFX rendering tweaks
user_pref("gfx.canvas.accelerated", true);
user_pref("gfx.canvas.accelerated.cache-items", 32768);
user_pref("gfx.canvas.accelerated.cache-size", 4096);
user_pref("layers.acceleration.force-enabled", false);
user_pref("gfx.content.skia-font-cache-size", 80);
user_pref("gfx.webrender.all", true);
user_pref("gfx.webrender.compositor", true);
user_pref("gfx.webrender.compositor.force-enabled", true);
user_pref("gfx.webrender.enabled", true);
user_pref("gfx.webrender.precache-shaders", true);
user_pref("gfx.webrender.program-binary-disk", true);
user_pref("gfx.webrender.software.opengl", true);
user_pref("image.mem.decode_bytes_at_a_time", 65536);
user_pref("image.mem.shared.unmap.min_expiration_ms", 120000);
user_pref("layers.gpu-process.enabled", true);
user_pref("layers.gpu-process.force-enabled", true);
user_pref("image.cache.size", 10485760);
user_pref("media.memory_cache_max_size", 1048576);
user_pref("media.memory_caches_combined_limit_kb", 3145728);
user_pref("media.hardware-video-decoding.force-enabled", true);
user_pref("media.ffmpeg.vaapi.enabled", true);

// Increase predictive network operations
user_pref("network.dns.disablePrefetchFromHTTPS", false);
user_pref("network.dnsCacheEntries", 20000);
user_pref("network.dnsCacheExpiration", 3600);
user_pref("network.dnsCacheExpirationGracePeriod", 240);
user_pref("network.predictor.enable-hover-on-ssl", true);
user_pref("network.predictor.enable-prefetch", true);
user_pref("network.predictor.preconnect-min-confidence", 20);
user_pref("network.predictor.prefetch-force-valid-for", 3600);
user_pref("network.predictor.prefetch-min-confidence", 30);
user_pref("network.predictor.prefetch-rolling-load-count", 120);
user_pref("network.predictor.preresolve-min-confidence", 10);

// Faster SSL
user_pref("network.ssl_tokens_cache_capacity", 32768);

// Disable network separations
user_pref("fission.autostart", false);
user_pref("privacy.partition.network_state", false);

// Reduce the number of processes
user_pref("dom.ipc.processCount", 1);
user_pref("dom.ipc.processCount.webIsolated", 1);

Save this as user.js in your profile folder.

@russeg
Copy link

russeg commented Apr 25, 2024

make firefox faster, but how do you know it is faster? where are the benchmarks or profiling info?

i'm not gonna eyeball wether firefox is faster because of the changes.. please provide some data, thank you.

@joshuataylor
Copy link

joshuataylor commented Apr 25, 2024 via email

@davidldennison
Copy link

make firefox faster, but how do you know it is faster? where are the benchmarks or profiling info?

i'm not gonna eyeball wether firefox is faster because of the changes.. please provide some data, thank you.

So, you want us to take time to create a benchmark that will only be useful to us? These flags and their ability to work or not work is VERY dependent on your operating environment and its capabilities. Any benchmark would be useless as it's very unlikely that you will be able to achieve the same or even closely reproduceable results as anyone else.

Just create a second Firefox user profile, paste in the stuff above, run your own tests. If it sucks, just go back to the old profile or keep tweaking. Firefox and its user base aren't really the community for "prove it first". Start testing and see what happens.

@RubenKelevra
Copy link
Author

RubenKelevra commented Apr 26, 2024

make firefox faster, but how do you know it is faster? where are the benchmarks or profiling info?

i'm not gonna eyeball wether firefox is faster because of the changes.. please provide some data, thank you.

Hey @russeg,

technically the defaults are faster, if you just have a very light usage for your browser, like open 2-3 tabs.

But the defaults are not optimized for heavy usage, where Firefox will spawn a lot of processes, which are only sparsely active.

Reason for this is, that a process is handling a couple of tabs at a time if there are many tabs open.

So if you e.g. got 30 tabs open and 8 virtual CPU cores (because of hyperthreading), each process will handle around 4 tabs. So switching back and forth between tabs actually means switching back and forth between processes.

If the group of tabs wasn't active for a while your operating system might have swapped parts of the process memory out. So switching to a different tab will become pretty laggy, as the disk needs to provide the memory for the tab again.

Forcing Firefox to use less processes, uses a lot less memory, as Firefox won't run 8 renderers next to eachother and not using less protection features, will also lighten up the work Firefox needs to do, as memory isn't so strictly isolated between tabs.

This allows Firefox to use more memory to actually cache web objects in memory, which is forced by setting a fixed size for the cache in memory, to avoid Firefox purging objects unnecessarily to disk, keeping things snappy.

It's worth mentioning here that if Firefox is swapping in process memory this actually blocks CPU cycles until completed. So it takes away possible CPU power while lagging. So the CPU will just wait until the data arrived from disk instead of doing something else.

So yes, if you would benchmark just rendering performance I'm sure you can see that Firefox with those tweaks might be a bit slower.

But as rendering is only a small part of what is taking time on loading a website I doubt there's much real world impact, as requesting small objects from the network rather than disk is taking probably ten times longer.


Bottom line is, I'm aiming for a snappy performance for a system with a moderate to high load with many tabs open and many add-ons installed, and those tweaks deliver this for me.

That's why I shared it.

Hope this helps making an educated decision for your use case.

Thanks for asking!

@RubenKelevra
Copy link
Author

RubenKelevra commented Apr 26, 2024

Super awesome guide, been using these tips for a few weeks.

As always with a page of random tweaks.. Don't blindly apply everything, understand what you're doing. :-)

I ended up not tuning as much memory, instead opting for disk access, as it's just as fast for me and uses less memory.

Hey @joshuataylor,

Yeah if you got a fast disk, you certainly can do that. I just found that reducing the number of processes freed a lot of memory, but Firefox feels like it drops nearly everything in the memory cache for some reason and starts lagging when scrolling on a page with a lot of images when I'm doing that. Like it rerendered the web page on the tab switch but then needs to load all the images from disk while scrolling again, creating a stuttering scrolling experience.

It nearly went away as I pinned the cache size to a fixed amount in memory.

You might see issues when using the addon Cache Longer, I've had issues with random caching issues due to sites actually expiring certain parts and those being cached, or something weird like that with certain sites.

Sure, that's possible. In this case refresh the page with a forced reload: Ctrl+F5

I don't think I've encountered it before, but surely there's a possibility if something has been updated in the background and the paths stay the same.

It would be actually really cool now I think of it to have what dnsmasq has which ismin-cache-ttl, where you can set the minimum time things should be DNS cached for. Many places use absurdly low times, and for me DNS resolution is kinda slow due to latency (I'm in a fairly remote city).

Yeah, but Firefox already does DNS caching on its own. That's what network.dnsCacheExpiration is for, IIRC.

Caching stuff is great, as it's not the download speed (for me), but the latency/request cycle etc.

Yeah, same here. Latency can be atrocious if I'm on the go. Having heavy caching certainly help to reduce the amount of request just asking for the same bytes you already fetched a thousand times before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment