{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/reactive/pulls/comments/196489482","pull_request_review_id":130051604,"id":196489482,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NjQ4OTQ4Mg==","diff_hunk":"@@ -208,45 +137,175 @@ public static IDisposable Schedule<TState>(this IScheduler scheduler, TState sta\n \n         private static IDisposable InvokeRec3<TState>(IScheduler scheduler, (TState state, Action<TState, Action<TState, DateTimeOffset>> action) tuple)\n         {\n-            var group = new CompositeDisposable(1);\n-            var gate = new object();\n+            var recursiveInvoker = new InvokeRec3State<TState>(scheduler, tuple.action);\n+            recursiveInvoker.InvokeFirst(tuple.state);\n+            return recursiveInvoker;\n+        }\n+\n+        abstract class InvokeRecBaseState<TState> : IDisposable\n+        {\n+            readonly object gate;\n+\n+            protected readonly IScheduler scheduler;\n \n-            Action<TState> recursiveAction = null;\n-            recursiveAction = state1 => tuple.action(state1, (state2, dueTime1) =>\n+            Dictionary<long, IDisposable> group;\n+\n+            protected long index;\n+\n+            public InvokeRecBaseState(IScheduler scheduler)\n             {\n-                var isAdded = false;\n-                var isDone = false;\n-                var d = default(IDisposable);\n-                d = scheduler.Schedule(state2, dueTime1, (scheduler1, state3) =>\n+                this.scheduler = scheduler;\n+                group = new Dictionary<long, IDisposable>(1);\n+                gate = new object();\n+            }\n+\n+            public void Dispose()\n+            {\n+                var g = default(Dictionary<long, IDisposable>);\n+                lock (gate)\n                 {\n-                    lock (gate)\n+                    g = group;\n+                    if (g == null)\n                     {\n-                        if (isAdded)\n-                        {\n-                            group.Remove(d);\n-                        }\n-                        else\n-                        {\n-                            isDone = true;\n-                        }\n+                        return;\n                     }\n-                    recursiveAction(state3);\n-                    return Disposable.Empty;\n-                });\n+                    group = null;\n+                }\n \n+                foreach (var d in g.Values)\n+                {\n+                    d?.Dispose();\n+                }\n+            }\n+\n+            protected long Prepare()\n+            {\n                 lock (gate)\n                 {\n-                    if (!isDone)\n+                    var g = group;\n+                    if (g == null)\n                     {\n-                        group.Add(d);\n-                        isAdded = true;\n+                        return -1;\n                     }\n+                    var idx = ++index;\n+                    g.Add(idx, Disposable.Empty);\n+                    return idx;\n                 }\n-            });\n+            }\n \n-            recursiveAction(tuple.state);\n+            protected void SetDisposable(long idx, IDisposable d)","path":"Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Recursive.cs","position":191,"original_position":191,"commit_id":"c1c7c040770036c313d48f15843ae22e2e506b97","original_commit_id":"c1c7c040770036c313d48f15843ae22e2e506b97","user":{"login":"danielcweber","id":1899410,"node_id":"MDQ6VXNlcjE4OTk0MTA=","avatar_url":"https://avatars1.githubusercontent.com/u/1899410?v=4","gravatar_id":"","url":"https://api.github.com/users/danielcweber","html_url":"https://github.com/danielcweber","followers_url":"https://api.github.com/users/danielcweber/followers","following_url":"https://api.github.com/users/danielcweber/following{/other_user}","gists_url":"https://api.github.com/users/danielcweber/gists{/gist_id}","starred_url":"https://api.github.com/users/danielcweber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielcweber/subscriptions","organizations_url":"https://api.github.com/users/danielcweber/orgs","repos_url":"https://api.github.com/users/danielcweber/repos","events_url":"https://api.github.com/users/danielcweber/events{/privacy}","received_events_url":"https://api.github.com/users/danielcweber/received_events","type":"User","site_admin":false},"body":"To make it wrap the increment should be unchecked?","created_at":"2018-06-19T16:13:11Z","updated_at":"2018-06-19T16:13:11Z","html_url":"https://github.com/dotnet/reactive/pull/617#discussion_r196489482","pull_request_url":"https://api.github.com/repos/dotnet/reactive/pulls/617","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/dotnet/reactive/pulls/comments/196489482"},"html":{"href":"https://github.com/dotnet/reactive/pull/617#discussion_r196489482"},"pull_request":{"href":"https://api.github.com/repos/dotnet/reactive/pulls/617"}},"in_reply_to_id":196475415},"pull_request":{"url":"https://api.github.com/repos/dotnet/reactive/pulls/617","id":195838792,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk1ODM4Nzky","html_url":"https://github.com/dotnet/reactive/pull/617","diff_url":"https://github.com/dotnet/reactive/pull/617.diff","patch_url":"https://github.com/dotnet/reactive/pull/617.patch","issue_url":"https://api.github.com/repos/dotnet/reactive/issues/617","number":617,"state":"open","locked":false,"title":"4.x: Make Scheduler.Recursive more uniform and allocate less","user":{"login":"akarnokd","id":1269832,"node_id":"MDQ6VXNlcjEyNjk4MzI=","avatar_url":"https://avatars2.githubusercontent.com/u/1269832?v=4","gravatar_id":"","url":"https://api.github.com/users/akarnokd","html_url":"https://github.com/akarnokd","followers_url":"https://api.github.com/users/akarnokd/followers","following_url":"https://api.github.com/users/akarnokd/following{/other_user}","gists_url":"https://api.github.com/users/akarnokd/gists{/gist_id}","starred_url":"https://api.github.com/users/akarnokd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akarnokd/subscriptions","organizations_url":"https://api.github.com/users/akarnokd/orgs","repos_url":"https://api.github.com/users/akarnokd/repos","events_url":"https://api.github.com/users/akarnokd/events{/privacy}","received_events_url":"https://api.github.com/users/akarnokd/received_events","type":"User","site_admin":false},"body":"This PR unifies the `Action`-based recursive scheduler helper by capturing all state into an instance and managing the recursive calls from there.\r\n\r\nThe original also allocated at least the `scheduler.Schedule(state2, (scheduler1, state3) =>` part due to the state capture of all those variables.\r\n\r\nThe `toAdd` and `isDone` has been replaced with a `Prepare`->`SetDisposable`->`RemoveDisposable` management, avoiding more heap usage and state capture. The underlying dictionary serves as the indicator for both state: `Prepare` makes sure there is an entry upfront before the schedule is called. `SetDisposable` only assigns the disposable to that entry if it still exist and `RemoveDisposable` removes the entry so that `SetDisposable` will do nothing.","created_at":"2018-06-19T14:02:27Z","updated_at":"2018-06-19T16:13:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9fd3cf1e954b93476b155d833557d4e1449ea791","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/reactive/pulls/617/commits","review_comments_url":"https://api.github.com/repos/dotnet/reactive/pulls/617/comments","review_comment_url":"https://api.github.com/repos/dotnet/reactive/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/reactive/issues/617/comments","statuses_url":"https://api.github.com/repos/dotnet/reactive/statuses/c1c7c040770036c313d48f15843ae22e2e506b97","head":{"label":"akarnokd:RecursiveScheduleImprovements","ref":"RecursiveScheduleImprovements","sha":"c1c7c040770036c313d48f15843ae22e2e506b97","user":{"login":"akarnokd","id":1269832,"node_id":"MDQ6VXNlcjEyNjk4MzI=","avatar_url":"https://avatars2.githubusercontent.com/u/1269832?v=4","gravatar_id":"","url":"https://api.github.com/users/akarnokd","html_url":"https://github.com/akarnokd","followers_url":"https://api.github.com/users/akarnokd/followers","following_url":"https://api.github.com/users/akarnokd/following{/other_user}","gists_url":"https://api.github.com/users/akarnokd/gists{/gist_id}","starred_url":"https://api.github.com/users/akarnokd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akarnokd/subscriptions","organizations_url":"https://api.github.com/users/akarnokd/orgs","repos_url":"https://api.github.com/users/akarnokd/repos","events_url":"https://api.github.com/users/akarnokd/events{/privacy}","received_events_url":"https://api.github.com/users/akarnokd/received_events","type":"User","site_admin":false},"repo":{"id":65015379,"node_id":"MDEwOlJlcG9zaXRvcnk2NTAxNTM3OQ==","name":"Rx.NET","full_name":"akarnokd/Rx.NET","owner":{"login":"akarnokd","id":1269832,"node_id":"MDQ6VXNlcjEyNjk4MzI=","avatar_url":"https://avatars2.githubusercontent.com/u/1269832?v=4","gravatar_id":"","url":"https://api.github.com/users/akarnokd","html_url":"https://github.com/akarnokd","followers_url":"https://api.github.com/users/akarnokd/followers","following_url":"https://api.github.com/users/akarnokd/following{/other_user}","gists_url":"https://api.github.com/users/akarnokd/gists{/gist_id}","starred_url":"https://api.github.com/users/akarnokd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akarnokd/subscriptions","organizations_url":"https://api.github.com/users/akarnokd/orgs","repos_url":"https://api.github.com/users/akarnokd/repos","events_url":"https://api.github.com/users/akarnokd/events{/privacy}","received_events_url":"https://api.github.com/users/akarnokd/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/akarnokd/Rx.NET","description":"The Reactive Extensions for .NET","fork":true,"url":"https://api.github.com/repos/akarnokd/Rx.NET","forks_url":"https://api.github.com/repos/akarnokd/Rx.NET/forks","keys_url":"https://api.github.com/repos/akarnokd/Rx.NET/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akarnokd/Rx.NET/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akarnokd/Rx.NET/teams","hooks_url":"https://api.github.com/repos/akarnokd/Rx.NET/hooks","issue_events_url":"https://api.github.com/repos/akarnokd/Rx.NET/issues/events{/number}","events_url":"https://api.github.com/repos/akarnokd/Rx.NET/events","assignees_url":"https://api.github.com/repos/akarnokd/Rx.NET/assignees{/user}","branches_url":"https://api.github.com/repos/akarnokd/Rx.NET/branches{/branch}","tags_url":"https://api.github.com/repos/akarnokd/Rx.NET/tags","blobs_url":"https://api.github.com/repos/akarnokd/Rx.NET/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akarnokd/Rx.NET/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akarnokd/Rx.NET/git/refs{/sha}","trees_url":"https://api.github.com/repos/akarnokd/Rx.NET/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akarnokd/Rx.NET/statuses/{sha}","languages_url":"https://api.github.com/repos/akarnokd/Rx.NET/languages","stargazers_url":"https://api.github.com/repos/akarnokd/Rx.NET/stargazers","contributors_url":"https://api.github.com/repos/akarnokd/Rx.NET/contributors","subscribers_url":"https://api.github.com/repos/akarnokd/Rx.NET/subscribers","subscription_url":"https://api.github.com/repos/akarnokd/Rx.NET/subscription","commits_url":"https://api.github.com/repos/akarnokd/Rx.NET/commits{/sha}","git_commits_url":"https://api.github.com/repos/akarnokd/Rx.NET/git/commits{/sha}","comments_url":"https://api.github.com/repos/akarnokd/Rx.NET/comments{/number}","issue_comment_url":"https://api.github.com/repos/akarnokd/Rx.NET/issues/comments{/number}","contents_url":"https://api.github.com/repos/akarnokd/Rx.NET/contents/{+path}","compare_url":"https://api.github.com/repos/akarnokd/Rx.NET/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akarnokd/Rx.NET/merges","archive_url":"https://api.github.com/repos/akarnokd/Rx.NET/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akarnokd/Rx.NET/downloads","issues_url":"https://api.github.com/repos/akarnokd/Rx.NET/issues{/number}","pulls_url":"https://api.github.com/repos/akarnokd/Rx.NET/pulls{/number}","milestones_url":"https://api.github.com/repos/akarnokd/Rx.NET/milestones{/number}","notifications_url":"https://api.github.com/repos/akarnokd/Rx.NET/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akarnokd/Rx.NET/labels{/name}","releases_url":"https://api.github.com/repos/akarnokd/Rx.NET/releases{/id}","deployments_url":"https://api.github.com/repos/akarnokd/Rx.NET/deployments","created_at":"2016-08-05T12:02:35Z","updated_at":"2018-05-28T21:59:36Z","pushed_at":"2018-06-19T15:43:07Z","git_url":"git://github.com/akarnokd/Rx.NET.git","ssh_url":"git@github.com:akarnokd/Rx.NET.git","clone_url":"https://github.com/akarnokd/Rx.NET.git","svn_url":"https://github.com/akarnokd/Rx.NET","homepage":"http://reactivex.io","size":30258,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"9a3def6a9648be974e7f9b011fe36c36e4c6d1c3","user":{"login":"dotnet","id":9141961,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkxNDE5NjE=","avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":12576526,"node_id":"MDEwOlJlcG9zaXRvcnkxMjU3NjUyNg==","name":"reactive","full_name":"dotnet/reactive","owner":{"login":"dotnet","id":9141961,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkxNDE5NjE=","avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/reactive","description":"The Reactive Extensions for .NET","fork":false,"url":"https://api.github.com/repos/dotnet/reactive","forks_url":"https://api.github.com/repos/dotnet/reactive/forks","keys_url":"https://api.github.com/repos/dotnet/reactive/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/reactive/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/reactive/teams","hooks_url":"https://api.github.com/repos/dotnet/reactive/hooks","issue_events_url":"https://api.github.com/repos/dotnet/reactive/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/reactive/events","assignees_url":"https://api.github.com/repos/dotnet/reactive/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/reactive/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/reactive/tags","blobs_url":"https://api.github.com/repos/dotnet/reactive/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/reactive/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/reactive/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/reactive/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/reactive/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/reactive/languages","stargazers_url":"https://api.github.com/repos/dotnet/reactive/stargazers","contributors_url":"https://api.github.com/repos/dotnet/reactive/contributors","subscribers_url":"https://api.github.com/repos/dotnet/reactive/subscribers","subscription_url":"https://api.github.com/repos/dotnet/reactive/subscription","commits_url":"https://api.github.com/repos/dotnet/reactive/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/reactive/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/reactive/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/reactive/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/reactive/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/reactive/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/reactive/merges","archive_url":"https://api.github.com/repos/dotnet/reactive/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/reactive/downloads","issues_url":"https://api.github.com/repos/dotnet/reactive/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/reactive/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/reactive/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/reactive/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/reactive/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/reactive/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/reactive/deployments","created_at":"2013-09-03T22:33:51Z","updated_at":"2018-06-19T15:58:52Z","pushed_at":"2018-06-19T15:58:59Z","git_url":"git://github.com/dotnet/reactive.git","ssh_url":"git@github.com:dotnet/reactive.git","clone_url":"https://github.com/dotnet/reactive.git","svn_url":"https://github.com/dotnet/reactive","homepage":"http://reactivex.io","size":37571,"stargazers_count":2796,"watchers_count":2796,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":412,"mirror_url":null,"archived":false,"open_issues_count":134,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":412,"open_issues":134,"watchers":2796,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/reactive/pulls/617"},"html":{"href":"https://github.com/dotnet/reactive/pull/617"},"issue":{"href":"https://api.github.com/repos/dotnet/reactive/issues/617"},"comments":{"href":"https://api.github.com/repos/dotnet/reactive/issues/617/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/reactive/pulls/617/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/reactive/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/reactive/pulls/617/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/reactive/statuses/c1c7c040770036c313d48f15843ae22e2e506b97"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"danielcweber"}}