Skip to content

Commit

Permalink
MemCache: ignore objects >= 100Mb (blackout issue)
Browse files Browse the repository at this point in the history
  • Loading branch information
Renee Koecher committed Jul 30, 2022
1 parent d346f65 commit e9ee9c9
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions XIPivot.Ashita/plugin/AshitaInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ namespace XiPivot
imgui->LabelText(u8"allocation", "%.2fmb", stats.allocation / 1048576.0f);
imgui->LabelText(u8"used size", "%.2fmb", stats.used / 1048576.0f);
imgui->LabelText(u8"objects", "%d", stats.activeObjects);
imgui->LabelText(u8"ignored", "%d", stats.cacheIgnored);
imgui->Separator();

imgui->LabelText(u8"next purge in", "%ds", m_nextCachePurge - time(nullptr));
Expand Down
1 change: 0 additions & 1 deletion XIPivot.Ashita/plugin/AshitaInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ namespace XiPivot
/* helpers for GUI config */
void renderOverlayConfigUI(IGuiManager* imgui);
void renderMemCacheConfigUI(IGuiManager* imgui);
void renderAboutUI(IGuiManager* imgui);
void renderCacheStatsUI(IGuiManager* imgui);

std::vector<std::string> listAvailableOverlays() const;
Expand Down
2 changes: 1 addition & 1 deletion XIPivot.Ashita/plugin/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extern "C" {
strcpy_s(info->Name, sizeof(info->Name), "XIPivot");

info->InterfaceVersion = ASHITA_INTERFACE_VERSION;
info->PluginVersion = 0.46f;
info->PluginVersion = 0.47f;
info->Priority = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion XIPivot.Ashita_v4/polplugin/AshitaInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace XiPivot
{
static constexpr auto PluginName = "pivot";
static constexpr auto PluginAuthor = "Heals";
static constexpr auto PluginVersion = 4.1002;
static constexpr auto PluginVersion = 4.1104;
static constexpr auto PluginUrl = "https://github.com/Shirk/XIPivot";
static constexpr auto PluginDescr = "Runtime DAT, sfx and bgm replacement manager.";
static constexpr auto PluginCommand = "pivot";
Expand Down
1 change: 1 addition & 0 deletions XIPivot.Ashita_v4/polplugin/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ namespace XiPivot
imgui->LabelText("allocation", "%.2fmb", stats.allocation / 1048576.0f);
imgui->LabelText("used size", "%.2fmb", stats.used / 1048576.0f);
imgui->LabelText("objects", "%d", stats.activeObjects);
imgui->LabelText("ignored", "%d", stats.cacheIgnored);
imgui->Separator();

imgui->LabelText("next purge in", "%ds", m_cacheNextPurge - time(nullptr));
Expand Down
20 changes: 17 additions & 3 deletions XIPivot.Core/src/MemCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ namespace XiPivot
{
/* static member initialisation */

namespace {
static constexpr size_t sMaxCacheObjectSize = 104857599U; // 100MB -1byte
}
MemCache* MemCache::s_instance = nullptr;

MemCache::pFnReadFile MemCache::s_procReadFile = ReadFile;
Expand Down Expand Up @@ -79,7 +82,7 @@ namespace XiPivot

MemCache::MemCache()
: m_hooksSet(false),
m_stats({ 0, 0, 0, 0, 0 }),
m_stats({ 0, 0, 0, 0, 0, 0 }),
m_logDebug(ILogProvider::LogLevel::Discard)
{
m_logger = DummyLogProvider::instance();
Expand Down Expand Up @@ -214,6 +217,9 @@ namespace XiPivot
++it;
}
}

m_stats.cacheIgnored = 0;

return objectsPurged;
}

Expand Down Expand Up @@ -270,12 +276,20 @@ namespace XiPivot
return nullptr;
}

size_t size = GetFileSize(hRef, nullptr);
if (size > sMaxCacheObjectSize)
{
/* do NOT cache objects above sMaxCacheObjectSize lower the risk of "blackouts"
* caused by XI running out of available memory */
m_logger->logMessageF(ILogProvider::LogLevel::Debug, "getCachedObject: object size exceeds limit, no cache object created.");
++m_stats.cacheIgnored;
return nullptr;
}

/* try and create a new object on the fly and store it */
CacheObject* obj = new (std::nothrow) CacheObject;
if (obj != nullptr)
{
size_t size = GetFileSize(hRef, nullptr);

if (m_stats.used + size <= m_stats.allocation)
{
memset(obj, 0, sizeof(CacheObject));
Expand Down
1 change: 1 addition & 0 deletions XIPivot.Core/src/MemCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ namespace XiPivot

unsigned cacheHits;
unsigned cacheMisses;
unsigned cacheIgnored;

unsigned activeObjects;
};
Expand Down
2 changes: 1 addition & 1 deletion XIPivot.Windower/lua/XIPivot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

_addon.name = 'XIPivot'
_addon.author = 'Heals'
_addon.version = '0.4.6'
_addon.version = '0.4.7'
_addon.command = 'pivot'

config = require('config')
Expand Down

0 comments on commit e9ee9c9

Please sign in to comment.