{"action":"created","issue":{"url":"https://api.github.com/repos/pangloss/vim-javascript/issues/391","repository_url":"https://api.github.com/repos/pangloss/vim-javascript","labels_url":"https://api.github.com/repos/pangloss/vim-javascript/issues/391/labels{/name}","comments_url":"https://api.github.com/repos/pangloss/vim-javascript/issues/391/comments","events_url":"https://api.github.com/repos/pangloss/vim-javascript/issues/391/events","html_url":"https://github.com/pangloss/vim-javascript/pull/391","id":150239417,"number":391,"title":"Performance Improvements","user":{"login":"amadeus","id":83376,"avatar_url":"https://avatars.githubusercontent.com/u/83376?v=3","gravatar_id":"","url":"https://api.github.com/users/amadeus","html_url":"https://github.com/amadeus","followers_url":"https://api.github.com/users/amadeus/followers","following_url":"https://api.github.com/users/amadeus/following{/other_user}","gists_url":"https://api.github.com/users/amadeus/gists{/gist_id}","starred_url":"https://api.github.com/users/amadeus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amadeus/subscriptions","organizations_url":"https://api.github.com/users/amadeus/orgs","repos_url":"https://api.github.com/users/amadeus/repos","events_url":"https://api.github.com/users/amadeus/events{/privacy}","received_events_url":"https://api.github.com/users/amadeus/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-22T01:36:13Z","updated_at":"2016-04-22T23:26:15Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/pangloss/vim-javascript/pulls/391","html_url":"https://github.com/pangloss/vim-javascript/pull/391","diff_url":"https://github.com/pangloss/vim-javascript/pull/391.diff","patch_url":"https://github.com/pangloss/vim-javascript/pull/391.patch"},"body":"I recently learned a bit about the `:syntime` command, and decided to use it to profile our syntax file. I've found some things that I think we can really optimize and I actually got some fairly significant optimizations just in this PR.\r\n\r\nI am using a fully compiled version of [PhaserJS](https://raw.githubusercontent.com/photonstorm/phaser/dev/build/phaser.js) for these benchmarks. I think it's safe to say it's a huge file and I considered it a good way to benchmark performance. As an aside, if there are files you find performance to be pretty bad, you should link it here so I can run these benchmarks and look for other optimizations.\r\n\r\nThe steps to reproduce the tests are as follows\r\n\r\n1. Open the `phaser.js` file\r\n2. Press `gg` to scroll to the top (I would additionally do `:set nowrap` as well)\r\n3. Start the syntax profiler: `:syntime on`\r\n4. Scroll quickly to around line 10,000 (I could've gone further, but I found it to be a pretty healthy test time)\r\n5. Get the profiles results using `:syntime report`\r\n\r\nHere are before and after results for the most intensive selectors:\r\n\r\n## Before\r\n```\r\nTOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN\r\n1.617329   62434  0       0.002201    0.000026  jsGlobalObjects    \\%(Intl\\.\\)\\@<=\\(Collator\\|DateTimeFormat\\|\r\n1.047933   19970  2490    0.002397    0.000052  jsFuncAssignExpr   \\v%(%([a-zA-Z_$]\\k*\\.)*[a-zA-Z_$]\\k*\\s*\\=\\s\r\n1.028959   147679 93522   0.002242    0.000007  jsOperator         \\(!\\||\\|&\\|+\\|-\\|<\\|>\\|=\\|%\\|\\/\\|*\\|\\~\\|\\^\\\r\n0.977351   69643  10656   0.002030    0.000014  jsRegexpString     \\(\\(\\(return\\|case\\)\\s\\+\\)\\@<=\\|\\(\\([)\\]\"']\r\n0.932609   62434  0       0.002367    0.000015  jsArrowFuncArgs    \\(\\k\\)\\+\\s*\\(=>\\)\\@=\r\n0.930731   109058 49930   0.003152    0.000009  jsFuncCall         \\k\\+\\%(\\s*(\\)\\@=\r\n0.701920   97547  35215   0.001612    0.000007  jsAssignmentExpr   \\v%([a-zA-Z_$]\\k*\\.)*[a-zA-Z_$]\\k*\\s*\\=\\>@!\r\n0.513394   192983 163196   0.001123   0.000003  jsNoise            \\%(:\\|,\\|\\;\\|\\.\\)\r\n0.439069   62434  0       0.001627    0.000007  jsTaggedTemplate   \\k\\+\\(\\(\\n\\|\\s\\)\\+\\)\\?`\r\n0.398041   103527 40664   0.001752    0.000004  jsNumber           \\<-\\=\\d\\+\\(L\\|[eE][+-]\\=\\d\\+\\)\\=\\>\\|\\<0[xX]\r\n0.205140   63112  687     0.001655    0.000003  jsFloat            \\<-\\=\\%(\\d\\+\\.\\d\\+\\|\\d\\+\\.\\|\\.\\d\\+\\)\\%([eE]\r\n0.189091   40580  23100   0.002135    0.000005  jsAssignExpIdent   \\v[a-zA-Z_$]\\k*\\ze%(\\s*\\=)\r\n0.140040   35583  3553    0.001768    0.000004  jsDocTags          @\\(abstract\\|access\\|accessor\\|author\\|clas\r\n0.132321   20175  1427    0.001212    0.000007  jsObjectKey        \\<[a-zA-Z_$][0-9a-zA-Z_$]*\\>\\(\\s*:\\)\\@=\r\n0.089218   63451  2689    0.001222    0.000001  jsLineComment      ^\\s*\\/\\/       \r\n```\r\n\r\n## After\r\n```\r\nTOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN\r\n0.887965   68688  12559   0.002036    0.000013  jsRegexpString     \\%(\\%(\\%(return\\|case\\)\\s\\+\\)\\@<=\\|\\%(\\%([)\\]\"']\\|\\d\\|\\w\r\n0.855625   109576 53343   0.002364    0.000008  jsFuncCall         \\k\\+\\%(\\s*(\\)\\@=\r\n0.671938   59407  0       0.002029    0.000011  jsArrowFuncArgs    \\k\\+\\s*\\%(=>\\)\\@=\r\n0.379020   137695 86113   0.001926    0.000003  jsOperator         [\\!\\|\\&\\+\\-\\<\\>\\=\\%\\/\\*\\~\\^]\\{1}\r\n0.376395   101537 41691   0.001237    0.000004  jsNumber           \\<-\\=\\d\\+\\(L\\|[eE][+-]\\=\\d\\+\\)\\=\\>\\|\\<0[xX]\\x\\+\\>\r\n0.295642   59407  0       0.002014    0.000005  jsTaggedTemplate   \\k\\+\\%([\\n\\s]\\+\\)\\?`\r\n0.284822   181546 152855   0.001993   0.000002  jsNoise            [:,\\;\\.]\\{1}\r\n0.194653   60391  991     0.001991    0.000003  jsFloat            \\<-\\=\\%(\\d\\+\\.\\d\\+\\|\\d\\+\\.\\|\\.\\d\\+\\)\\%([eE][+-]\\=\\d\\+\\)\\\r\n0.139054   21099  1720    0.002092    0.000007  jsObjectKey        \\<[a-zA-Z_$][0-9a-zA-Z_$]*\\>\\(\\s*:\\)\\@=\r\n0.128952   35864  3521    0.002004    0.000004  jsDocTags          @\\(abstract\\|access\\|accessor\\|author\\|classdesc\\|consta\r\n0.093106   60401  2413    0.001991    0.000002  jsLineComment      ^\\s*\\/\\/\r\n```\r\n\r\nIn summary, I found a few rules that seem to be just hanging around not matching anything (probably from a bygone era of function matching) that could easily be removed and also found a few ways to optimize a few of the hotter important contenders.\r\n\r\nI am open to more optimization suggestions if you guys have them! I will let this sit for a bit though, to ensure I haven't really broken anything, but so far everything seems very solid."},"comment":{"url":"https://api.github.com/repos/pangloss/vim-javascript/issues/comments/213623283","html_url":"https://github.com/pangloss/vim-javascript/pull/391#issuecomment-213623283","issue_url":"https://api.github.com/repos/pangloss/vim-javascript/issues/391","id":213623283,"user":{"login":"amadeus","id":83376,"avatar_url":"https://avatars.githubusercontent.com/u/83376?v=3","gravatar_id":"","url":"https://api.github.com/users/amadeus","html_url":"https://github.com/amadeus","followers_url":"https://api.github.com/users/amadeus/followers","following_url":"https://api.github.com/users/amadeus/following{/other_user}","gists_url":"https://api.github.com/users/amadeus/gists{/gist_id}","starred_url":"https://api.github.com/users/amadeus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amadeus/subscriptions","organizations_url":"https://api.github.com/users/amadeus/orgs","repos_url":"https://api.github.com/users/amadeus/repos","events_url":"https://api.github.com/users/amadeus/events{/privacy}","received_events_url":"https://api.github.com/users/amadeus/received_events","type":"User","site_admin":false},"created_at":"2016-04-22T23:26:15Z","updated_at":"2016-04-22T23:26:15Z","body":"I've noticed that long lines tend to lag syntax highlighting, but generally the regexes I've used in JS have been pretty small and I have never noticed any serious performance issues, although I think it can be confirmed by the fact that `jsRegexpString` is a always at the top of the regex checks.\r\n\r\nThis PR might help a bit with this? I think the reason that `jsRegexpString` is so gnarly is that massive look behind. I am a bit afraid to mess with it more since I know it has incorporated a lot of various fixes over the years for bizarre regex edge cases."}}