From 04578edf6550156350f475067ab4df29896b8493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 11 Sep 2021 15:02:52 +0200 Subject: [PATCH 1/6] Hide directories games should not know about from them. Stops some games from spending lots of time iterating over files they should not care about. Helps the performance issues in #13847 quite a bit. --- Core/HLE/sceIo.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 0c4dcf20e1..c1e3f9e998 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -21,6 +21,7 @@ #include #include "Common/Thread/ThreadUtil.h" +#include "Common/TimeUtil.h" #include "Common/Profiler/Profiler.h" #include "Common/File/FileUtil.h" @@ -2321,10 +2322,48 @@ static u32 sceIoDopen(const char *path) { DirListing *dir = new DirListing(); SceUID id = kernelObjects.Create(dir); + double time = time_now_d(); dir->listing = pspFileSystem.GetDirListing(path); dir->index = 0; dir->name = std::string(path); + // Blacklist some directories that games should not be able to find out about. + // Speeds up directory iteration on slow Android Scoped Storage implementations :( + // Might also want to filter out PSP/GAME if not a homebrew, maybe also irrelevant directories + // in PSP/SAVEDATA, though iffy to know which ones are irrelevant.. + if (!strcmp(path, "ms0:/PSP")) { + static const char *const pspFolderBlacklist[] = { + "CHEATS", + "PPSSPP_STATE", + "PLUGINS", + "SYSTEM", + "SCREENSHOT", + "TEXTURES", + "DUMP", + }; + std::vector filtered; + for (const auto &entry : dir->listing) { + bool blacklisted = false; + for (auto black : pspFolderBlacklist) { + if (!strcasecmp(entry.name.c_str(), black)) { + blacklisted = true; + break; + } + } + + if (!blacklisted) { + filtered.push_back(entry); + } + } + + dir->listing = filtered; + } + + double diff = time_now_d() - time; + //if (diff > 0.01) { + ERROR_LOG(IO, "sceIoDopen(%s) took %0.3f seconds", path, diff); + //} + // TODO: The result is delayed only from the memstick, it seems. return id; } @@ -2349,7 +2388,7 @@ static u32 sceIoDread(int id, u32 dirent_addr) { SceIoDirEnt *entry = (SceIoDirEnt*) Memory::GetPointer(dirent_addr); if (dir->index == (int) dir->listing.size()) { - DEBUG_LOG(SCEIO, "sceIoDread( %d %08x ) - end of the line", id, dirent_addr); + DEBUG_LOG(SCEIO, "sceIoDread( %d %08x ) - end", id, dirent_addr); entry->d_name[0] = '\0'; return 0; } From 1f81876ab13debe9e1f7516932e7b9c44faa95da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 11 Sep 2021 15:04:53 +0200 Subject: [PATCH 2/6] Cleanup --- Core/HLE/sceIo.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index c1e3f9e998..ef842b92f5 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -2322,7 +2322,6 @@ static u32 sceIoDopen(const char *path) { DirListing *dir = new DirListing(); SceUID id = kernelObjects.Create(dir); - double time = time_now_d(); dir->listing = pspFileSystem.GetDirListing(path); dir->index = 0; dir->name = std::string(path); @@ -2359,11 +2358,6 @@ static u32 sceIoDopen(const char *path) { dir->listing = filtered; } - double diff = time_now_d() - time; - //if (diff > 0.01) { - ERROR_LOG(IO, "sceIoDopen(%s) took %0.3f seconds", path, diff); - //} - // TODO: The result is delayed only from the memstick, it seems. return id; } From 830d205839257328f3215411f04aaf3b1b482c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 11 Sep 2021 15:11:56 +0200 Subject: [PATCH 3/6] Optimize savedata size calculation --- UI/GameInfoCache.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index 3d8db8fd7c..00e3395eaf 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -152,12 +152,9 @@ u64 GameInfo::GetSaveDataSizeInBytes() { for (size_t j = 0; j < saveDataDir.size(); j++) { std::vector fileInfo; File::GetFilesInDir(saveDataDir[j], &fileInfo); - // Note: GetFilesInDir does not fill in fileSize properly. - for (size_t i = 0; i < fileInfo.size(); i++) { - File::FileInfo finfo; - File::GetFileInfo(fileInfo[i].fullName, &finfo); - if (!finfo.isDirectory) - filesSizeInDir += finfo.size; + for (auto const &file : fileInfo) { + if (!file.isDirectory) + filesSizeInDir += file.size; } if (filesSizeInDir < 0xA00000) { // HACK: Generally the savedata size in a dir shouldn't be more than 10MB. @@ -351,7 +348,9 @@ public: if (!info_->LoadFromPath(gamePath_)) { return; } + // In case of a remote file, check if it actually exists before locking. + // This is likely not necessary at a if (!info_->GetFileLoader()->Exists()) { return; } From 369ae031dea0f348ddd8171c929178ec686666fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 11 Sep 2021 15:12:55 +0200 Subject: [PATCH 4/6] Optimize install data size calculation. --- UI/GameInfoCache.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index 00e3395eaf..803315aa77 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -176,12 +176,11 @@ u64 GameInfo::GetInstallDataSizeInBytes() { for (size_t j = 0; j < saveDataDir.size(); j++) { std::vector fileInfo; File::GetFilesInDir(saveDataDir[j], &fileInfo); - // Note: GetFilesInDir does not fill in fileSize properly. - for (size_t i = 0; i < fileInfo.size(); i++) { - File::FileInfo finfo; - File::GetFileInfo(fileInfo[i].fullName, &finfo); - if (!finfo.isDirectory) - filesSizeInDir += finfo.size; + for (auto const &file : fileInfo) { + // TODO: Might want to recurse here? Don't know games that use directories + // for install-data though. + if (!file.isDirectory) + filesSizeInDir += file.size; } if (filesSizeInDir >= 0xA00000) { // HACK: Generally the savedata size in a dir shouldn't be more than 10MB. From b075b7917500d4ebfbf049a2f7dcfca5c893c4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 11 Sep 2021 15:14:44 +0200 Subject: [PATCH 5/6] Also hide SHADERS directory from games --- Core/HLE/sceIo.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index ef842b92f5..64af3b4ebb 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -2339,6 +2339,7 @@ static u32 sceIoDopen(const char *path) { "SCREENSHOT", "TEXTURES", "DUMP", + "SHADERS", }; std::vector filtered; for (const auto &entry : dir->listing) { From 09f65db91c6eff0f65d50d2ee14445f4ec3a9cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 11 Sep 2021 15:35:11 +0200 Subject: [PATCH 6/6] Cleanup --- Core/FileSystems/MetaFileSystem.cpp | 1 - Core/HLE/sceIo.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/Core/FileSystems/MetaFileSystem.cpp b/Core/FileSystems/MetaFileSystem.cpp index 6ecd36226c..173cf4a863 100644 --- a/Core/FileSystems/MetaFileSystem.cpp +++ b/Core/FileSystems/MetaFileSystem.cpp @@ -654,7 +654,6 @@ u64 MetaFileSystem::getDirSize(const std::string &dirPath) { for (auto file : allFiles) { if (file.name == "." || file.name == "..") continue; - _assert_(!file.name.empty()); if (file.type == FILETYPE_DIRECTORY) { result += getDirSize(dirPath + file.name); } else { diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 64af3b4ebb..d290d540b0 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -21,7 +21,6 @@ #include #include "Common/Thread/ThreadUtil.h" -#include "Common/TimeUtil.h" #include "Common/Profiler/Profiler.h" #include "Common/File/FileUtil.h"