{"action":"created","comment":{"url":"https://api.github.com/repos/PowerShell/PowerShell/pulls/comments/106740031","pull_request_review_id":27682376,"id":106740031,"diff_hunk":"@@ -60,19 +70,56 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt\n                 _pendingProgress = new PendingProgress();\n             }\n \n-            _pendingProgress.Update(sourceId, record);\n-\n             if (_progPane == null)\n             {\n-                // This is the first time we've received a progress record. Create a progress pane, then show it.\n+                // This is the first time we've received a progress record\n+                // Create a progress pane\n+                // Set up a update flag\n+                // Create a timer for updating the flag\n \n                 _progPane = new ProgressPane(this);\n+\n+                if (_progPaneUpdateTimer == null && _progPane != null)\n+                {\n+                    // Show a progress pane at the first time we've received a progress record\n+                    progPaneUpdateFlag = true;\n+\n+                    // Invoke the timer only once to exclude overlaps\n+                    // The timer will be restarted in 'ProgressPaneUpdateTimerElapsed'\n+                    _progPaneUpdateTimer = new Timer( new TimerCallback(ProgressPaneUpdateTimerElapsed), null, UpdateTimerThreshold, Timeout.Infinite);\n+                }\n+            }\n+\n+            if (progPaneUpdateFlag || record.RecordType == ProgressRecordType.Completed)\n+            {\n+                // Update the progress pane only when the timer set up the update flag or WriteProgress is completed.\n+                // As a result, we do not block WriteProgress and whole script and eliminate unnecessary console locks and updates.\n+                _pendingProgress.Update(sourceId, record);\n+                _progPane.Show(_pendingProgress);\n+                progPaneUpdateFlag = false;\n             }\n-            _progPane.Show(_pendingProgress);\n         }\n \n \n \n+        /// <summary>\n+        ///\n+        /// TimerCallback for _progPaneUpdateTimer to update 'progPaneUpdateFlag' and restart the timer\n+        ///\n+        /// </summary>\n+\n+        private\n+        void\n+        ProgressPaneUpdateTimerElapsed(object sender)\n+        {\n+            if (_progPane != null)","path":"src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs","position":null,"original_position":78,"commit_id":"144b28e3d9db58ff866025b2397c78fd45141b72","original_commit_id":"0a494c130b13a434c862db5fd3e884a7eaba97f0","user":{"login":"iSazonov","id":22290914,"avatar_url":"https://avatars1.githubusercontent.com/u/22290914?v=3","gravatar_id":"","url":"https://api.github.com/users/iSazonov","html_url":"https://github.com/iSazonov","followers_url":"https://api.github.com/users/iSazonov/followers","following_url":"https://api.github.com/users/iSazonov/following{/other_user}","gists_url":"https://api.github.com/users/iSazonov/gists{/gist_id}","starred_url":"https://api.github.com/users/iSazonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iSazonov/subscriptions","organizations_url":"https://api.github.com/users/iSazonov/orgs","repos_url":"https://api.github.com/users/iSazonov/repos","events_url":"https://api.github.com/users/iSazonov/events{/privacy}","received_events_url":"https://api.github.com/users/iSazonov/received_events","type":"User","site_admin":false},"body":"Fixed.","created_at":"2017-03-17T20:33:56Z","updated_at":"2017-03-17T20:33:56Z","html_url":"https://github.com/PowerShell/PowerShell/pull/2822#discussion_r106740031","pull_request_url":"https://api.github.com/repos/PowerShell/PowerShell/pulls/2822","_links":{"self":{"href":"https://api.github.com/repos/PowerShell/PowerShell/pulls/comments/106740031"},"html":{"href":"https://github.com/PowerShell/PowerShell/pull/2822#discussion_r106740031"},"pull_request":{"href":"https://api.github.com/repos/PowerShell/PowerShell/pulls/2822"}}},"pull_request":{"url":"https://api.github.com/repos/PowerShell/PowerShell/pulls/2822","id":96114875,"html_url":"https://github.com/PowerShell/PowerShell/pull/2822","diff_url":"https://github.com/PowerShell/PowerShell/pull/2822.diff","patch_url":"https://github.com/PowerShell/PowerShell/pull/2822.patch","issue_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2822","number":2822,"state":"open","locked":false,"title":"Improve a progress pane performance (one thread)","user":{"login":"iSazonov","id":22290914,"avatar_url":"https://avatars1.githubusercontent.com/u/22290914?v=3","gravatar_id":"","url":"https://api.github.com/users/iSazonov","html_url":"https://github.com/iSazonov","followers_url":"https://api.github.com/users/iSazonov/followers","following_url":"https://api.github.com/users/iSazonov/following{/other_user}","gists_url":"https://api.github.com/users/iSazonov/gists{/gist_id}","starred_url":"https://api.github.com/users/iSazonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iSazonov/subscriptions","organizations_url":"https://api.github.com/users/iSazonov/orgs","repos_url":"https://api.github.com/users/iSazonov/repos","events_url":"https://api.github.com/users/iSazonov/events{/privacy}","received_events_url":"https://api.github.com/users/iSazonov/received_events","type":"User","site_admin":false},"body":"Close #2138\r\n(Reference #2800)\r\n\r\n1. All updates left in one thread. (The use of multiple threads was the main problem previous PR #2640)\r\n\r\n2. The timer is only used to set up a update flag. (According to my tests calling Datetime.Now() and verifing the time delta creates a much larger delay)\r\n\r\n3. The timer interval is set to 200 ms. I test intervals from 50 ms to 2000 ms. I don't see any differences on the screen with 100 ms and 200 ms. So I chose the more cost-effective option. @lzybkr What do you think about this?\r\n\r\n4. Removed unnecessary locks and updates. `WriteProgress` is executed as quickly as possible, as a result the entire script executes significantly faster.\r\n\r\n5. Performance tests:\r\n\r\n```powershell\r\nMeasure-Command { 1..1e4 | % { Write-Progress \"...\" -PercentComplete ($_*100/1e4)} }\r\n```\r\nAfter:\r\n```\r\nDays              : 0\r\nHours             : 0\r\nMinutes           : 0\r\nSeconds           : 1\r\nMilliseconds      : 26\r\nTicks             : 10269198\r\nTotalDays         : 1.18856458333333E-05\r\nTotalHours        : 0.0002852555\r\nTotalMinutes      : 0.01711533\r\nTotalSeconds      : 1.0269198\r\nTotalMilliseconds : 1026.9198\r\n```\r\nBefore:\r\n```\r\nDays              : 0\r\nHours             : 0\r\nMinutes           : 0\r\nSeconds           : 30\r\nMilliseconds      : 697\r\nTicks             : 306978612\r\nTotalDays         : 0.000355299319444444\r\nTotalHours        : 0.00852718366666667\r\nTotalMinutes      : 0.51163102\r\nTotalSeconds      : 30.6978612\r\nTotalMilliseconds : 30697.8612\r\n```\r\n\r\n6. The two problems are not addressed this PR:\r\n6.1 `Hung`  or  `Freeze`  of a progress pane. If Write-Progress is not called very frequently user sees that the pane freeze.\r\n6.2 If Write-Progress frequently updates a progress pane and the script make output to console the user sees that the display flickers. The following script illustrates this:\r\n```powershell\r\n1..1e4 | % { $_;Write-Progress \"...\" -PercentComplete ($_*100/1e4)}\r\n```","created_at":"2016-12-01T15:52:43Z","updated_at":"2017-03-17T20:33:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f7bb0e8e420dc97834564b44f38ddcf9540ae591","assignee":{"login":"daxian-dbw","id":127450,"avatar_url":"https://avatars1.githubusercontent.com/u/127450?v=3","gravatar_id":"","url":"https://api.github.com/users/daxian-dbw","html_url":"https://github.com/daxian-dbw","followers_url":"https://api.github.com/users/daxian-dbw/followers","following_url":"https://api.github.com/users/daxian-dbw/following{/other_user}","gists_url":"https://api.github.com/users/daxian-dbw/gists{/gist_id}","starred_url":"https://api.github.com/users/daxian-dbw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daxian-dbw/subscriptions","organizations_url":"https://api.github.com/users/daxian-dbw/orgs","repos_url":"https://api.github.com/users/daxian-dbw/repos","events_url":"https://api.github.com/users/daxian-dbw/events{/privacy}","received_events_url":"https://api.github.com/users/daxian-dbw/received_events","type":"User","site_admin":false},"assignees":[{"login":"daxian-dbw","id":127450,"avatar_url":"https://avatars1.githubusercontent.com/u/127450?v=3","gravatar_id":"","url":"https://api.github.com/users/daxian-dbw","html_url":"https://github.com/daxian-dbw","followers_url":"https://api.github.com/users/daxian-dbw/followers","following_url":"https://api.github.com/users/daxian-dbw/following{/other_user}","gists_url":"https://api.github.com/users/daxian-dbw/gists{/gist_id}","starred_url":"https://api.github.com/users/daxian-dbw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daxian-dbw/subscriptions","organizations_url":"https://api.github.com/users/daxian-dbw/orgs","repos_url":"https://api.github.com/users/daxian-dbw/repos","events_url":"https://api.github.com/users/daxian-dbw/events{/privacy}","received_events_url":"https://api.github.com/users/daxian-dbw/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/PowerShell/PowerShell/pulls/2822/commits","review_comments_url":"https://api.github.com/repos/PowerShell/PowerShell/pulls/2822/comments","review_comment_url":"https://api.github.com/repos/PowerShell/PowerShell/pulls/comments{/number}","comments_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2822/comments","statuses_url":"https://api.github.com/repos/PowerShell/PowerShell/statuses/144b28e3d9db58ff866025b2397c78fd45141b72","head":{"label":"iSazonov:writeprogressperf","ref":"writeprogressperf","sha":"144b28e3d9db58ff866025b2397c78fd45141b72","user":{"login":"iSazonov","id":22290914,"avatar_url":"https://avatars1.githubusercontent.com/u/22290914?v=3","gravatar_id":"","url":"https://api.github.com/users/iSazonov","html_url":"https://github.com/iSazonov","followers_url":"https://api.github.com/users/iSazonov/followers","following_url":"https://api.github.com/users/iSazonov/following{/other_user}","gists_url":"https://api.github.com/users/iSazonov/gists{/gist_id}","starred_url":"https://api.github.com/users/iSazonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iSazonov/subscriptions","organizations_url":"https://api.github.com/users/iSazonov/orgs","repos_url":"https://api.github.com/users/iSazonov/repos","events_url":"https://api.github.com/users/iSazonov/events{/privacy}","received_events_url":"https://api.github.com/users/iSazonov/received_events","type":"User","site_admin":false},"repo":{"id":69433034,"name":"PowerShell","full_name":"iSazonov/PowerShell","owner":{"login":"iSazonov","id":22290914,"avatar_url":"https://avatars1.githubusercontent.com/u/22290914?v=3","gravatar_id":"","url":"https://api.github.com/users/iSazonov","html_url":"https://github.com/iSazonov","followers_url":"https://api.github.com/users/iSazonov/followers","following_url":"https://api.github.com/users/iSazonov/following{/other_user}","gists_url":"https://api.github.com/users/iSazonov/gists{/gist_id}","starred_url":"https://api.github.com/users/iSazonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iSazonov/subscriptions","organizations_url":"https://api.github.com/users/iSazonov/orgs","repos_url":"https://api.github.com/users/iSazonov/repos","events_url":"https://api.github.com/users/iSazonov/events{/privacy}","received_events_url":"https://api.github.com/users/iSazonov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/iSazonov/PowerShell","description":"PowerShell for every system!","fork":true,"url":"https://api.github.com/repos/iSazonov/PowerShell","forks_url":"https://api.github.com/repos/iSazonov/PowerShell/forks","keys_url":"https://api.github.com/repos/iSazonov/PowerShell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/iSazonov/PowerShell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/iSazonov/PowerShell/teams","hooks_url":"https://api.github.com/repos/iSazonov/PowerShell/hooks","issue_events_url":"https://api.github.com/repos/iSazonov/PowerShell/issues/events{/number}","events_url":"https://api.github.com/repos/iSazonov/PowerShell/events","assignees_url":"https://api.github.com/repos/iSazonov/PowerShell/assignees{/user}","branches_url":"https://api.github.com/repos/iSazonov/PowerShell/branches{/branch}","tags_url":"https://api.github.com/repos/iSazonov/PowerShell/tags","blobs_url":"https://api.github.com/repos/iSazonov/PowerShell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/iSazonov/PowerShell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/iSazonov/PowerShell/git/refs{/sha}","trees_url":"https://api.github.com/repos/iSazonov/PowerShell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/iSazonov/PowerShell/statuses/{sha}","languages_url":"https://api.github.com/repos/iSazonov/PowerShell/languages","stargazers_url":"https://api.github.com/repos/iSazonov/PowerShell/stargazers","contributors_url":"https://api.github.com/repos/iSazonov/PowerShell/contributors","subscribers_url":"https://api.github.com/repos/iSazonov/PowerShell/subscribers","subscription_url":"https://api.github.com/repos/iSazonov/PowerShell/subscription","commits_url":"https://api.github.com/repos/iSazonov/PowerShell/commits{/sha}","git_commits_url":"https://api.github.com/repos/iSazonov/PowerShell/git/commits{/sha}","comments_url":"https://api.github.com/repos/iSazonov/PowerShell/comments{/number}","issue_comment_url":"https://api.github.com/repos/iSazonov/PowerShell/issues/comments{/number}","contents_url":"https://api.github.com/repos/iSazonov/PowerShell/contents/{+path}","compare_url":"https://api.github.com/repos/iSazonov/PowerShell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/iSazonov/PowerShell/merges","archive_url":"https://api.github.com/repos/iSazonov/PowerShell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/iSazonov/PowerShell/downloads","issues_url":"https://api.github.com/repos/iSazonov/PowerShell/issues{/number}","pulls_url":"https://api.github.com/repos/iSazonov/PowerShell/pulls{/number}","milestones_url":"https://api.github.com/repos/iSazonov/PowerShell/milestones{/number}","notifications_url":"https://api.github.com/repos/iSazonov/PowerShell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/iSazonov/PowerShell/labels{/name}","releases_url":"https://api.github.com/repos/iSazonov/PowerShell/releases{/id}","deployments_url":"https://api.github.com/repos/iSazonov/PowerShell/deployments","created_at":"2016-09-28T06:30:22Z","updated_at":"2017-02-07T09:21:08Z","pushed_at":"2017-03-17T13:05:59Z","git_url":"git://github.com/iSazonov/PowerShell.git","ssh_url":"git@github.com:iSazonov/PowerShell.git","clone_url":"https://github.com/iSazonov/PowerShell.git","svn_url":"https://github.com/iSazonov/PowerShell","homepage":"https://microsoft.com/powershell","size":24213,"stargazers_count":1,"watchers_count":1,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"PowerShell:master","ref":"master","sha":"02512fafe9914043660fb04ac5e1fd478acd885a","user":{"login":"PowerShell","id":11524380,"avatar_url":"https://avatars0.githubusercontent.com/u/11524380?v=3","gravatar_id":"","url":"https://api.github.com/users/PowerShell","html_url":"https://github.com/PowerShell","followers_url":"https://api.github.com/users/PowerShell/followers","following_url":"https://api.github.com/users/PowerShell/following{/other_user}","gists_url":"https://api.github.com/users/PowerShell/gists{/gist_id}","starred_url":"https://api.github.com/users/PowerShell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PowerShell/subscriptions","organizations_url":"https://api.github.com/users/PowerShell/orgs","repos_url":"https://api.github.com/users/PowerShell/repos","events_url":"https://api.github.com/users/PowerShell/events{/privacy}","received_events_url":"https://api.github.com/users/PowerShell/received_events","type":"Organization","site_admin":false},"repo":{"id":49609581,"name":"PowerShell","full_name":"PowerShell/PowerShell","owner":{"login":"PowerShell","id":11524380,"avatar_url":"https://avatars0.githubusercontent.com/u/11524380?v=3","gravatar_id":"","url":"https://api.github.com/users/PowerShell","html_url":"https://github.com/PowerShell","followers_url":"https://api.github.com/users/PowerShell/followers","following_url":"https://api.github.com/users/PowerShell/following{/other_user}","gists_url":"https://api.github.com/users/PowerShell/gists{/gist_id}","starred_url":"https://api.github.com/users/PowerShell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PowerShell/subscriptions","organizations_url":"https://api.github.com/users/PowerShell/orgs","repos_url":"https://api.github.com/users/PowerShell/repos","events_url":"https://api.github.com/users/PowerShell/events{/privacy}","received_events_url":"https://api.github.com/users/PowerShell/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/PowerShell/PowerShell","description":"PowerShell for every system!","fork":false,"url":"https://api.github.com/repos/PowerShell/PowerShell","forks_url":"https://api.github.com/repos/PowerShell/PowerShell/forks","keys_url":"https://api.github.com/repos/PowerShell/PowerShell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PowerShell/PowerShell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PowerShell/PowerShell/teams","hooks_url":"https://api.github.com/repos/PowerShell/PowerShell/hooks","issue_events_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/events{/number}","events_url":"https://api.github.com/repos/PowerShell/PowerShell/events","assignees_url":"https://api.github.com/repos/PowerShell/PowerShell/assignees{/user}","branches_url":"https://api.github.com/repos/PowerShell/PowerShell/branches{/branch}","tags_url":"https://api.github.com/repos/PowerShell/PowerShell/tags","blobs_url":"https://api.github.com/repos/PowerShell/PowerShell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PowerShell/PowerShell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PowerShell/PowerShell/git/refs{/sha}","trees_url":"https://api.github.com/repos/PowerShell/PowerShell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PowerShell/PowerShell/statuses/{sha}","languages_url":"https://api.github.com/repos/PowerShell/PowerShell/languages","stargazers_url":"https://api.github.com/repos/PowerShell/PowerShell/stargazers","contributors_url":"https://api.github.com/repos/PowerShell/PowerShell/contributors","subscribers_url":"https://api.github.com/repos/PowerShell/PowerShell/subscribers","subscription_url":"https://api.github.com/repos/PowerShell/PowerShell/subscription","commits_url":"https://api.github.com/repos/PowerShell/PowerShell/commits{/sha}","git_commits_url":"https://api.github.com/repos/PowerShell/PowerShell/git/commits{/sha}","comments_url":"https://api.github.com/repos/PowerShell/PowerShell/comments{/number}","issue_comment_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/comments{/number}","contents_url":"https://api.github.com/repos/PowerShell/PowerShell/contents/{+path}","compare_url":"https://api.github.com/repos/PowerShell/PowerShell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PowerShell/PowerShell/merges","archive_url":"https://api.github.com/repos/PowerShell/PowerShell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PowerShell/PowerShell/downloads","issues_url":"https://api.github.com/repos/PowerShell/PowerShell/issues{/number}","pulls_url":"https://api.github.com/repos/PowerShell/PowerShell/pulls{/number}","milestones_url":"https://api.github.com/repos/PowerShell/PowerShell/milestones{/number}","notifications_url":"https://api.github.com/repos/PowerShell/PowerShell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PowerShell/PowerShell/labels{/name}","releases_url":"https://api.github.com/repos/PowerShell/PowerShell/releases{/id}","deployments_url":"https://api.github.com/repos/PowerShell/PowerShell/deployments","created_at":"2016-01-13T23:41:35Z","updated_at":"2017-03-17T18:39:11Z","pushed_at":"2017-03-17T20:19:32Z","git_url":"git://github.com/PowerShell/PowerShell.git","ssh_url":"git@github.com:PowerShell/PowerShell.git","clone_url":"https://github.com/PowerShell/PowerShell.git","svn_url":"https://github.com/PowerShell/PowerShell","homepage":"https://microsoft.com/powershell","size":25132,"stargazers_count":6446,"watchers_count":6446,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":803,"mirror_url":null,"open_issues_count":660,"forks":803,"open_issues":660,"watchers":6446,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/PowerShell/PowerShell/pulls/2822"},"html":{"href":"https://github.com/PowerShell/PowerShell/pull/2822"},"issue":{"href":"https://api.github.com/repos/PowerShell/PowerShell/issues/2822"},"comments":{"href":"https://api.github.com/repos/PowerShell/PowerShell/issues/2822/comments"},"review_comments":{"href":"https://api.github.com/repos/PowerShell/PowerShell/pulls/2822/comments"},"review_comment":{"href":"https://api.github.com/repos/PowerShell/PowerShell/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/PowerShell/PowerShell/pulls/2822/commits"},"statuses":{"href":"https://api.github.com/repos/PowerShell/PowerShell/statuses/144b28e3d9db58ff866025b2397c78fd45141b72"}}}}
{"actor":{"display_login":"iSazonov"}}