Skip to content

Make parsing even faster, and use less memory #108

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

Merged
merged 1 commit into from
Aug 29, 2017

Conversation

gpittarelli
Copy link
Member

@gpittarelli gpittarelli commented Aug 29, 2017

Further refinement to #107. cpu+mem profiler in emacs still showed a global scope completion with javascript-typescript-langserver chewing through 119MB and GC was taking up 28% of the runtime. Profiling still pointed towards lsp--parser-read. I suspected constantly concat'ing chunks was making a ton of extra allocs; eg we'd get a 4k chunk initially, then we'd alloc a new 8k chunk when (to hold leftover 4k + new chunk), then 12k, 16, ... compounding until we reached the full megabyte response.

This change preallocates a single big string of the total Content-Length size, then fills it as we go. This cuts memory usage to around 29M and GC cpu time to ~23%.

Note: trusting the server to not set a malicious Content-Length...

As an aside, json-read-from-string is now the the single biggest CPU bottleneck, followed by GC and then various internal emacs completion stuff. So I guess we're good for now?

Number are from running a test script with emacs -q --script. Profiles are in the zip (open with profiler-find-profile)
profiles.zip

@vibhavp vibhavp merged commit 48233dc into emacs-lsp:master Aug 29, 2017
@vibhavp
Copy link
Member

vibhavp commented Aug 29, 2017

Thanks!

@gpittarelli gpittarelli deleted the gjp/even-faster branch August 30, 2017 01:07
wkirschbaum pushed a commit to wkirschbaum/lsp-mode that referenced this pull request Jun 1, 2021
Hopefully it makes it more obvious that it can take a while
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants