{"action":"created","issue":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4936","repository_url":"https://api.github.com/repos/HaxeFoundation/haxe","labels_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4936/labels{/name}","comments_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4936/comments","events_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4936/events","html_url":"https://github.com/HaxeFoundation/haxe/issues/4936","id":140498478,"number":4936,"title":"cache loaded functions in haxe.macro.* methods","user":{"login":"nadako","id":49749,"avatar_url":"https://avatars.githubusercontent.com/u/49749?v=3","gravatar_id":"","url":"https://api.github.com/users/nadako","html_url":"https://github.com/nadako","followers_url":"https://api.github.com/users/nadako/followers","following_url":"https://api.github.com/users/nadako/following{/other_user}","gists_url":"https://api.github.com/users/nadako/gists{/gist_id}","starred_url":"https://api.github.com/users/nadako/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nadako/subscriptions","organizations_url":"https://api.github.com/users/nadako/orgs","repos_url":"https://api.github.com/users/nadako/repos","events_url":"https://api.github.com/users/nadako/events{/privacy}","received_events_url":"https://api.github.com/users/nadako/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/HaxeFoundation/haxe/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/HaxeFoundation/haxe/labels/platform-macro","name":"platform-macro","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/milestones/5","html_url":"https://github.com/HaxeFoundation/haxe/milestones/3.3.0-rc1","labels_url":"https://api.github.com/repos/HaxeFoundation/haxe/milestones/5/labels","id":586975,"number":5,"title":"3.3.0-rc1","description":"","creator":{"login":"ncannasse","id":1022912,"avatar_url":"https://avatars.githubusercontent.com/u/1022912?v=3","gravatar_id":"","url":"https://api.github.com/users/ncannasse","html_url":"https://github.com/ncannasse","followers_url":"https://api.github.com/users/ncannasse/followers","following_url":"https://api.github.com/users/ncannasse/following{/other_user}","gists_url":"https://api.github.com/users/ncannasse/gists{/gist_id}","starred_url":"https://api.github.com/users/ncannasse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncannasse/subscriptions","organizations_url":"https://api.github.com/users/ncannasse/orgs","repos_url":"https://api.github.com/users/ncannasse/repos","events_url":"https://api.github.com/users/ncannasse/events{/privacy}","received_events_url":"https://api.github.com/users/ncannasse/received_events","type":"User","site_admin":false},"open_issues":85,"closed_issues":216,"state":"open","created_at":"2014-03-04T14:22:27Z","updated_at":"2016-03-30T22:01:43Z","due_on":"2016-04-02T22:00:00Z","closed_at":null},"comments":2,"created_at":"2016-03-13T15:52:37Z","updated_at":"2016-03-30T22:16:30Z","closed_at":null,"body":"Currently, all methods in `haxe.macro.Context/Compiler/Tools` look like this:\r\n```haxe\r\npublic static function follow( t : Type, ?once : Bool ) : Type {\r\n    return load(\"follow\", 2)(t,once);\r\n}\r\n```\r\nWhich mean they will `load` an interp function each time they are called. That seem like a silly overhead which is slowing down compilation and, more importantly, completion when macros are used a lot.\r\n\r\nPersonally, I tested it with my macro-heavy codebase and it saved about 0.6 sec per compilation which may not seem like much, but it's still good. However if we talk about completion, IMO this is a huge speedup.\r\n\r\nI think we should cache `load`ed functions in static vars, like it's done in neko/hxcpp CFFI-based classes. I'm not sure whether we should make it lazy or not. (e.g. `if (_follow == null) _follow = load(\"follow\",2); _follow(t, once);`), it seems reasonable to me to load all macro functions once and make them available without loading or even `==null` branching.\r\n\r\n@ncannasse what do you think?"},"comment":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/comments/203663643","html_url":"https://github.com/HaxeFoundation/haxe/issues/4936#issuecomment-203663643","issue_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4936","id":203663643,"user":{"login":"ncannasse","id":1022912,"avatar_url":"https://avatars.githubusercontent.com/u/1022912?v=3","gravatar_id":"","url":"https://api.github.com/users/ncannasse","html_url":"https://github.com/ncannasse","followers_url":"https://api.github.com/users/ncannasse/followers","following_url":"https://api.github.com/users/ncannasse/following{/other_user}","gists_url":"https://api.github.com/users/ncannasse/gists{/gist_id}","starred_url":"https://api.github.com/users/ncannasse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncannasse/subscriptions","organizations_url":"https://api.github.com/users/ncannasse/orgs","repos_url":"https://api.github.com/users/ncannasse/repos","events_url":"https://api.github.com/users/ncannasse/events{/privacy}","received_events_url":"https://api.github.com/users/ncannasse/received_events","type":"User","site_admin":false},"created_at":"2016-03-30T22:16:29Z","updated_at":"2016-03-30T22:16:29Z","body":"@nadako with completion + macros, you should use compilation server which will cache you macro context, so most likely you will not have to call any macros.\r\nIf you still want to optimize the Context methods I'm fine with it, maybe try @back2dos suggestion first to see if that does improve things already"}}