summaryrefslogtreecommitdiff
path: root/view/sharedcache/core/VM.cpp
diff options
context:
space:
mode:
authorMark Rowe <mrowe@bdash.net.nz>2024-11-24 14:18:25 -0800
committerkat <kat@vector35.com>2025-01-27 13:55:18 -0500
commit9c9f5085e010059c813d2285ddff79b542c76834 (patch)
tree1f6438c591dd6426775abf402013138be5aceb82 /view/sharedcache/core/VM.cpp
parentaf7715d0e86352ca78badc2272a4cb79cf5aef6a (diff)
[SharedCache] Optimize `ReadExportNode`
`ReadExportNode` is called a lot during the initial load of the shared cache and thus impacts how long it takes for the UI to become responsive. This is a collection of optimizations that cut the time spent within `ReadExportNode` by 50%: 1. Pass iterators to `ReadExportNode` rather than a `DataBuffer` + offset. The lack of inlining in `DataBuffer`'s `operator[]` kills performance. Ideally this would have used `std::span`, but that would require bumping the minimum C++ version to C++20. 2. Add `MMappedFileAccessor::ReadSpan` so that `ReadExportNode` can operate directly on the mapped data without first copying it. 3. Removes a call to `GetAnalysisFunctionsForAddress` whose result was unused. 4. Use `std::find` to find the nul at the end of strings rather than assembling the string a character at a time. This avoids repeatedly growing the string. 5. Avoid the usual `Symbol` constructor in favor of `BNCreateSymbol`. The `Symbol` constructor has over head in two forms: 1. It has a `NameSpace` as an argument. Creating / destroying this allocates and deallocates memory We could create a single instance and reuse it for all calls, but... 2. The constructor copies all fields of the `NameSpace` to the heap before calling `BNCreateSymbol` and then deallocates them afterwards. This seems unnecessary, and adds a non-trivial amount of overhead. This can go back to directly constructing the `Symbol` once the constructors are improved.
Diffstat (limited to 'view/sharedcache/core/VM.cpp')
-rw-r--r--view/sharedcache/core/VM.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/view/sharedcache/core/VM.cpp b/view/sharedcache/core/VM.cpp
index 72d6d202..358a1dd8 100644
--- a/view/sharedcache/core/VM.cpp
+++ b/view/sharedcache/core/VM.cpp
@@ -465,6 +465,17 @@ BinaryNinja::DataBuffer MMappedFileAccessor::ReadBuffer(size_t address, size_t l
return BinaryNinja::DataBuffer(data, length);
}
+std::pair<const uint8_t*, const uint8_t*> MMappedFileAccessor::ReadSpan(size_t address, size_t length)
+{
+ if (address > m_mmap.len)
+ throw MappingReadException();
+ if (address + length > m_mmap.len)
+ throw MappingReadException();
+ const uint8_t* data = (&(((uint8_t*)m_mmap._mmap)[address]));
+ return {data, data + length};
+}
+
+
void MMappedFileAccessor::Read(void* dest, size_t address, size_t length)
{
if (address > m_mmap.len)