{"action":"created","issue":{"url":"https://api.github.com/repos/status-im/status-go/issues/251","repository_url":"https://api.github.com/repos/status-im/status-go","labels_url":"https://api.github.com/repos/status-im/status-go/issues/251/labels{/name}","comments_url":"https://api.github.com/repos/status-im/status-go/issues/251/comments","events_url":"https://api.github.com/repos/status-im/status-go/issues/251/events","html_url":"https://github.com/status-im/status-go/issues/251","id":250003026,"number":251,"title":"slow CreateAccount method","user":{"login":"rasom","id":2364994,"avatar_url":"https://avatars2.githubusercontent.com/u/2364994?v=4","gravatar_id":"","url":"https://api.github.com/users/rasom","html_url":"https://github.com/rasom","followers_url":"https://api.github.com/users/rasom/followers","following_url":"https://api.github.com/users/rasom/following{/other_user}","gists_url":"https://api.github.com/users/rasom/gists{/gist_id}","starred_url":"https://api.github.com/users/rasom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rasom/subscriptions","organizations_url":"https://api.github.com/users/rasom/orgs","repos_url":"https://api.github.com/users/rasom/repos","events_url":"https://api.github.com/users/rasom/events{/privacy}","received_events_url":"https://api.github.com/users/rasom/received_events","type":"User","site_admin":false},"labels":[{"id":392024016,"url":"https://api.github.com/repos/status-im/status-go/labels/bug","name":"bug","color":"ee0701","default":true},{"id":485676172,"url":"https://api.github.com/repos/status-im/status-go/labels/high-priority","name":"high-priority","color":"000000","default":false},{"id":648484418,"url":"https://api.github.com/repos/status-im/status-go/labels/intermediate","name":"intermediate","color":"fef2c0","default":false}],"state":"open","locked":false,"assignee":{"login":"divan","id":880202,"avatar_url":"https://avatars2.githubusercontent.com/u/880202?v=4","gravatar_id":"","url":"https://api.github.com/users/divan","html_url":"https://github.com/divan","followers_url":"https://api.github.com/users/divan/followers","following_url":"https://api.github.com/users/divan/following{/other_user}","gists_url":"https://api.github.com/users/divan/gists{/gist_id}","starred_url":"https://api.github.com/users/divan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/divan/subscriptions","organizations_url":"https://api.github.com/users/divan/orgs","repos_url":"https://api.github.com/users/divan/repos","events_url":"https://api.github.com/users/divan/events{/privacy}","received_events_url":"https://api.github.com/users/divan/received_events","type":"User","site_admin":false},"assignees":[{"login":"divan","id":880202,"avatar_url":"https://avatars2.githubusercontent.com/u/880202?v=4","gravatar_id":"","url":"https://api.github.com/users/divan","html_url":"https://github.com/divan","followers_url":"https://api.github.com/users/divan/followers","following_url":"https://api.github.com/users/divan/following{/other_user}","gists_url":"https://api.github.com/users/divan/gists{/gist_id}","starred_url":"https://api.github.com/users/divan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/divan/subscriptions","organizations_url":"https://api.github.com/users/divan/orgs","repos_url":"https://api.github.com/users/divan/repos","events_url":"https://api.github.com/users/divan/events{/privacy}","received_events_url":"https://api.github.com/users/divan/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/status-im/status-go/milestones/12","html_url":"https://github.com/status-im/status-go/milestone/12","labels_url":"https://api.github.com/repos/status-im/status-go/milestones/12/labels","id":2672925,"number":12,"title":"Beta milestone 2 of 6","description":"Iteration N2 14.08-01-09","creator":{"login":"sla-shi","id":1944596,"avatar_url":"https://avatars0.githubusercontent.com/u/1944596?v=4","gravatar_id":"","url":"https://api.github.com/users/sla-shi","html_url":"https://github.com/sla-shi","followers_url":"https://api.github.com/users/sla-shi/followers","following_url":"https://api.github.com/users/sla-shi/following{/other_user}","gists_url":"https://api.github.com/users/sla-shi/gists{/gist_id}","starred_url":"https://api.github.com/users/sla-shi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sla-shi/subscriptions","organizations_url":"https://api.github.com/users/sla-shi/orgs","repos_url":"https://api.github.com/users/sla-shi/repos","events_url":"https://api.github.com/users/sla-shi/events{/privacy}","received_events_url":"https://api.github.com/users/sla-shi/received_events","type":"User","site_admin":false},"open_issues":26,"closed_issues":3,"state":"open","created_at":"2017-08-01T04:55:04Z","updated_at":"2017-08-27T09:43:53Z","due_on":"2017-09-01T07:00:00Z","closed_at":null},"comments":8,"created_at":"2017-08-14T11:23:34Z","updated_at":"2017-08-29T20:42:44Z","closed_at":null,"author_association":"MEMBER","body":"`CreateAccount` started to be slow in [`develop`](https://github.com/status-im/status-go/commit/02705906469a1a44e6ea89e51eb71628045b0b5f), it takes 20-45 seconds before callback is invoked on real device (iphone 6s).\r\n\r\nPreviously it worked much faster, 1.5-2.0 seconds in `bug/whisper-on-geth1.6.1`."},"comment":{"url":"https://api.github.com/repos/status-im/status-go/issues/comments/325797823","html_url":"https://github.com/status-im/status-go/issues/251#issuecomment-325797823","issue_url":"https://api.github.com/repos/status-im/status-go/issues/251","id":325797823,"user":{"login":"divan","id":880202,"avatar_url":"https://avatars2.githubusercontent.com/u/880202?v=4","gravatar_id":"","url":"https://api.github.com/users/divan","html_url":"https://github.com/divan","followers_url":"https://api.github.com/users/divan/followers","following_url":"https://api.github.com/users/divan/following{/other_user}","gists_url":"https://api.github.com/users/divan/gists{/gist_id}","starred_url":"https://api.github.com/users/divan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/divan/subscriptions","organizations_url":"https://api.github.com/users/divan/orgs","repos_url":"https://api.github.com/users/divan/repos","events_url":"https://api.github.com/users/divan/events{/privacy}","received_events_url":"https://api.github.com/users/divan/received_events","type":"User","site_admin":false},"created_at":"2017-08-29T20:42:43Z","updated_at":"2017-08-29T20:42:43Z","author_association":"CONTRIBUTOR","body":"After analysis of original commit and debugging code introduced, the problem seems to be in this loop: https://github.com/status-im/status-go/blob/develop/vendor/fknsrs.biz/p/ottoext/loop/loop.go#L172\r\n```go\r\nouter:\r\n\tfor {\r\n\t\tselect {\r\n\t\tcase t := <-l.ready:\r\n\t\t\tif t != nil {\r\n\t\t\t\tif err := l.processTask(t); err != nil {\r\n\t\t\t\t\treturn err\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\tdefault:\r\n\t\t\tbreak outer\r\n\t\t}\r\n\t}\r\n```\r\n\r\nThe same instance of `Loop` is being run multiple times. In the first run it executes and `close(l.ready)` closes the channel.\r\nOn subsequent run, it goes into the `outer` loop and `<-l.ready` always returns nil, as channel already closed. And the loop repeats infinitely, the call never ends and, supposedly, uses a lot of CPU - at least enough to make things slow.\r\n\r\nSo, it's not only CreateAccount slow, it should slow other things. I have no idea how device handles such cpu-expensive loops, but UI seems to be not affected to much. The difference becomes evident in CPU heavy tasks as crypto, hence visible slowdown of CreateAccount.\r\n\r\nThis also explains, why bug is not reproduced locally, but only on device/emulator.\r\n\r\nNext patch seems to solve the issue, but I'm not sure yet how it supposed to work originally. Maybe the design of the `loop` package is completely wrong (@influx6 suggested that it begs for refactoring in any case).\r\n\r\nAnyhow, this fix solved problem in emulator, confirming the guess:\r\n```diff\r\ndiff --git a/vendor/fknsrs.biz/p/ottoext/loop/loop.go b/vendor/fknsrs.biz/p/ottoext/loop/loop.go\r\nindex ac97dc5..6c319e9 100644\r\n--- a/vendor/fknsrs.biz/p/ottoext/loop/loop.go\r\n+++ b/vendor/fknsrs.biz/p/ottoext/loop/loop.go\r\n@@ -172,7 +172,10 @@ func (l *Loop) Run() error {\r\n outer:\r\n \tfor {\r\n \t\tselect {\r\n-\t\tcase t := <-l.ready:\r\n+\t\tcase t, ok := <-l.ready:\r\n+\t\t\tif !ok {\r\n+\t\t\t\treturn nil\r\n+\t\t\t}\r\n \t\t\tif t != nil {\r\n \t\t\t\tif err := l.processTask(t); err != nil {\r\n \t\t\t\t\treturn err\r\n\r\n```"}}
{"actor":{"display_login":"divan"}}