{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/8670","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/8670/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/8670/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/8670/events","html_url":"https://github.com/nodejs/node/issues/8670","id":178154066,"number":8670,"title":"Garbage collection causes bad performance ","user":{"login":"dsehnal","id":21145776,"avatar_url":"https://avatars.githubusercontent.com/u/21145776?v=3","gravatar_id":"","url":"https://api.github.com/users/dsehnal","html_url":"https://github.com/dsehnal","followers_url":"https://api.github.com/users/dsehnal/followers","following_url":"https://api.github.com/users/dsehnal/following{/other_user}","gists_url":"https://api.github.com/users/dsehnal/gists{/gist_id}","starred_url":"https://api.github.com/users/dsehnal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsehnal/subscriptions","organizations_url":"https://api.github.com/users/dsehnal/orgs","repos_url":"https://api.github.com/users/dsehnal/repos","events_url":"https://api.github.com/users/dsehnal/events{/privacy}","received_events_url":"https://api.github.com/users/dsehnal/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodejs/node/labels/V8","name":"V8","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-09-20T19:25:32Z","updated_at":"2016-10-11T15:44:39Z","closed_at":null,"body":"* **Version**: 6.6.0, x64\r\n* **Platform**: win10, x64\r\n* **Subsystem**: v8 (probably)\r\n\r\nA little background: I need to parse a lot of text based data. Everything was running smoothly and the code was very fast, until I ran it on a larger amount of data (about 15GB). Around halfway down the computation, the code suddenly started to be slow and sections that should have taken 30s took up to 10 minutes. \r\n\r\nThe issue seems to be that if the garbage collection is called enough times, it causes some code to run very slowly. I have also tested Node 4.5 and 6.3 of different machines and the issue was the same.\r\n\r\n------------------\r\n\r\nI experimented with the problem and narrowed the problem down to the code that is available here: https://gist.github.com/dsehnal/004f7f46a238ab2e391a62a172b9b19c.\r\n\r\nThe code includes two slightly different implementations are stripped down versions of the tokenizer of my parser:\r\n\r\n- In the original (slow) version of the code I use a \"class\" (prototype + access the state of the tokenizer via ``this``). So moving to the next token is done through ``tokenizer.moveNext()``.\r\n- In the updated (fast) version of the code I use a literal object to represent the state and use \"normal\" functions that I pass the state to explicitly: ``moveNext(state)``.\r\n\r\nI have also included code to trigger manual garbage collection to trigger the issue:\r\n\r\n```javascript\r\nif (global.gc && t % 100 === 0) {\r\n  global.gc();\r\n}\r\n```\r\n\r\nWhen I run the code without the manual GC, both approaches perform the same:\r\n\r\n```\r\n> node test slow\r\n7 runs: min 125ms, max 129ms, median 127ms\r\n\r\n> node test fast\r\n7 runs: min 129ms, max 133ms, median 132ms\r\n```\r\n\r\nHowever, when I enable manual garbage collection (via ``--expose_gc``), the \"slow\" code is more than 2 times slower:\r\n\r\n```\r\n> node --expose_gc test slow\r\n7 runs: min 574ms, max 629ms, median 611ms\r\n\r\n> node --expose_gc test fast\r\n7 runs: min 257ms, max 296ms, median 276ms\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/252956909","html_url":"https://github.com/nodejs/node/issues/8670#issuecomment-252956909","issue_url":"https://api.github.com/repos/nodejs/node/issues/8670","id":252956909,"user":{"login":"dsehnal","id":21145776,"avatar_url":"https://avatars.githubusercontent.com/u/21145776?v=3","gravatar_id":"","url":"https://api.github.com/users/dsehnal","html_url":"https://github.com/dsehnal","followers_url":"https://api.github.com/users/dsehnal/followers","following_url":"https://api.github.com/users/dsehnal/following{/other_user}","gists_url":"https://api.github.com/users/dsehnal/gists{/gist_id}","starred_url":"https://api.github.com/users/dsehnal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsehnal/subscriptions","organizations_url":"https://api.github.com/users/dsehnal/orgs","repos_url":"https://api.github.com/users/dsehnal/repos","events_url":"https://api.github.com/users/dsehnal/events{/privacy}","received_events_url":"https://api.github.com/users/dsehnal/received_events","type":"User","site_admin":false},"created_at":"2016-10-11T15:44:39Z","updated_at":"2016-10-11T15:44:39Z","body":"@bmeurer So do you think that the solution proposed at https://docs.google.com/document/d/1VEeXn6BfKmVkYpfMuxNs3otLLNPIxIVA1cLoSwGMIxI will fix this?"}}
{"actor":{"display_login":"dsehnal"}}