Files app become very sluggish when trash has many files

I think you’ll generally find that if a directory has a large number of files, the time to open a file in that directory becomes long, linear search time. Consider the trash as a directory.
If you are looking to create a large number of files, consider doing something like you’ll see in a number of caching applications. Suppose your lotsoffiles directory is where you’re going to keep these files. Instead of saving file ‘abc123456’ in lotsoffiles/abc123456, save it in lotsoffiles/a/b/abc123456, using the first two letters to create a ‘hash bucket’ for that file. There is a cost to this method, that of checking for a subdirectory ‘a’ in the toplevel lotsoffiles, and for a sub-subdirectory ‘b’. But now, when you later want to read that file, you won’t be forcing the system to do a linear search of the toplevel, instead (presuming your file names are somewhat uniformly spread out over the alphabet) the system will be searching a smaller directory.
You may see samples of this method in use in your home directory if there’s a .cache or .ccache directory there.

2 Likes