{"action":"created","issue":{"url":"https://api.github.com/repos/meteor/meteor/issues/5633","labels_url":"https://api.github.com/repos/meteor/meteor/issues/5633/labels{/name}","comments_url":"https://api.github.com/repos/meteor/meteor/issues/5633/comments","events_url":"https://api.github.com/repos/meteor/meteor/issues/5633/events","html_url":"https://github.com/meteor/meteor/issues/5633","id":115712247,"number":5633,"title":"Great slowdown because of the interaction between a Minimongo query and subscription","user":{"login":"mitar","id":585279,"avatar_url":"https://avatars.githubusercontent.com/u/585279?v=3","gravatar_id":"","url":"https://api.github.com/users/mitar","html_url":"https://github.com/mitar","followers_url":"https://api.github.com/users/mitar/followers","following_url":"https://api.github.com/users/mitar/following{/other_user}","gists_url":"https://api.github.com/users/mitar/gists{/gist_id}","starred_url":"https://api.github.com/users/mitar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitar/subscriptions","organizations_url":"https://api.github.com/users/mitar/orgs","repos_url":"https://api.github.com/users/mitar/repos","events_url":"https://api.github.com/users/mitar/events{/privacy}","received_events_url":"https://api.github.com/users/mitar/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/meteor/meteor/labels/Project:DDP","name":"Project:DDP","color":"c7def8"},{"url":"https://api.github.com/repos/meteor/meteor/labels/Project:Minimongo","name":"Project:Minimongo","color":"006b75"}],"state":"open","locked":false,"assignee":{"login":"tmeasday","id":132554,"avatar_url":"https://avatars.githubusercontent.com/u/132554?v=3","gravatar_id":"","url":"https://api.github.com/users/tmeasday","html_url":"https://github.com/tmeasday","followers_url":"https://api.github.com/users/tmeasday/followers","following_url":"https://api.github.com/users/tmeasday/following{/other_user}","gists_url":"https://api.github.com/users/tmeasday/gists{/gist_id}","starred_url":"https://api.github.com/users/tmeasday/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmeasday/subscriptions","organizations_url":"https://api.github.com/users/tmeasday/orgs","repos_url":"https://api.github.com/users/tmeasday/repos","events_url":"https://api.github.com/users/tmeasday/events{/privacy}","received_events_url":"https://api.github.com/users/tmeasday/received_events","type":"User","site_admin":false},"milestone":null,"comments":26,"created_at":"2015-11-08T06:35:40Z","updated_at":"2015-11-19T00:43:50Z","closed_at":null,"body":"I want my Saturday back.\r\n\r\nSee reproduction [here](https://github.com/mitar/meteor-issue5633).\r\n\r\nThe issue is that I have one subscription which returns the latest document in a collection. And then I display that latest document. So I have a helper like:\r\n\r\n```javascript\r\nTemplate.hello.helpers({\r\n  latest: function () {\r\n    return Documents.findOne({}, {sort: {createdAt: -1}});\r\n  }\r\n});\r\n```\r\n\r\nAnd then I want to subscribe to the whole collection as well, so I open another subscription to a publish function which publishes all documents. That subscription takes (in the example app) for 500 documents **more than 10 seconds to get to the ready state**. The interesting thing is that if I comment out the content of the `latest` template helper, subscription finishes at normal speed (0.3 seconds, which still feels a bit large for localhost app, but OK).\r\n\r\nIt seems that the bottleneck is in the Minimongo query which is then slowing down everything else, including the reception and processing of DDP messages. So it seems that for every new document Minimongo is recomputing the query, and this grows super-linearly, it is slower and slower with number of documents in the collection.\r\n\r\nI would guess this is potentially huge slowdown for many applications because. Especially cases like infinity scroll where you have an order specified in Minimongo and you are subscribing to a new larger publish of same documents."},"comment":{"url":"https://api.github.com/repos/meteor/meteor/issues/comments/157910761","html_url":"https://github.com/meteor/meteor/issues/5633#issuecomment-157910761","issue_url":"https://api.github.com/repos/meteor/meteor/issues/5633","id":157910761,"user":{"login":"mitar","id":585279,"avatar_url":"https://avatars.githubusercontent.com/u/585279?v=3","gravatar_id":"","url":"https://api.github.com/users/mitar","html_url":"https://github.com/mitar","followers_url":"https://api.github.com/users/mitar/followers","following_url":"https://api.github.com/users/mitar/following{/other_user}","gists_url":"https://api.github.com/users/mitar/gists{/gist_id}","starred_url":"https://api.github.com/users/mitar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitar/subscriptions","organizations_url":"https://api.github.com/users/mitar/orgs","repos_url":"https://api.github.com/users/mitar/repos","events_url":"https://api.github.com/users/mitar/events{/privacy}","received_events_url":"https://api.github.com/users/mitar/received_events","type":"User","site_admin":false},"created_at":"2015-11-19T00:43:50Z","updated_at":"2015-11-19T00:43:50Z","body":"> Well maybe you are right. Let me know if you figure any more out about it.\r\n\r\nOr maybe that can be a ticket for some from the core MDG to do. At the moment I do not have free cycles to get to now the internals of the livedata. Maybe @glasser can explain more why current suspend/resume does not work in this case?\r\n\r\n> Otherwise you just don't have any control about what is rendered.\r\n\r\nYou do. Because you are getting one document by document."}}