Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting with a TS/JS file is significantly file slower than opening other files #77990

Closed
jrieken opened this issue Jul 26, 2019 · 16 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug candidate Issue identified as probable candidate for fixing in the next release important Issue identified as high-priority perf-startup verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@jrieken
Copy link
Member

jrieken commented Jul 26, 2019

  • start profiler
  • reload with a TS file
  • stop profiler
  • 🔥 notice how all grammar files are read and processed
  • start profiler again
  • reload with a JSON file
  • stop profiler
  • 🚀 getting colors was much, much quicker

Screenshot 2019-07-26 at 15 01 52

The problem is the jsdoc injection which itself drags in the MD grammar which drags in the world...

@alexdima alexdima added the important Issue identified as high-priority label Jul 29, 2019
@alexdima
Copy link
Member

root cause --

{
"scopeName": "documentation.injection",
"path": "./syntaxes/jsdoc.injection.tmLanguage.json",
"injectTo": [
"source.ts",
"source.tsx",
"source.js",
"source.js.jsx"
]
}

This injection drags in markdown, which drags in almost all our grammars...

Removing that reduces the time significantly.

@mjbvz
Copy link
Collaborator

mjbvz commented Aug 13, 2019

I believe the core reason for this is the markdown grammar's fenced code block support. That ends up pulling in grammars for most of our builtin languages. Will see if including a subset of the markdown grammar fixes this or if we maybe need to split up the markdown grammar file in some way

(note that we already do include subsets of the markdown grammar instead of pulling in the entire thing, but one of those subsets is the entire fenced code block set of rules)

@alexdima
Copy link
Member

@mjbvz Good idea! I think going for a reduced subset is the right thing to do.

I would also incorporate this into the TS grammar itself, the TS grammar already appears to do a lot of JSDoc parsing anyways, so why wouldn't Sublime and other editors where the TS grammar is used benefit from this...

Also, IMHO we should avoid injection if possible and in this case I think it is possible because we can reach to the TS team who own the TS grammar and they can add the fenced block rule to their grammar if we would give them a PR.

@mjbvz
Copy link
Collaborator

mjbvz commented Aug 14, 2019

It's a bit complicated since fenced code blocks can appear inside other markdown elements, like lists, which we do want to support in jsdoc comments

Sublime doesn't support some of the rules we need to support the jsdoc highlighting feature (microsoft/TypeScript-TmLanguage#693) so that why I went with the injection based approach

I think we either need to:

  • Inline some basic parts of the markdown grammar
  • Split all the fenced code block into an injection grammar (these are not loaded for referenced grammars)

I'll be looking into the first approach today

@mjbvz
Copy link
Collaborator

mjbvz commented Aug 15, 2019

After thinking about this more, I don't think we should do a js/ts specific fix. The same performance problem also exists when you load VS Code with a markdown file open.

I've opened microsoft/vscode-textmate#106 that proposes loading referenced grammars lazily. This would fix the issue for js/ts and for normal md files too

@alexdima
Copy link
Member

@mjbvz Let's remove the TS injection until we address microsoft/vscode-textmate#106
(We have only added this a few months ago and IMHO is not critical to the TS experience)

@mjbvz mjbvz closed this as completed in 5c27385 Aug 20, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 4, 2019
@bpasero
Copy link
Member

bpasero commented Oct 28, 2019

I am still seeing this in web. Steps:

  • add a console.log statement where we load grammars using file service:

const content = await this._fileService.readFile(resource);

  • open a JS/TS file
  • observe that every grammar seems to be loaded
