Assuming NTFS, there is a limit of 4 billion files per volume (2 ^ 32 - 1). This is a common limit for all folders on a volume (including operating system files, etc.)
A large number of files in one folder should not be a problem; NTFS uses the B + tree for quick retrieval. Microsoft recommends disabling short file name creation (a function that allows you to extract mypictureofyou.html as mypic ~ 1.htm).
I do not know if there is a performance advantage for segmenting them into multiple directories; I assume that there would be no advantage because NTFS was designed for performance with large directories.
If you decide to segment them into several directories, use the hash function in the file name to get the directory name (and not the directory name, which is the first letter of the file name, for example), so each subdirectory has about the same number of files.
source share