Speaking of newer kernels, Linux v6.2-rc1 was tagged two days ago. It comes with a much faster way to count open files for a process.
Previously the only way to do this was to getdents() for /proc/<pid>/fd, which generated a dentry for every open file one the fly, and then count the number of files in the directory.
Linux v6.2 allows you to stat /proc/pid/fd and get the number of open files in the "size" field.
Counting 1 million open files: 725ms -> 0.2ms 📉
@robryk, that's usually the main reason, same as with memory monitoring.