A hidden performance cost of regional windows

Raymond Chen


Regional windows are neat, but they come at a cost. Most of the cost you can see directly. For example, constantly changing the region clearly generates a cost since you have to sit there and generate new regions all the time.

One question that came up on an internal performance alias highlights one of the hidden costs of regional windows: The putative window rectangle.

Suppose you have a large window but set a small window region. How much worse is this than haveing a small window with a small window region?

Quite a bit, actually.

Hit-testing is one of the most common operations performed by a window manager. Given a point on the screen, find the window that it corresponds to. To speed this up, the window rectangle is used to rule out windows quickly. For example, if a window’s rectangle is (0,0)-(100,100) then the point (200,10) is clearly not within the window since it doesn’t fit in the rectangle. Rectangle tests are fast.

If the window is regional, then the rectangle test is not good enough, because the point may exist within the rectangle but outside the region. In that case, the point must be tested against the window region itself.

But Windows uses the window rectangle as a “quick test” to see if the region is worth checking. If the point lies outside the rectangle, then the window manager doesn’t even bother checking the region, which is good because region testing is comparatively slow.

In other word, the pseudocode for hit-testing goes something like this:

if (point is outside window rectangle)
  return no-hit;
else if (window has no region)
  return hit;
else if (point is inside region)
  return hit;
  return no-hit;

So if you create a huge window with a tiny region, the window manager can’t rule out the hit-test based on the first (fast) rectangle test. It has to go to the third (slower) region test.

Moral of the story: When using regional windows, try to keep the window rectangle reasonably close to the bounding box of the region itself. It helps the window manager decide more quickly which window a point belongs to.


Comments are closed. Login to edit/delete your existing comments