php-language-server
php-language-server copied to clipboard
Memory usage
Using it with atom/ide-php, it consumes ~1.2G of RAM. Is that expected?
Depends on how big your project is. What do the logs say?
@felixfbecker How can I check logs?
Depends on your client
@felixfbecker It has 25298 PHP files including vendors.
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 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?
It does that, but the index is in memory.
@felixfbecker Aaah, I see. Big project - big index. I guess keeping it anywhere else would be too slow.
@felixfbecker Does it parse only php files?
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 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.
they could also be resolved on-demand if that doesn't impact perf
@felixfbecker Worth a try? What would be memory decrease in that case?
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)
You could use blackfire.io for perf and memory profilling
@felixfbecker Blackfire, xdebug or memory_get_usage()
.
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 I googled this out https://derickrethans.nl/xdebug-and-tracing-memory-usage.html
@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.
@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.
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.
I found a temporary workaround on Linux: Enable swap (I used this article). Language server ran with no issues. I fallocated 4G.