The situation is somewhat surprising. UFS is an unusual filesystem for a production Linux install. UFS write-access under Linux normally needs to be explicitly enabled in the kernel, since it has been considered experimental for many years:
CONFIG_UFS_FS_WRITE: UFS file system write support (DANGEROUS)
Say Y here if you want to try writing to UFS partitions. This is
experimental, so you should back up your UFS partitions beforehand.
Like many traditional file systems, UFS uses sequential file lookups within directories. This does indeed lead to performance problems for directories with many files, since the search time grows linearly with number of files. In the BSDs, where UFS is often the default file system, this issue lead directly to the creation of Dirhash, a hash table lookup for directories, which significantly improves performance.
As far as I know, UFS support under Linux does not use Dirhash. Therefore, you can expect to experience increasing performance issues as the number of files in your directory grows. In terms of sequential access, 400K files is a lot, and you can expect a significant performance hit.
Splitting files between sub-directories effectively manages the sequential access problem. Alternatively, you could move to a filesystem that supports a more sophisticated file storage structure. For example, XFS implements fast file access for large directories through the use of B+ trees.
Your second concern was about inodes. Usually, the number of inodes on your filesystem is fixed, and this is usually a function of the amount of space available at filesystem creation time. For example,
/etc/mke2fs.conf holds the default inode ratio (number of inodes per x bytes) for ext filesystems.
Normally, this number is far larger than the number of files you are likely to create, and is not a cause for concern. However, you can check your inode usage with
df -i. If inode limitations actually are likely to be a problem, messing with directories will not help you, since inodes are a filesystem-wide concept, independent of directory. In this case, you would be forced to recreate the filesystem, setting the inode parameter (