{"action":"created","comment":{"url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/pulls/comments/117605129","pull_request_review_id":39331007,"id":117605129,"diff_hunk":"@@ -2,47 +2,50 @@ module.exports = ParseWavefrontObj\n \n // Map .obj vertex info line names to our returned property names\n var vertexInfoNameMap = {v: 'vertex', vt: 'uv', vn: 'normal'}\n-// The returned properties that we will populate\n-var parsedProperties = ['normal', 'uv', 'vertex', 'normalIndex', 'uvIndex', 'vertexIndex']\n+\n function ParseWavefrontObj (wavefrontString) {\n+  'use strict'\n+\n   var parsedJSON = {normal: [], uv: [], vertex: [], normalIndex: [], uvIndex: [], vertexIndex: []}\n \n   var linesInWavefrontObj = wavefrontString.split('\\n')\n \n+  var currentLine, currentLineTokens, vertexInfoType, i, k\n+\n   // Loop through and parse every line in our .obj file\n-  linesInWavefrontObj.forEach(function (currentLine) {\n+  for (i = 0; i < linesInWavefrontObj.length; i++) {\n+    currentLine = linesInWavefrontObj[i]\n     // Tokenize our current line\n-    var currentLineTokens = currentLine.split(' ')\n+    currentLineTokens = currentLine.split(' ')\n     // vertex position, vertex texture, or vertex normal\n-    var vertexInfoType = vertexInfoNameMap[currentLineTokens[0]]\n+    vertexInfoType = vertexInfoNameMap[currentLineTokens[0]]\n+\n     if (vertexInfoType) {\n-      parsedJSON[vertexInfoType] = parsedJSON[vertexInfoType].concat(currentLineTokens.slice(1))\n-      return\n+      for (k = 1; k < currentLineTokens.length; k++) {\n+        parsedJSON[vertexInfoType].push(parseFloat(currentLineTokens[k]))\n+      }\n+      continue\n     }\n+\n     if (currentLineTokens[0] === 'f') {\n       // Get our 4 sets of vertex, uv, and normal indices for this face\n-      for (var i = 1; i < 5; i++) {\n+      for (k = 1; k < 5; k++) {\n         // If there is no fourth face entry then this is specifying a triangle\n         // in this case we push `-1`\n         // Consumers of this module should check for `-1` before expanding face data\n-        if (i === 4 && !currentLineTokens[4]) {\n+        if (k === 4 && !currentLineTokens[4]) {\n           parsedJSON.vertexIndex.push(-1)\n           parsedJSON.uvIndex.push(-1)\n           parsedJSON.normalIndex.push(-1)\n         } else {\n-          var indices = currentLineTokens[i].split('/')\n-          parsedJSON.vertexIndex.push(Number(indices[0]) - 1) // We zero index\n-          parsedJSON.uvIndex.push(Number(indices[1]) - 1) // our face indices\n-          parsedJSON.normalIndex.push(Number(indices[2]) - 1) // by subtracting 1\n+          var indices = currentLineTokens[k].split('/')\n+          parsedJSON.vertexIndex.push(parseInt(indices[0], 10) - 1) // We zero index\n+          parsedJSON.uvIndex.push(parseInt(indices[1], 10) - 1) // our face indices\n+          parsedJSON.normalIndex.push(parseInt(indices[2], 10) - 1) // by subtracting 1\n         }\n       }\n     }\n-  })\n-  // Convert our parsed strings into floats (trims trailing insignificant `0`s)\n-  parsedProperties.forEach(function (property) {","path":"src/wavefront-obj-parser.js","position":62,"original_position":62,"commit_id":"7b37e04c8f41aed5301a13f40813c22766df9fd4","original_commit_id":"7b37e04c8f41aed5301a13f40813c22766df9fd4","user":{"login":"chinedufn","id":2099811,"avatar_url":"https://avatars3.githubusercontent.com/u/2099811?v=3","gravatar_id":"","url":"https://api.github.com/users/chinedufn","html_url":"https://github.com/chinedufn","followers_url":"https://api.github.com/users/chinedufn/followers","following_url":"https://api.github.com/users/chinedufn/following{/other_user}","gists_url":"https://api.github.com/users/chinedufn/gists{/gist_id}","starred_url":"https://api.github.com/users/chinedufn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chinedufn/subscriptions","organizations_url":"https://api.github.com/users/chinedufn/orgs","repos_url":"https://api.github.com/users/chinedufn/repos","events_url":"https://api.github.com/users/chinedufn/events{/privacy}","received_events_url":"https://api.github.com/users/chinedufn/received_events","type":"User","site_admin":false},"body":"Fantastic fixes","created_at":"2017-05-20T08:28:21Z","updated_at":"2017-05-20T08:28:21Z","html_url":"https://github.com/chinedufn/wavefront-obj-parser/pull/1#discussion_r117605129","pull_request_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/pulls/comments/117605129"},"html":{"href":"https://github.com/chinedufn/wavefront-obj-parser/pull/1#discussion_r117605129"},"pull_request":{"href":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/pulls/1","id":121543324,"html_url":"https://github.com/chinedufn/wavefront-obj-parser/pull/1","diff_url":"https://github.com/chinedufn/wavefront-obj-parser/pull/1.diff","patch_url":"https://github.com/chinedufn/wavefront-obj-parser/pull/1.patch","issue_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/issues/1","number":1,"state":"open","locked":false,"title":"Parsing performances optimization","user":{"login":"kchapelier","id":5741699,"avatar_url":"https://avatars2.githubusercontent.com/u/5741699?v=3","gravatar_id":"","url":"https://api.github.com/users/kchapelier","html_url":"https://github.com/kchapelier","followers_url":"https://api.github.com/users/kchapelier/followers","following_url":"https://api.github.com/users/kchapelier/following{/other_user}","gists_url":"https://api.github.com/users/kchapelier/gists{/gist_id}","starred_url":"https://api.github.com/users/kchapelier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kchapelier/subscriptions","organizations_url":"https://api.github.com/users/kchapelier/orgs","repos_url":"https://api.github.com/users/kchapelier/repos","events_url":"https://api.github.com/users/kchapelier/events{/privacy}","received_events_url":"https://api.github.com/users/kchapelier/received_events","type":"User","site_admin":false},"body":"I've been using this module without much issue for some time but lately I had to convert huge OBJ models to json with some custom mapping for indexed Three.js BufferGeometries and it was taking a considerable amount of time (about 30 minutes for some models). After some profiling, I figured the parsing was the bottleneck. Here is my attempt at fixing it.\r\n\r\nFor reference, on my MBP late 2013, the time to parse my [test file](https://github.com/chinedufn/wavefront-obj-parser/files/1014895/core.obj.zip) (33kB, zip) went from `2050ms` to `38ms` with node v6.x.\r\n\r\nAll the tests and code-style checks are still passing.\r\n\r\n**Edit:** Just checked using the big files which were taking 30+ minutes, it's now a matter of less than 10 seconds.","created_at":"2017-05-19T17:03:11Z","updated_at":"2017-05-20T08:28:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"88b315e2235d839cf1538a5f6f20b6b1c86cb469","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/pulls/1/commits","review_comments_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/pulls/1/comments","review_comment_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/pulls/comments{/number}","comments_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/issues/1/comments","statuses_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/statuses/7b37e04c8f41aed5301a13f40813c22766df9fd4","head":{"label":"kchapelier:perfoptim","ref":"perfoptim","sha":"7b37e04c8f41aed5301a13f40813c22766df9fd4","user":{"login":"kchapelier","id":5741699,"avatar_url":"https://avatars2.githubusercontent.com/u/5741699?v=3","gravatar_id":"","url":"https://api.github.com/users/kchapelier","html_url":"https://github.com/kchapelier","followers_url":"https://api.github.com/users/kchapelier/followers","following_url":"https://api.github.com/users/kchapelier/following{/other_user}","gists_url":"https://api.github.com/users/kchapelier/gists{/gist_id}","starred_url":"https://api.github.com/users/kchapelier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kchapelier/subscriptions","organizations_url":"https://api.github.com/users/kchapelier/orgs","repos_url":"https://api.github.com/users/kchapelier/repos","events_url":"https://api.github.com/users/kchapelier/events{/privacy}","received_events_url":"https://api.github.com/users/kchapelier/received_events","type":"User","site_admin":false},"repo":{"id":91821717,"name":"wavefront-obj-parser","full_name":"kchapelier/wavefront-obj-parser","owner":{"login":"kchapelier","id":5741699,"avatar_url":"https://avatars2.githubusercontent.com/u/5741699?v=3","gravatar_id":"","url":"https://api.github.com/users/kchapelier","html_url":"https://github.com/kchapelier","followers_url":"https://api.github.com/users/kchapelier/followers","following_url":"https://api.github.com/users/kchapelier/following{/other_user}","gists_url":"https://api.github.com/users/kchapelier/gists{/gist_id}","starred_url":"https://api.github.com/users/kchapelier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kchapelier/subscriptions","organizations_url":"https://api.github.com/users/kchapelier/orgs","repos_url":"https://api.github.com/users/kchapelier/repos","events_url":"https://api.github.com/users/kchapelier/events{/privacy}","received_events_url":"https://api.github.com/users/kchapelier/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kchapelier/wavefront-obj-parser","description":"An api and cli for parsing wavefront .obj files into JSON","fork":true,"url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser","forks_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/forks","keys_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/teams","hooks_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/hooks","issue_events_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/issues/events{/number}","events_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/events","assignees_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/assignees{/user}","branches_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/branches{/branch}","tags_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/tags","blobs_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/git/refs{/sha}","trees_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/statuses/{sha}","languages_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/languages","stargazers_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/stargazers","contributors_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/contributors","subscribers_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/subscribers","subscription_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/subscription","commits_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/commits{/sha}","git_commits_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/git/commits{/sha}","comments_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/comments{/number}","issue_comment_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/issues/comments{/number}","contents_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/contents/{+path}","compare_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/merges","archive_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/downloads","issues_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/issues{/number}","pulls_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/pulls{/number}","milestones_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/milestones{/number}","notifications_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/labels{/name}","releases_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/releases{/id}","deployments_url":"https://api.github.com/repos/kchapelier/wavefront-obj-parser/deployments","created_at":"2017-05-19T15:48:43Z","updated_at":"2017-05-19T15:48:45Z","pushed_at":"2017-05-19T16:14:44Z","git_url":"git://github.com/kchapelier/wavefront-obj-parser.git","ssh_url":"git@github.com:kchapelier/wavefront-obj-parser.git","clone_url":"https://github.com/kchapelier/wavefront-obj-parser.git","svn_url":"https://github.com/kchapelier/wavefront-obj-parser","homepage":"http://chinedufn.github.io/wavefront-obj-parser/","size":380,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"chinedufn:master","ref":"master","sha":"464b0c948e01848383b71aa6db557635b8bd473e","user":{"login":"chinedufn","id":2099811,"avatar_url":"https://avatars3.githubusercontent.com/u/2099811?v=3","gravatar_id":"","url":"https://api.github.com/users/chinedufn","html_url":"https://github.com/chinedufn","followers_url":"https://api.github.com/users/chinedufn/followers","following_url":"https://api.github.com/users/chinedufn/following{/other_user}","gists_url":"https://api.github.com/users/chinedufn/gists{/gist_id}","starred_url":"https://api.github.com/users/chinedufn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chinedufn/subscriptions","organizations_url":"https://api.github.com/users/chinedufn/orgs","repos_url":"https://api.github.com/users/chinedufn/repos","events_url":"https://api.github.com/users/chinedufn/events{/privacy}","received_events_url":"https://api.github.com/users/chinedufn/received_events","type":"User","site_admin":false},"repo":{"id":54517686,"name":"wavefront-obj-parser","full_name":"chinedufn/wavefront-obj-parser","owner":{"login":"chinedufn","id":2099811,"avatar_url":"https://avatars3.githubusercontent.com/u/2099811?v=3","gravatar_id":"","url":"https://api.github.com/users/chinedufn","html_url":"https://github.com/chinedufn","followers_url":"https://api.github.com/users/chinedufn/followers","following_url":"https://api.github.com/users/chinedufn/following{/other_user}","gists_url":"https://api.github.com/users/chinedufn/gists{/gist_id}","starred_url":"https://api.github.com/users/chinedufn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chinedufn/subscriptions","organizations_url":"https://api.github.com/users/chinedufn/orgs","repos_url":"https://api.github.com/users/chinedufn/repos","events_url":"https://api.github.com/users/chinedufn/events{/privacy}","received_events_url":"https://api.github.com/users/chinedufn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chinedufn/wavefront-obj-parser","description":"An api and cli for parsing wavefront .obj files into JSON","fork":false,"url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser","forks_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/forks","keys_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/teams","hooks_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/hooks","issue_events_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/issues/events{/number}","events_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/events","assignees_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/assignees{/user}","branches_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/branches{/branch}","tags_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/tags","blobs_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/git/refs{/sha}","trees_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/statuses/{sha}","languages_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/languages","stargazers_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/stargazers","contributors_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/contributors","subscribers_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/subscribers","subscription_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/subscription","commits_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/commits{/sha}","git_commits_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/git/commits{/sha}","comments_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/comments{/number}","issue_comment_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/issues/comments{/number}","contents_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/contents/{+path}","compare_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/merges","archive_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/downloads","issues_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/issues{/number}","pulls_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/pulls{/number}","milestones_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/milestones{/number}","notifications_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/labels{/name}","releases_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/releases{/id}","deployments_url":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/deployments","created_at":"2016-03-23T00:11:46Z","updated_at":"2017-01-16T23:39:59Z","pushed_at":"2017-05-19T17:03:11Z","git_url":"git://github.com/chinedufn/wavefront-obj-parser.git","ssh_url":"git@github.com:chinedufn/wavefront-obj-parser.git","clone_url":"https://github.com/chinedufn/wavefront-obj-parser.git","svn_url":"https://github.com/chinedufn/wavefront-obj-parser","homepage":"http://chinedufn.github.io/wavefront-obj-parser/","size":431,"stargazers_count":5,"watchers_count":5,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/pulls/1"},"html":{"href":"https://github.com/chinedufn/wavefront-obj-parser/pull/1"},"issue":{"href":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/issues/1"},"comments":{"href":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/chinedufn/wavefront-obj-parser/statuses/7b37e04c8f41aed5301a13f40813c22766df9fd4"}}}}
{"actor":{"display_login":"chinedufn"}}