The more RAM you install, the more macOS will use it to try and improve performance.
Up to a limit. A 10 GB file cache tends to be highly speculative.
Programs may not be written to take advantage of extremely large amounts of memory. I'd think that fsck_hfs would like to use more than 3GB of memory (to store deeper trees and other more elaborate data structures), but no.
Safari, with a couple dozen tabs might use 8GB.
From what I can tell. Abbyy Finereader, divides the workload among 4 processes, each using a gigabyte... Might be different with a hyperthreaded processor, or a cpu with more than four cores...
Photoshop, and a few other adobe products like to grab enormous amounts of ram for themselves, but whether it amounts to a speed advantage depends on the circumstances.
Remember, good programmers are careful about memory usage. A scheme that deliberately uses more memory in order to produce a speed advantage must be carefully profiled.
Virtual machines tend to require the most amount of memory, but then you might have to consider whether the VM really needs all 8 GB, or 16 GB, or can do the job with 4 GB...
40 GB is an enormous amount of RAM, and if it ends up being slower than the stock 8GB due to a timing mismatch you'd probably notice the slowdown, before you'd notice the effects of having more.