php-language-server icon indicating copy to clipboard operation
php-language-server copied to clipboard

Memory usage

Open umpirsky opened this issue 7 years ago • 22 comments

Using it with atom/ide-php, it consumes ~1.2G of RAM. Is that expected?

umpirsky avatar Sep 19 '17 15:09 umpirsky

Depends on how big your project is. What do the logs say?

felixfbecker avatar Sep 19 '17 16:09 felixfbecker

@felixfbecker How can I check logs?

umpirsky avatar Sep 19 '17 16:09 umpirsky

Depends on your client

felixfbecker avatar Sep 19 '17 16:09 felixfbecker

@felixfbecker It has 25298 PHP files including vendors.

umpirsky avatar Sep 19 '17 16:09 umpirsky

That's a pretty big project, so that is kinda expected atm. Not saying there is no potential for memory optimisation though. Do you need the whole folder open in your IDE?

felixfbecker avatar Sep 19 '17 16:09 felixfbecker

@felixfbecker Yes, it's a large project. And yes, I need whole folder.

I'm not sure how the server works, but the way I see it is that it needs some resources to index all the symbols etc, but once that's done, what is taking so much RAM? Shouldn't it just incrementally index and have everything else cached?

umpirsky avatar Sep 19 '17 18:09 umpirsky

It does that, but the index is in memory.

felixfbecker avatar Sep 19 '17 18:09 felixfbecker

@felixfbecker Aaah, I see. Big project - big index. I guess keeping it anywhere else would be too slow.

umpirsky avatar Sep 19 '17 18:09 umpirsky

@felixfbecker Does it parse only php files?

umpirsky avatar Sep 19 '17 18:09 umpirsky

Exactly. Keeping it in memory allows it to be look up definitions, completions, symbols etc fast. That said, there are definitely ways to store less data in the Definition class so it takes less RAM per index item. Yes, it only parses PHP files.

felixfbecker avatar Sep 19 '17 18:09 felixfbecker

@felixfbecker I see. It would be nice if it can detect what features are enabled, for example I don't use declarationLine and documentation hover, that would probably save lots of memory because they are large strings.

umpirsky avatar Sep 19 '17 19:09 umpirsky

they could also be resolved on-demand if that doesn't impact perf

felixfbecker avatar Sep 19 '17 19:09 felixfbecker

@felixfbecker Worth a try? What would be memory decrease in that case?

umpirsky avatar Sep 19 '17 19:09 umpirsky

I don't know, I never memory-profiled the language server (I wouldn't know what tool to use from the tip of my head)

felixfbecker avatar Sep 19 '17 19:09 felixfbecker

You could use blackfire.io for perf and memory profilling

staabm avatar Sep 19 '17 20:09 staabm

@felixfbecker Blackfire, xdebug or memory_get_usage().

umpirsky avatar Sep 19 '17 22:09 umpirsky

I wasn't aware that XDebug does memory profiling? memory_get_usage() is already used to log memory usage, but that doesn't tell what application parts actually use the most memory

felixfbecker avatar Sep 19 '17 23:09 felixfbecker

@felixfbecker I googled this out https://derickrethans.nl/xdebug-and-tracing-memory-usage.html

umpirsky avatar Sep 20 '17 07:09 umpirsky

@felixfbecker are there any plans of removing the index from memory? Have you though using sqlite for example? My project has 26k php files. I tried it with vscode and it's impossible to use. Indexing takes too much time too, by storing data in a database you can avoid big reindexing and just update what changed from the last time.

josecanciani avatar Feb 02 '18 18:02 josecanciani

@felixfbecker are there any plans of removing the index from memory? Have you though using sqlite for example? My project has 26k php files. I tried it with vscode and it's impossible to use. Indexing takes too much time too, by storing data in a database you can avoid big reindexing and just update what changed from the last time.

That is a great idea. My notebook has only 4 GB of ram where the language server take 1 Gb. It is impossible to do development with framework like laravel or symfony. Moving the database to disk should save most of the ram and re-indexing time.

SYip avatar May 02 '19 10:05 SYip

The issue is exacerbated when several language servers are running due to multiple projects. As a workaround I'm using earlyoom to kill off the language server: https://github.com/rfjakob/earlyoom.

apapsch avatar May 22 '19 10:05 apapsch

I found a temporary workaround on Linux: Enable swap (I used this article). Language server ran with no issues. I fallocated 4G.

Kenny2github avatar Aug 31 '21 21:08 Kenny2github