Skip to content

Switch: list the SD card once for the disc index, without a stat per file - #43

Open
TomasUribe wants to merge 1 commit into
dorPXP:android-portfrom
TomasUribe:switch-fast-disc-index
Open

TomasUribe wants to merge 1 commit into
dorPXP:android-portfrom
TomasUribe:switch-fast-disc-index

Conversation

@TomasUribe

Copy link
Copy Markdown
Contributor

On Switch, starting Retro Rewind spent most of its time in DVDInit's disc index. The pack has thousands of files, and walking them with std::filesystem asks for each file's type and size separately. On the Switch that's several file system requests per file (the entry type, then open, get size, close), so the startup cover sat still for close to a minute.

This lists the SD card with its own directory reads instead:

  • Disc index: WalkDirectory lists sdmc:/ folders with fsDirRead (new switch_sd_list.{h,cpp}), which returns every file's size along with its name. The visitors now get that size (WalkEntry) instead of statting each entry again. Other platforms, and any folder that can't be opened this way, walk with std::filesystem exactly as before.
  • Single files: Riivolution's <file>/<folder> existence checks (RiivoCollectMappings) and the disc index's single-file mappings take their type and size from one cached listing of each folder (SwitchSdList::Lookup). Retro Rewind's XML names 152 files, each a stat or two before. Anything the listing can't answer, such as a name spelled with different case, still falls back to a stat.

The resulting index is the same: same entries and sizes, in the order recursive_directory_iterator gives (a folder before its contents).

Measured on my Switch (Mariko, Atmosphère 1.12.1, firmware 23.0.1, Retro Rewind 6.13.5, build from source): the disc index is 2,037 disc files plus 5,454 overlay registrations in 1,980 ms. The first game frame comes 9.6 s after the launcher hands over; before, the startup cover sat still for about 55 s at this point. The game played normally afterwards, online included.

🤖 Generated with Claude Code

…file

Starting Retro Rewind spent most of its time in DVDInit's disc index: Retro Rewind's pack has
thousands of files, and std::filesystem asks for each one's type and size separately, several
file system requests each on the Switch (the entry's type, then open, size and close).

- WalkDirectory lists sdmc:/ folders with fsDirRead (switch_sd_list.cpp), which carries every
  file's size, and hands its visitors the size it already has. Elsewhere, or for a folder that
  cannot be opened this way, it walks with std::filesystem as before.
- Riivolution's file and folder patches, and the disc index's single-file mappings, take their
  type and size from one cached listing of each folder (SwitchSdList::Lookup): Retro Rewind's XML
  names 152 files, which were a stat or two each. Anything the listing can't answer still stats.

Measured on a Switch (Mariko, Retro Rewind 6.13.5): the disc index is 2037 disc files plus 5454
overlay registrations in 1980 ms, and the first game frame comes 9.6 s after the launcher hands
over; the startup cover used to sit still for about 55 s here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant