{"action":"opened","issue":{"url":"https://api.github.com/repos/scala-js/scala-js/issues/1588","labels_url":"https://api.github.com/repos/scala-js/scala-js/issues/1588/labels{/name}","comments_url":"https://api.github.com/repos/scala-js/scala-js/issues/1588/comments","events_url":"https://api.github.com/repos/scala-js/scala-js/issues/1588/events","html_url":"https://github.com/scala-js/scala-js/issues/1588","id":67592611,"number":1588,"title":"Excessive LoadModule usage","user":{"login":"colinrgodsey","id":535083,"avatar_url":"https://avatars.githubusercontent.com/u/535083?v=3","gravatar_id":"","url":"https://api.github.com/users/colinrgodsey","html_url":"https://github.com/colinrgodsey","followers_url":"https://api.github.com/users/colinrgodsey/followers","following_url":"https://api.github.com/users/colinrgodsey/following{/other_user}","gists_url":"https://api.github.com/users/colinrgodsey/gists{/gist_id}","starred_url":"https://api.github.com/users/colinrgodsey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colinrgodsey/subscriptions","organizations_url":"https://api.github.com/users/colinrgodsey/orgs","repos_url":"https://api.github.com/users/colinrgodsey/repos","events_url":"https://api.github.com/users/colinrgodsey/events{/privacy}","received_events_url":"https://api.github.com/users/colinrgodsey/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-10T13:14:59Z","updated_at":"2015-04-10T13:14:59Z","closed_at":null,"body":"Assumptions\r\n----------------\r\n* Static object initialization is merky and largely 'undefined' behavior anyways\r\n* Scala may optimize object methods/fields into pure static access\r\n* Static object initialization is potentially side-effecting, with initialization order being provided naturally by the 'first reference' of such objects\r\n* Can deterministically deduce whether an object causes side-effects\r\n* Scala will set the singleton reference to a static object before its init code is run (potentially leaking the 'this' reference during construction, causing null vals and all that fun)\r\n* To fully mimic the 'static space' initialization, we need to imitate class-loading by executing the static space on first class reference/load.\r\n* Getters on the JVM are basically free. They are more costly in JavaScript.\r\n\r\nSuggestions\r\n----------------\r\n* Remove side-effect-only LoadModule calls if we can guarantee it's already been loaded. \r\n* Remove side-effect-only LoadModule calls all together (does scala do this?). \r\n* Reference the static object itself instead of LoadModule if we can guarantee it's been loaded.\r\n\r\nQuestions\r\n-------------\r\n* If values or defs are inlined, do we really need to load the module? Does scala do this? It would seem to me that the normal class-loader dynamic would avoid referencing static-space on an object if you've already inlined its content. "}}