javascript/syntaxes/JavaScript.tmLanguage.json
typescript-basics/syntaxes/jsdoc.js.injection.tmLanguage.json
markdown-basics/syntaxes/markdown.tmLanguage.json
typescript-basics/syntaxes/TypeScript.tmLanguage.json
javascript/syntaxes/JavaScriptReact.tmLanguage.json
css/syntaxes/css.tmLanguage.json
html/syntaxes/html.tmLanguage.json
ini/syntaxes/ini.tmLanguage.json
java/syntaxes/java.tmLanguage.json
lua/syntaxes/lua.tmLanguage.json
make/syntaxes/make.tmLanguage.json
perl/syntaxes/perl.tmLanguage.json
r/syntaxes/r.tmLanguage.json
ruby/syntaxes/ruby.tmLanguage.json
php/syntaxes/php.tmLanguage.json
sql/syntaxes/sql.tmLanguage.json
vb/syntaxes/asp-vb-net.tmlanguage.json
xml/syntaxes/xml.tmLanguage.json
xml/syntaxes/xsl.tmLanguage.json
yaml/syntaxes/yaml.tmLanguage.json
bat/syntaxes/batchfile.tmLanguage.json
clojure/syntaxes/clojure.tmLanguage.json
coffeescript/syntaxes/coffeescript.tmLanguage.json
cpp/syntaxes/c.tmLanguage.json
cpp/syntaxes/cpp.tmLanguage.json
git/syntaxes/diff.tmLanguage.json
docker/syntaxes/docker.tmLanguage.json
git/syntaxes/git-commit.tmLanguage.json
git/syntaxes/git-rebase.tmLanguage.json
go/syntaxes/go.tmLanguage.json
groovy/syntaxes/groovy.tmLanguage.json
pug/syntaxes/pug.tmLanguage.json
javascript/syntaxes/Regular%20Expressions%20(JavaScript).tmLanguage
json/syntaxes/JSON.tmLanguage.json
json/syntaxes/JSONC.tmLanguage.json
less/syntaxes/less.tmLanguage.json
objective-c/syntaxes/objective-c.tmLanguage.json
swift/syntaxes/swift.tmLanguage.json
scss/syntaxes/scss.tmLanguage.json
perl/syntaxes/perl6.tmLanguage.json
powershell/syntaxes/powershell.tmLanguage.json
python/syntaxes/MagicPython.tmLanguage.json
python/syntaxes/MagicRegExp.tmLanguage.json
rust/syntaxes/rust.tmLanguage.json
shellscript/syntaxes/shell-unix-bash.tmLanguage.json
typescript-basics/syntaxes/TypeScriptReact.tmLanguage.json
csharp/syntaxes/csharp.tmLanguage.json
fsharp/syntaxes/fsharp.tmLanguage.json
handlebars/syntaxes/Handlebars.tmLanguage.json
log/syntaxes/log.tmLanguage.json
html/syntaxes/html-derivative.tmLanguage.json
typescript-basics/syntaxes/jsdoc.ts.injection.tmLanguage.json
cpp/syntaxes/cpp.embedded.macro.tmLanguage.json
scss/syntaxes/sassdoc.tmLanguage.json

@bpasero bpasero reopened this Oct 28, 2019
@bpasero bpasero added the verification-needed Verification of issue is requested label Oct 28, 2019
@bpasero bpasero modified the milestones: August 2019, October 2019 Oct 28, 2019
@alexdima
Copy link
Member

It is unfortunate how this was never verified because it didn't have a bug label :|

@alexdima alexdima added the bug Issue identified by VS Code Team member as probable bug label Oct 28, 2019
@alexdima
Copy link
Member

The fix from @mjbvz in 5c27385 unfortunately had no effect because the grammar resolver was not written to only partially resolve grammars, so even if a small subset of markdown was included via injection, the entirety of it was loaded.

@bpasero
Copy link
Member

bpasero commented Oct 28, 2019

Thanks!

@mjbvz
Copy link
Collaborator

mjbvz commented Oct 29, 2019

Thanks @alexandrudima! Sorry, I thought I had profiled when I made the original fix but clearly was not look at the right thing. You change looks much better

@bpasero
Copy link
Member

bpasero commented Oct 29, 2019

@mjbvz there are other languages that will suffer from this issue too, should we fix them as well? For example I think F#, PHP, Perl. Probably anything that depends on markdown.

@connor4312
Copy link
Member

connor4312 commented Oct 29, 2019

I gave a spin at verifying this by measuring the total time spent in tokenize2 for a small JSON file and a small TypeScript file. Understanding that TypeScript will always be more complex than JSON, here's the results:

JSON:
 - 18.5ms
 - 20.6ms
 - 16.8ms

TypeScript:
 - 72.4ms
 - 76.1ms
 - 82.0ms

This appears a good bit better than the ~300ms Johannes reported initially, though we're on different hardware and opening different files. @alexandrudima @jrieken are these measurements within the bounds that you'd consider this resolved? (Unlabel if not 🙂 )

@connor4312 connor4312 added verified Verification succeeded and removed verification-needed Verification of issue is requested labels Oct 29, 2019
@jrieken
Copy link
Member Author

jrieken commented Oct 30, 2019

Yeah, I have measure the same number. I think reasonable because the JSON grammar is trivial in comparison to the TS grammar. Tho, there is still #77990 (comment) which we should probably move into a separate issue

@bpasero
Copy link
Member

bpasero commented Oct 30, 2019

Opened #83633 for @mjbvz

@alexdima alexdima added the candidate Issue identified as probable candidate for fixing in the next release label Nov 6, 2019
@alexdima
Copy link
Member

alexdima commented Nov 6, 2019

This is all rather complicated, but we had to revert vscode-textmate to the last month's stable version, because of a flaw which was causing #83541 .

That would technically mean that this issue is reopened (with the revert).

The lowest risk fix at this point is to revert vscode-textmate and delete the problematic injections.

@alexdima alexdima added verification-needed Verification of issue is requested and removed verified Verification succeeded labels Nov 6, 2019
@mjbvz mjbvz added the verified Verification succeeded label Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug candidate Issue identified as probable candidate for fixing in the next release important Issue identified as high-priority perf-startup verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants