Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SharedCache] Use m_exportInfos as an export list cache #6197

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Commits on Nov 25, 2024

  1. [SharedCache] Use m_exportInfos as an export list cache

    `SharedCache::ParseExportTrie` is getting called a lot during DSC library loading and analysis. In large part due to the hot path `SharedCache::FindSymbolAtAddrAndApplyToAddr`. Its unnecessary for it to be being called more than once per DSC header as the export list symbol information is stored in `SharedCache::m_exportInfos`.
    
    This commit adds the function `SharedCache::GetExportListForHeader`, which will either return the header's list of symbol information cached in `SharedCache::m_exportInfos` or call `SharedCache::ParseExportTrie` and cache the results in `SharedCache::m_exportInfos`.
    
    This should also improve the execution time of `SharedCache::LoadAllSymbolsAndWait`.
    
    Further improvement here would be to add locking to `SharedCache::GetExportListForHeader` so that races don't result in redundant parsing of the export trie for the same header if multiple threads call `SharedCache::GetExportListForHeader` at the same time for the same header. This only really matters during initial loading because from what I can tell that parses all the export trie's anyway.
    WeiN76LQh authored and WeiN76LQh committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    b7ccf06 View commit details
    Browse the repository at this point in the history

Commits on Nov 26, 2024

  1. [SharedCache] Add parameter to SharedCache::InitializeHeader to che…

    …ck if `m_exportInfos` was modified
    
    This probably makes more sense than the current solution of using execution of the callback parameter to determine if `m_exportInfos` was modified.
    WeiN76LQh authored and WeiN76LQh committed Nov 26, 2024
    Configuration menu
    Copy the full SHA
    64174ee View commit details
    Browse the repository at this point in the history
  2. [SharedCache] Improve the types for m_exportInfos

    This commit changes 2 things;
    1. `m_exportInfos` is now a map where its values are also a map rather than a vector of pairs. The reason for this is that `SharedCache::FindSymbolAtAddrAndApplyToAddr` is a hot path which does by far the most accesses to `m_exportInfos`. In that function it must find the correct symbol for a given address so a map lookup will be much quicker than iterating a vector. The other use cases of `m_exportInfos` would prefer a vector but they are executed very infrequently.
    2. The symbols are stored in `m_exportInfos` as references to the `Symbol` type. This makes more sense because otherwise there is a lot of time spent converting to and from a `Symbol` type and a pair of `BNSymbolType` + a `std::string`.
    WeiN76LQh authored and WeiN76LQh committed Nov 26, 2024
    Configuration menu
    Copy the full SHA
    6edb250 View commit details
    Browse the repository at this point in the history
  3. [SharedCache] Only setup undo actions and bulk modify in `SharedCache…

    …::FindSymbolAtAddrAndApplyToAddr` if a symbol is found
    WeiN76LQh authored and WeiN76LQh committed Nov 26, 2024
    Configuration menu
    Copy the full SHA
    9e7d6e2 View commit details
    Browse the repository at this point in the history
  4. [SharedCache] Make m_exportInfos map's values a shared_ptr

    This avoids expensive copying when returning a value from the map in `SharedCache::GetExportListForHeader`. Additionally it ensures that the value stays alive and at the same location in memory if `m_exportInfos` is modified and requires its storage to be re-allocated.
    
    I was unable to use a `unique_ptr` instead of a `shared_ptr` because of copy semantics with `m_exportInfos` in `ViewStateCacheStore`. I don't see things being any worse using `shared_ptr` instead of `unique_ptr` anyway and it means less code changes.
    WeiN76LQh authored and WeiN76LQh committed Nov 26, 2024
    Configuration menu
    Copy the full SHA
    202a792 View commit details
    Browse the repository at this point in the history
  5. [SharedCache] Remove commenting out of line from debugging

    WeiN76LQh authored and WeiN76LQh committed Nov 26, 2024
    Configuration menu
    Copy the full SHA
    c83ec00 View commit details
    Browse the repository at this point in the history