Kernel: Don't traverse the whole tree in find_regions_intersecting

When using the default iterator, the region tree is traversed in
ascending order. This mean that as soon as we find a region that is
above the tested range, we can safely exit the loop.

This was a major bottleneck in test-js, with this patch the runtime goes
from 6.761s to 4.680 (using a best-of-five).
This commit is contained in:
Lucas Chollet authored and Sönke Holz committed 2026-10-29 15:03:29 +01:00
1 parent b5d4da532a
commit ccdd6504f9
1 file changed
+8 -1
+8 -1
View File
@@ -265,12 +265,19 @@ ErrorOr<Vector<Region*, 4>> AddressSpace::find_regions_intersecting(VirtualRange
return regions;
for (auto iter = m_region_tree.regions().begin_from(*found_region); !iter.is_end(); ++iter) {
auto const& iter_range = (*iter).range();
if (iter_range.base() < range.end() && iter_range.end() > range.base()) {
if (iter_range.end() <= range.base())
continue;
if (iter_range.base() < range.end()) {
TRY(regions.try_append(&*iter));
total_size_collected += (*iter).size() - iter_range.intersect(range).size();
if (total_size_collected == range.size())
break;
} else {
// We're iterating the tree in ascending order, so as soon as we reach the
// first region that is outside the range, we can bail out.
break;
}
}