{"id":38923,"date":"2004-06-11T06:58:00","date_gmt":"2004-06-11T06:58:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/06\/11\/a-hidden-performance-cost-of-regional-windows\/"},"modified":"2004-06-11T06:58:00","modified_gmt":"2004-06-11T06:58:00","slug":"a-hidden-performance-cost-of-regional-windows","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040611-00\/?p=38923","title":{"rendered":"A hidden performance cost of regional windows"},"content":{"rendered":"<p>\nRegional windows are neat, but they come at a cost.\nMost of the cost you can see directly.\nFor example, constantly changing the region clearly generates\na cost since you have to sit there and generate new regions all\nthe time.\n<\/p>\n<p>\nOne question that came up on an internal performance alias\nhighlights one of the hidden costs of regional windows:\nThe putative window rectangle.\n<\/p>\n<p>\nSuppose you have a large window but set a small window region.\nHow much worse is this than haveing a small window with a small\nwindow region?\n<\/p>\n<p>\nQuite a bit, actually.\n<\/p>\n<p>\nHit-testing is one of the most common operations performed by\na window manager. Given a point on the screen, find the window\nthat it corresponds to.  To speed this up, the window rectangle\nis used to rule out windows quickly.  For example, if a window&#8217;s\nrectangle is (0,0)-(100,100) then the point (200,10) is clearly\nnot within the window since it doesn&#8217;t fit in the rectangle.\nRectangle tests are fast.\n<\/p>\n<p>\nIf the window is regional, then the rectangle test is not good\nenough, because the point may exist within the rectangle but outside\nthe region.  In that case, the point must be tested against the\nwindow region itself.\n<\/p>\n<p>\nBut Windows uses the window rectangle as a &#8220;quick test&#8221; to see\nif the region is worth checking.  If the point lies outside the\nrectangle, then the window manager doesn&#8217;t even bother checking\nthe region, which is good because region testing is comparatively slow.\n<\/p>\n<p>\nIn other word, the pseudocode for hit-testing goes something like\nthis:\n<\/p>\n<pre>\nif (point is outside window rectangle)\n  return no-hit;\nelse if (window has no region)\n  return hit;\nelse if (point is inside region)\n  return hit;\nelse\n  return no-hit;\n<\/pre>\n<p>\nSo if you create a huge window with a tiny region, the window\nmanager can&#8217;t rule out the hit-test based on the first (fast)\nrectangle test.  It has to go to the third (slower) region test.\n<\/p>\n<p>\nMoral of the story: When using regional windows,\ntry to keep the window rectangle reasonably close to the bounding\nbox of the region itself.\nIt helps the window manager decide more quickly\nwhich window a point belongs to.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-38923","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/38923","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=38923"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/38923\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=38923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=38923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=38923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}