summaryrefslogtreecommitdiff
path: root/view/sharedcache/core/FileAccessorCache.cpp
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-04-06 20:00:00 -0400
committerMason Reed <mason@vector35.com>2025-04-06 20:00:37 -0400
commitc22d54c5d95f4d23629484579414387b0c7503ee (patch)
tree933a58c8ed3518f507f5bd4d496364411273f5b9 /view/sharedcache/core/FileAccessorCache.cpp
parent4f22a944d77f784b53ee3a37d9f1966ede1c98a4 (diff)
[SharedCache] Replace write log with callback registration for reapplying slide info
This improves performance by ~10x with the only real issue being a copy of the cache entry existing for each weak ref. Also fixes - Some old TODO's that are no longer relevant - Some function signatures not being const - FileAccessorCache not evicting enough accessors to fit under an adjusted cache size - Added a warning if we are over the global cache size in view initialization - Logger name not having a `.` in `SlideInfoProcessor::SlideInfoProcessor` - Re-added the accessor dirty check before applying slide info to fix https://github.com/Vector35/binaryninja-api/issues/6570
Diffstat (limited to 'view/sharedcache/core/FileAccessorCache.cpp')
-rw-r--r--view/sharedcache/core/FileAccessorCache.cpp37
1 files changed, 7 insertions, 30 deletions
diff --git a/view/sharedcache/core/FileAccessorCache.cpp b/view/sharedcache/core/FileAccessorCache.cpp
index e281ec5f..5fa965b3 100644
--- a/view/sharedcache/core/FileAccessorCache.cpp
+++ b/view/sharedcache/core/FileAccessorCache.cpp
@@ -32,7 +32,6 @@ FileAccessorCache& FileAccessorCache::Global()
return cache;
}
-
WeakFileAccessor FileAccessorCache::Open(const std::string& filePath)
{
const auto id = GetCacheAccessorID(filePath);
@@ -51,7 +50,7 @@ WeakFileAccessor FileAccessorCache::Open(const std::string& filePath)
}
// Evict if we are going to go above the limit.
- if (m_cache.size() >= m_cacheSize)
+ while (m_cache.size() >= m_cacheSize)
EvictLastUsed();
// Create a new file accessor and add it to the cache.
@@ -69,20 +68,6 @@ WeakFileAccessor FileAccessorCache::Open(const std::string& filePath)
return WeakFileAccessor(sharedAccessor, filePath);
}
-void FileAccessorWriteLog::AddPointer(const size_t address, const size_t pointer)
-{
- // TODO: A sharded map here would be better. see: rust dashmap
- std::unique_lock<std::shared_mutex> lock(m_persistedMutex);
- m_persistedPointers.emplace_back(address, pointer);
-}
-
-void FileAccessorWriteLog::ApplyWrites(MappedFileAccessor& accessor)
-{
- std::shared_lock<std::shared_mutex> lock(m_persistedMutex);
- for (const auto& [address, pointer] : m_persistedPointers)
- accessor.WritePointer(address, pointer);
-}
-
std::shared_ptr<MappedFileAccessor> WeakFileAccessor::lock()
{
auto sharedPtr = m_weakPtr.lock();
@@ -93,20 +78,12 @@ std::shared_ptr<MappedFileAccessor> WeakFileAccessor::lock()
m_weakPtr = FileAccessorCache::Global().Open(m_filePath).m_weakPtr;
sharedPtr = m_weakPtr.lock();
- // Apply any previously written pointers back.
- if (sharedPtr)
- m_writeLog->ApplyWrites(*sharedPtr);
+ // Call the function registered with `RegisterReviveCallback`.
+ // TODO: This races if two functions cannot acquire and revive the same file at the same time.
+ // TODO: This will be called twice.
+ if (m_reviveCallback.has_value())
+ (*m_reviveCallback)(*sharedPtr);
}
return sharedPtr;
-}
-
-void WeakFileAccessor::WritePointer(const size_t address, const size_t pointer)
-{
- // Persist the pointer after the file accessor is revived.
- m_writeLog->AddPointer(address, pointer);
-
- // And then actually apply the written pointer...
- if (auto sharedPtr = m_weakPtr.lock())
- sharedPtr->WritePointer(address, pointer);
-}
+} \ No newline at end of file