{"action":"created","comment":{"url":"https://api.github.com/repos/privat/nit/pulls/comments/26576209","id":26576209,"diff_hunk":"@@ -2122,6 +2268,12 @@ class SeparateRuntimeFunction\n \tend\n end\n \n+redef class MType\n+\t# Is the type is tagged?\n+\t# If false, it means that the type is not promitive, or is boxed.","path":"src/compiler/separate_compiler.nit","position":295,"original_position":295,"commit_id":"5bafd3fa95f6ad8e944cb365181abf47f34e5983","original_commit_id":"5bafd3fa95f6ad8e944cb365181abf47f34e5983","user":{"login":"Morriar","id":583144,"avatar_url":"https://avatars.githubusercontent.com/u/583144?v=3","gravatar_id":"","url":"https://api.github.com/users/Morriar","html_url":"https://github.com/Morriar","followers_url":"https://api.github.com/users/Morriar/followers","following_url":"https://api.github.com/users/Morriar/following{/other_user}","gists_url":"https://api.github.com/users/Morriar/gists{/gist_id}","starred_url":"https://api.github.com/users/Morriar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Morriar/subscriptions","organizations_url":"https://api.github.com/users/Morriar/orgs","repos_url":"https://api.github.com/users/Morriar/repos","events_url":"https://api.github.com/users/Morriar/events{/privacy}","received_events_url":"https://api.github.com/users/Morriar/received_events","type":"User","site_admin":false},"body":"I don't know what is a pr**o**mitive type. And at this point, I'm affraid to ask :p","created_at":"2015-03-17T14:23:40Z","updated_at":"2015-03-17T14:23:40Z","html_url":"https://github.com/privat/nit/pull/1206#discussion_r26576209","pull_request_url":"https://api.github.com/repos/privat/nit/pulls/1206","_links":{"self":{"href":"https://api.github.com/repos/privat/nit/pulls/comments/26576209"},"html":{"href":"https://github.com/privat/nit/pull/1206#discussion_r26576209"},"pull_request":{"href":"https://api.github.com/repos/privat/nit/pulls/1206"}}},"pull_request":{"url":"https://api.github.com/repos/privat/nit/pulls/1206","id":31202408,"html_url":"https://github.com/privat/nit/pull/1206","diff_url":"https://github.com/privat/nit/pull/1206.diff","patch_url":"https://github.com/privat/nit/pull/1206.patch","issue_url":"https://api.github.com/repos/privat/nit/issues/1206","number":1206,"state":"open","locked":false,"title":"Enable tagging of primitive types","user":{"login":"privat","id":135828,"avatar_url":"https://avatars.githubusercontent.com/u/135828?v=3","gravatar_id":"","url":"https://api.github.com/users/privat","html_url":"https://github.com/privat","followers_url":"https://api.github.com/users/privat/followers","following_url":"https://api.github.com/users/privat/following{/other_user}","gists_url":"https://api.github.com/users/privat/gists{/gist_id}","starred_url":"https://api.github.com/users/privat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/privat/subscriptions","organizations_url":"https://api.github.com/users/privat/orgs","repos_url":"https://api.github.com/users/privat/repos","events_url":"https://api.github.com/users/privat/events{/privacy}","received_events_url":"https://api.github.com/users/privat/received_events","type":"User","site_admin":false},"body":"Another old optimization since it was present in PRM, the Australopithecus compiler.\r\n\r\nThis PR bring back tagging of the primitives types Int, Bool and Char.\r\n\r\nPreviously, all primitive types where boxed. \r\nIt means that when a Bool, or any primitive object, must be manipulated in a polymorphic way (i.e. as an Object in a `val*`), a small box is allocated that contain the value and the reference (the `val*`) points to the box.\r\nThe boxes use the layout of real objects (with a pointer to the class table and everything) so that boxes are compatible with the various implementation of OO mechanism, eg `obj->class->vtf[METHODID]` to implement a method invocation.\r\n\r\nBasically boxes work like Java auxiliary classes (eg. `Integer`) except that they are fully transparent for the user and, more important, a implementation detail unrelated to the specification of the language.\r\nTherefore, one can provide a different implementation, like tagging, without worrying about breaking the specification and existing programs.\r\n\r\nThe principle of tagging is that `val*` values are overloaded to store primitive value in addition to genuine pointers to allocated object.\r\nThe two low bits of the `val*` (so 4 combinations) is used to distinguish if the value is a real pointer (in this case, bits are 00) or one of the masqueraded common type (Int, Bool and Char).\r\nIf it is a pointer there is nothing to do and the value can be used as is.\r\nIf it is a primitive value, then the real value is stored in the remaining bits (but shifted).\r\nThe trick works because allocated objects are aligned so that pointer of genuine allocated object have always their last two bits at 00.\r\n\r\nThe advantage of tagging is that this reduces the cost of manipulating primitive values in a polymorphic way, especially this reduce the numerous allocations of short lived boxes that is slow to do and increase the workload of the GC.\r\nBy comparison, with tagging, masquerading a Bool as a `val*` is easily done with few bit-to-bit operations.\r\n\r\nUnfortunately, tagging is not a panacea since `val*` is not always a real pointer and require specific and additional protection to avoid doing `obj->class` in the case of `obj` is in fact a tagged value.\r\nTherefore tagging add a minimal but systematic overhead to OO mechanisms like calls, type tests and equality tests.\r\n\r\nAfter quick tests, the numbers are encouraging.\r\n\r\nFor nitc/nitc/nitc:\r\nbefore: 0m6.796s\r\nafter: 0m6.452s (-5%, not that bad)\r\n\r\nBenches where run and tagging was either comparable or better than systematic boxing:\r\n\r\n![](https://cloud.githubusercontent.com/assets/135828/6656784/b5a38698-cb67-11e4-96a4-c46f7df2331f.png)\r\n\r\nEspecially `lib/ai/examples/queens.nit` get the best of it with a -20% improvement.\r\nThat make sense because it use arrays of integers to model the states of the n-queen problem. And unfortunately arrays are implemented in a homogeneous way where elements are always polymorphic `val*` values.\r\nOnce generics and collections are implemented in an heterogeneous way for primitive types, the benefit of tagging should be reevaluated.\r\n\r\nNote: funnily, the main commit of the series, the one that implements tagging, is only made of insertions of lines (no deletion or changes) and it only modifies a single file.\r\n","created_at":"2015-03-15T16:06:25Z","updated_at":"2015-03-17T14:23:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5d23aa50674712681202d59a316b657092cb0120","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/privat/nit/pulls/1206/commits","review_comments_url":"https://api.github.com/repos/privat/nit/pulls/1206/comments","review_comment_url":"https://api.github.com/repos/privat/nit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/privat/nit/issues/1206/comments","statuses_url":"https://api.github.com/repos/privat/nit/statuses/5bafd3fa95f6ad8e944cb365181abf47f34e5983","head":{"label":"privat:tagging","ref":"tagging","sha":"5bafd3fa95f6ad8e944cb365181abf47f34e5983","user":{"login":"privat","id":135828,"avatar_url":"https://avatars.githubusercontent.com/u/135828?v=3","gravatar_id":"","url":"https://api.github.com/users/privat","html_url":"https://github.com/privat","followers_url":"https://api.github.com/users/privat/followers","following_url":"https://api.github.com/users/privat/following{/other_user}","gists_url":"https://api.github.com/users/privat/gists{/gist_id}","starred_url":"https://api.github.com/users/privat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/privat/subscriptions","organizations_url":"https://api.github.com/users/privat/orgs","repos_url":"https://api.github.com/users/privat/repos","events_url":"https://api.github.com/users/privat/events{/privacy}","received_events_url":"https://api.github.com/users/privat/received_events","type":"User","site_admin":false},"repo":{"id":328597,"name":"nit","full_name":"privat/nit","owner":{"login":"privat","id":135828,"avatar_url":"https://avatars.githubusercontent.com/u/135828?v=3","gravatar_id":"","url":"https://api.github.com/users/privat","html_url":"https://github.com/privat","followers_url":"https://api.github.com/users/privat/followers","following_url":"https://api.github.com/users/privat/following{/other_user}","gists_url":"https://api.github.com/users/privat/gists{/gist_id}","starred_url":"https://api.github.com/users/privat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/privat/subscriptions","organizations_url":"https://api.github.com/users/privat/orgs","repos_url":"https://api.github.com/users/privat/repos","events_url":"https://api.github.com/users/privat/events{/privacy}","received_events_url":"https://api.github.com/users/privat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/privat/nit","description":"Nit language","fork":false,"url":"https://api.github.com/repos/privat/nit","forks_url":"https://api.github.com/repos/privat/nit/forks","keys_url":"https://api.github.com/repos/privat/nit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/privat/nit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/privat/nit/teams","hooks_url":"https://api.github.com/repos/privat/nit/hooks","issue_events_url":"https://api.github.com/repos/privat/nit/issues/events{/number}","events_url":"https://api.github.com/repos/privat/nit/events","assignees_url":"https://api.github.com/repos/privat/nit/assignees{/user}","branches_url":"https://api.github.com/repos/privat/nit/branches{/branch}","tags_url":"https://api.github.com/repos/privat/nit/tags","blobs_url":"https://api.github.com/repos/privat/nit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/privat/nit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/privat/nit/git/refs{/sha}","trees_url":"https://api.github.com/repos/privat/nit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/privat/nit/statuses/{sha}","languages_url":"https://api.github.com/repos/privat/nit/languages","stargazers_url":"https://api.github.com/repos/privat/nit/stargazers","contributors_url":"https://api.github.com/repos/privat/nit/contributors","subscribers_url":"https://api.github.com/repos/privat/nit/subscribers","subscription_url":"https://api.github.com/repos/privat/nit/subscription","commits_url":"https://api.github.com/repos/privat/nit/commits{/sha}","git_commits_url":"https://api.github.com/repos/privat/nit/git/commits{/sha}","comments_url":"https://api.github.com/repos/privat/nit/comments{/number}","issue_comment_url":"https://api.github.com/repos/privat/nit/issues/comments{/number}","contents_url":"https://api.github.com/repos/privat/nit/contents/{+path}","compare_url":"https://api.github.com/repos/privat/nit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/privat/nit/merges","archive_url":"https://api.github.com/repos/privat/nit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/privat/nit/downloads","issues_url":"https://api.github.com/repos/privat/nit/issues{/number}","pulls_url":"https://api.github.com/repos/privat/nit/pulls{/number}","milestones_url":"https://api.github.com/repos/privat/nit/milestones{/number}","notifications_url":"https://api.github.com/repos/privat/nit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/privat/nit/labels{/name}","releases_url":"https://api.github.com/repos/privat/nit/releases{/id}","created_at":"2009-10-06T15:03:00Z","updated_at":"2015-03-15T05:12:18Z","pushed_at":"2015-03-16T04:50:10Z","git_url":"git://github.com/privat/nit.git","ssh_url":"git@github.com:privat/nit.git","clone_url":"https://github.com/privat/nit.git","svn_url":"https://github.com/privat/nit","homepage":"http://nitlanguage.org","size":78278,"stargazers_count":65,"watchers_count":65,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":36,"mirror_url":null,"open_issues_count":108,"forks":36,"open_issues":108,"watchers":65,"default_branch":"master"}},"base":{"label":"privat:master","ref":"master","sha":"02bd2e568b1f0e7331524788eda3cda1ce30b161","user":{"login":"privat","id":135828,"avatar_url":"https://avatars.githubusercontent.com/u/135828?v=3","gravatar_id":"","url":"https://api.github.com/users/privat","html_url":"https://github.com/privat","followers_url":"https://api.github.com/users/privat/followers","following_url":"https://api.github.com/users/privat/following{/other_user}","gists_url":"https://api.github.com/users/privat/gists{/gist_id}","starred_url":"https://api.github.com/users/privat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/privat/subscriptions","organizations_url":"https://api.github.com/users/privat/orgs","repos_url":"https://api.github.com/users/privat/repos","events_url":"https://api.github.com/users/privat/events{/privacy}","received_events_url":"https://api.github.com/users/privat/received_events","type":"User","site_admin":false},"repo":{"id":328597,"name":"nit","full_name":"privat/nit","owner":{"login":"privat","id":135828,"avatar_url":"https://avatars.githubusercontent.com/u/135828?v=3","gravatar_id":"","url":"https://api.github.com/users/privat","html_url":"https://github.com/privat","followers_url":"https://api.github.com/users/privat/followers","following_url":"https://api.github.com/users/privat/following{/other_user}","gists_url":"https://api.github.com/users/privat/gists{/gist_id}","starred_url":"https://api.github.com/users/privat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/privat/subscriptions","organizations_url":"https://api.github.com/users/privat/orgs","repos_url":"https://api.github.com/users/privat/repos","events_url":"https://api.github.com/users/privat/events{/privacy}","received_events_url":"https://api.github.com/users/privat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/privat/nit","description":"Nit language","fork":false,"url":"https://api.github.com/repos/privat/nit","forks_url":"https://api.github.com/repos/privat/nit/forks","keys_url":"https://api.github.com/repos/privat/nit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/privat/nit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/privat/nit/teams","hooks_url":"https://api.github.com/repos/privat/nit/hooks","issue_events_url":"https://api.github.com/repos/privat/nit/issues/events{/number}","events_url":"https://api.github.com/repos/privat/nit/events","assignees_url":"https://api.github.com/repos/privat/nit/assignees{/user}","branches_url":"https://api.github.com/repos/privat/nit/branches{/branch}","tags_url":"https://api.github.com/repos/privat/nit/tags","blobs_url":"https://api.github.com/repos/privat/nit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/privat/nit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/privat/nit/git/refs{/sha}","trees_url":"https://api.github.com/repos/privat/nit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/privat/nit/statuses/{sha}","languages_url":"https://api.github.com/repos/privat/nit/languages","stargazers_url":"https://api.github.com/repos/privat/nit/stargazers","contributors_url":"https://api.github.com/repos/privat/nit/contributors","subscribers_url":"https://api.github.com/repos/privat/nit/subscribers","subscription_url":"https://api.github.com/repos/privat/nit/subscription","commits_url":"https://api.github.com/repos/privat/nit/commits{/sha}","git_commits_url":"https://api.github.com/repos/privat/nit/git/commits{/sha}","comments_url":"https://api.github.com/repos/privat/nit/comments{/number}","issue_comment_url":"https://api.github.com/repos/privat/nit/issues/comments{/number}","contents_url":"https://api.github.com/repos/privat/nit/contents/{+path}","compare_url":"https://api.github.com/repos/privat/nit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/privat/nit/merges","archive_url":"https://api.github.com/repos/privat/nit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/privat/nit/downloads","issues_url":"https://api.github.com/repos/privat/nit/issues{/number}","pulls_url":"https://api.github.com/repos/privat/nit/pulls{/number}","milestones_url":"https://api.github.com/repos/privat/nit/milestones{/number}","notifications_url":"https://api.github.com/repos/privat/nit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/privat/nit/labels{/name}","releases_url":"https://api.github.com/repos/privat/nit/releases{/id}","created_at":"2009-10-06T15:03:00Z","updated_at":"2015-03-15T05:12:18Z","pushed_at":"2015-03-16T04:50:10Z","git_url":"git://github.com/privat/nit.git","ssh_url":"git@github.com:privat/nit.git","clone_url":"https://github.com/privat/nit.git","svn_url":"https://github.com/privat/nit","homepage":"http://nitlanguage.org","size":78278,"stargazers_count":65,"watchers_count":65,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":36,"mirror_url":null,"open_issues_count":108,"forks":36,"open_issues":108,"watchers":65,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/privat/nit/pulls/1206"},"html":{"href":"https://github.com/privat/nit/pull/1206"},"issue":{"href":"https://api.github.com/repos/privat/nit/issues/1206"},"comments":{"href":"https://api.github.com/repos/privat/nit/issues/1206/comments"},"review_comments":{"href":"https://api.github.com/repos/privat/nit/pulls/1206/comments"},"review_comment":{"href":"https://api.github.com/repos/privat/nit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/privat/nit/pulls/1206/commits"},"statuses":{"href":"https://api.github.com/repos/privat/nit/statuses/5bafd3fa95f6ad8e944cb365181abf47f34e5983"}}}}