SaveState: Only rehash functions in code a load changed

Every load hashed all known functions again, for the replacement hooks:
2.4-6 ms, about half the load. Functions in module code the load left as
it was keep their hash, so only the rest is hashed now (0.5-1 ms). The
code is compared on every load for this, not only with a JIT.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-10-19 20:18:46 +02:00
1 parent a62aa69986
commit f45f4d5c85
5 files changed
+43 -8

No files matched your search

+10 -1
View File
@@ -534,6 +534,13 @@ static void __KernelModuleInit() {
eventModuleLoadDone = CoreTiming::RegisterEvent("LoadModuleDone", &__KernelLoadModuleDone);
}
// Set for the next load by the savestate code: code the load left as it was.
static std::vector<std::pair<u32, u32>> g_unchangedCodeOnLoad;
void __KernelModuleSetUnchangedCodeOnLoad(std::vector<std::pair<u32, u32>> unchanged) {
g_unchangedCodeOnLoad = std::move(unchanged);
}
std::vector<std::pair<u32, u32>> __KernelModuleCodeRanges() {
std::vector<std::pair<u32, u32>> ranges;
u32 error;
@@ -615,7 +622,9 @@ void __KernelModuleDoState(PointerWrap &p) {
}
// The functions were found in memory from before the load, where other code may have been
// (an overlay module, say.) Hash them from what's there now, so a hook only goes where it matches.
MIPSAnalyst::RehashFunctions();
// Only what the load may have changed: hashing it all again takes milliseconds.
MIPSAnalyst::RehashFunctions(g_unchangedCodeOnLoad);
g_unchangedCodeOnLoad.clear();
if (g_Config.bFuncReplacements) {
MIPSAnalyst::ReplaceFunctions();
}