Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wutdevoptab: implement __wut_fsa_get_stat_from_dir to allow optimized implemenation of readdir that avoid an addtional stat #340

Closed
wants to merge 1 commit into from

Conversation

Maschell
Copy link
Contributor

@Maschell Maschell commented Nov 27, 2023

In the FAT32 driver that is used on the Wii U each readdir and stat can be really slow, Especially in directory with many files. This functions helps dev to avoid stat calls in a readdir loop by reading the current dir entry from the DIR*.

Example usage:

std::string dirPath = "fs:/vol/external01";
DIR* dir = opendir(dirPath.c_str());
if (dir)
{
  struct dirent *ent;
  while ((ent = readdir (dir)) != NULL)
  {
    struct stat st = {};
    if (!__wut_fsa_get_stat_from_dir (dir, &st))
    {
      std::string fullpath = dirPath + "/" + ent->d_name;
      ::stat (fullpath.c_str(), &st);
    }
    OSReport ("\"%s\" size: %lld bytes\n ", ent->d_name, st.st_size);
  }
  closedir (dir);
}

Benchmarks (tested by listing the dir via ftp, so all numbers include an overhead, but I only cared of the relative not absolute numbers)
(Already using mocha 0.3.0-dev with experimental fs patches)

Directory 1, 1000 files, each file has a very long and similar name e.g. `this_is_a_normal_filename_but_long_0atcpsdz.xvg`:
     with addtional stat: 125.883 sec
 without additional stat: 1.814 sec

Directory 2, 1000 files, each file has a unique and short name (e.g. `0b2vj3w4.2nl`):
    with addtional stat: 7.747
without additional stat: 1.383 sec

I know this is not very clean and not a very optimal solution, but the impact is really huge if you look at the benchmarks. I would rather have this helper function inside wut than having it in each homebrew app.

… implemenation of readdir that avoid an addtional stat
@WinterMute
Copy link
Member

Superseded by stat extension in dirent struct devkitPro/newlib@c4ef0a7

@WinterMute WinterMute closed this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants