{"action":"opened","issue":{"url":"https://api.github.com/repos/facebook/prepack/issues/914","repository_url":"https://api.github.com/repos/facebook/prepack","labels_url":"https://api.github.com/repos/facebook/prepack/issues/914/labels{/name}","comments_url":"https://api.github.com/repos/facebook/prepack/issues/914/comments","events_url":"https://api.github.com/repos/facebook/prepack/issues/914/events","html_url":"https://github.com/facebook/prepack/issues/914","id":252099371,"number":914,"title":"factorifyObjects inefficiency","user":{"login":"NTillmann","id":6457462,"avatar_url":"https://avatars2.githubusercontent.com/u/6457462?v=4","gravatar_id":"","url":"https://api.github.com/users/NTillmann","html_url":"https://github.com/NTillmann","followers_url":"https://api.github.com/users/NTillmann/followers","following_url":"https://api.github.com/users/NTillmann/following{/other_user}","gists_url":"https://api.github.com/users/NTillmann/gists{/gist_id}","starred_url":"https://api.github.com/users/NTillmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NTillmann/subscriptions","organizations_url":"https://api.github.com/users/NTillmann/orgs","repos_url":"https://api.github.com/users/NTillmann/repos","events_url":"https://api.github.com/users/NTillmann/events{/privacy}","received_events_url":"https://api.github.com/users/NTillmann/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-08-22T21:47:45Z","updated_at":"2017-08-22T21:47:45Z","closed_at":null,"body":"The `factorifyObjects` feature in Prepack reduces code size by creating factory functions for common object creation patterns. For example,\r\n```js\r\n(function() {\r\n    a = { x: 0, y: 1 };\r\n    b = { x: 0, y: 1 };\r\n    c = { x: 0, y: 1 };\r\n    d = { x: 0, y: 1 };\r\n    e = { x: 0, y: 1 };\r\n    A = { x: 0, y: 2 };\r\n    B = { x: 0, y: 2 };\r\n    C = { x: 0, y: 2 };\r\n    D = { x: 0, y: 2 };\r\n    E = { x: 0, y: 2 };\r\n})();\r\n```\r\nprepacks to\r\n```js\r\n(function () {\r\n  function $_2() {\r\n    return $_0(0, 2);\r\n  }\r\n  function $_1() {\r\n    return $_0(0, 1);\r\n  }\r\n  function $_0(__0, __1) {\r\n    return {\r\n      x: __0,\r\n      y: __1\r\n    };\r\n  }\r\n  var _0 = $_1();\r\n  a = _0;\r\n  var _1 = $_1();\r\n  b = _1;\r\n  var _2 = $_1();\r\n  c = _2;\r\n  var _3 = $_1();\r\n  d = _3;\r\n  var _4 = $_1();\r\n  e = _4;\r\n  var _5 = $_2();\r\n  A = _5;\r\n  var _6 = $_2();\r\n  B = _6;\r\n  var _7 = $_2();\r\n  C = _7;\r\n  var _8 = $_2();\r\n  D = _8;\r\n  var _9 = $_2();\r\n  E = _9;\r\n})();\r\n```\r\n\r\nWhile correct, the two levels of factory functions seems a bit excessive. We should consider simply inlining `$_0`. This would save a good thousand function calls in a medium FB internal JavaScript program."}}
{"actor":{"display_login":"NTillmann"}}