mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
Kernel: Add a 1-deep cache to Process::region_from_range()
This simple cache gets hit over 70% of the time on "g++ Process.cpp" and shaves ~3% off the runtime.
This commit is contained in:
parent
ae0c435e68
commit
8d9dd1b04b
Notes:
sideshowbarker
2024-07-19 09:57:16 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/8d9dd1b04bb
2 changed files with 14 additions and 1 deletions
|
@ -223,6 +223,8 @@ Region* Process::allocate_region_with_vmobject(VirtualAddress vaddr, size_t size
|
|||
bool Process::deallocate_region(Region& region)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
if (m_region_lookup_cache.region == ®ion)
|
||||
m_region_lookup_cache.region = nullptr;
|
||||
for (int i = 0; i < m_regions.size(); ++i) {
|
||||
if (&m_regions[i] == ®ion) {
|
||||
m_regions.remove(i);
|
||||
|
@ -234,10 +236,16 @@ bool Process::deallocate_region(Region& region)
|
|||
|
||||
Region* Process::region_from_range(const Range& range)
|
||||
{
|
||||
if (m_region_lookup_cache.range == range && m_region_lookup_cache.region)
|
||||
return m_region_lookup_cache.region;
|
||||
|
||||
size_t size = PAGE_ROUND_UP(range.size());
|
||||
for (auto& region : m_regions) {
|
||||
if (region.vaddr() == range.base() && region.size() == size)
|
||||
if (region.vaddr() == range.base() && region.size() == size) {
|
||||
m_region_lookup_cache.range = range;
|
||||
m_region_lookup_cache.region = ®ion;
|
||||
return ®ion;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -452,6 +452,11 @@ private:
|
|||
Region* region_containing(const Range&);
|
||||
|
||||
NonnullOwnPtrVector<Region> m_regions;
|
||||
struct RegionLookupCache {
|
||||
Range range;
|
||||
Region* region { nullptr };
|
||||
};
|
||||
RegionLookupCache m_region_lookup_cache;
|
||||
|
||||
pid_t m_ppid { 0 };
|
||||
mode_t m_umask { 022 };
|
||||
|
|
Loading…
Reference in a new issue