{"id":119,"date":"2019-06-24T00:21:11","date_gmt":"2019-06-24T00:21:11","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=119"},"modified":"2019-06-21T00:46:01","modified_gmt":"2019-06-21T00:46:01","slug":"speed-tip-with-popupmenus","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2019\/06\/24\/speed-tip-with-popupmenus\/","title":{"rendered":"Speed tip with popupmenus"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In a different forum a user reminded me of a speed tip that had cropped up once or twice over the years. It has to do with popupmenus.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Basically on older versions of macOS if you did<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nPopupMenu1.ListIndex = -1\nFor i As Integer = 0 To 1000\n  PopupMenu1.AddRow Str(i)\nNext<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This behaved not so badly although there is a slightly faster variation<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But on Mojave this is noticeably slow. This simple loop could take as much as a second on Mojave in dark mode.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To speed it up it was discovered that if you added an item in position(0), set the listindex to 0 then added all the items and removed that extraneous item at position 0 then the speed was hardly impacted at all.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PopupMenu2.AddRow \"\"\nPopupMenu2.ListIndex = 0\nFor i As Integer = 0 To 1000\n  PopupMenu2.AddRow Str(i)\nNext\nPopupMenu2.RemoveRow 0\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">My testing on 10.12.6 and 10.14.5,  in light and dark modes, using 2019r1.1 with the following code shows the differences in the debugger<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Sub Action()\n  Dim startTime1 As Double \n  Dim endTime1 As Double\n  \n  Dim startTime2 As Double \n  Dim endTime2 As Double\n  \n  \n  startTime1 = Microseconds\n  PopupMenu1.ListIndex = -1\n  For i As Integer = 0 To 1000\n    PopupMenu1.AddRow Str(i)\n  Next\n  endTime1 = Microseconds\n  \n  \n  startTime2 = Microseconds\n  PopupMenu2.AddRow \"\"\n  PopupMenu2.ListIndex = 0\n  For i As Integer = 0 To 1000\n    PopupMenu2.AddRow Str(i)\n  Next\n  PopupMenu2.RemoveRow 0\n  endTime2 = Microseconds\n  \n  \n  Dim total1 As Double = (endtime1 - startTime1) \/ 1000000\n  Dim total2 As Double = (endtime2 - startTime2) \/ 1000000\n  \n  label1.text = str(total1, \"###.00000\")\n  label2.text = str(total2, \"###.00000\")\n\nEnd Sub<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And the results are surprising and consistent between running in the debugger &amp; a built application<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Debug              Total1 (slow)       Total2 (fast)\n 10.12.6            0.037 sec            0.012 sec\n 10.14.5 (light)    1.152 sec            0.019 sec\n 10.14.5 (dark)     1.158 sec            0.019 sec \n Built x86_64       Total1 (slow)       Total2 (fast)\n 10.12.6            0.036 sec            0.010 sec\n 10.14.5 (light)    1.174 sec            0.017 sec\n 10.14.5 (dark)     1.174 sec            0.028 sec<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Whatever changed in Mojave Popupmenus got very slow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Heads up.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks to Jim McKay for <a href=\"http:\/\/feedback.xojo.com\/case\/54760\">reporting this <\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a different forum a user reminded me of a speed tip that had cropped up once or twice over the years. It has to do with popupmenus. Basically on older versions of macOS if you did This behaved not so badly although there is a slightly faster variation But on Mojave this is noticeably &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2019\/06\/24\/speed-tip-with-popupmenus\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Speed tip with popupmenus&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[21,6],"class_list":["post-119","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-speed","tag-tips"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=119"}],"version-history":[{"count":4,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/119\/revisions"}],"predecessor-version":[{"id":132,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/119\/revisions\/132"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}