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
phpactor is killing my cpu #2538
Comments
have you enabled Psalm or Phpstan? and which version of Phpactor are you using? you can also set this option to |
ok, the Psalm/PHPStan extensions wouild be enabled in the version you are using is from 10 weeks ago though, can you update to the latest development version ( Also I assume you are starting Neovim in the root of your project? If not try that. |
I've also had periods when phpactor just runs away and becomes painfully slow and I have to manually kill the processes. I also work on a large codebase though. I use phpactor with phpstan |
updated this morning through Mason to version:
I am, but been in or not doesn't change anything for me in that case.
One could say mine is pretty large too. I just tested with a folder with only a few files without an issue. |
Same here, it came abruptly without config change, it was working nicely before, now CPU stuck at 100% . It looks like it's indexing, after many minutes without actions the CPU slows down a bit to ~10% Using Phpactor with Helix, PHP 8.3, no composer, linux, all that was working alright few days before, that looks strange to me.
|
can you indicate which version of Phpactor you are using. indexing should be unreleated to multiple CPU cores being maxed out to 100% as the indexer uses only one core. i'd be more inclined to suspect:
|
if I add a 10 second delay to the worker process: diff --git a/lib/Extension/LanguageServer/Command/DiagnosticsCommand.php b/lib/Extension/LanguageServer/Comman>
index dd644fc8..22d93d5c 100644
--- a/lib/Extension/LanguageServer/Command/DiagnosticsCommand.php
+++ b/lib/Extension/LanguageServer/Command/DiagnosticsCommand.php
@@ -45,6 +45,7 @@ class DiagnosticsCommand extends Command
);
}
+ sleep(10);
$output->write($decoded);
return 0;
} and hit spam key presses I only get 1 or maybe 2 processes (excluding the without-xdebug-respawn): as I recall only one diagnostic collection process should be spawned per diagnostic provider (e.g. phpactor, psalm php-cs-fxier, phpstan, etc could all spawn one process each) |
Hi. Version:
Yes, my code base is huge, but was also previously. If i understand, it may be linked to a particular file created recently? |
try updating to the lastest master version if you can. there may be 2 issues being discussed in this thread. the one I'd consider this issue to be about is the diagnostics processes eating all the CPUs, anything to do with "size of project" and "indexer" is another issue. |
Can't update to master due to some unclear composer error. Since the last message, in the doubt after your message, I roll all my files into phplint, php-cs-fixer, prettier, and everything is working absolutely alright. In any cases, an error in a file, even a quadruple loop of GOTO, or the size of the codebase or whatever MUST never create that kind of wild loop of process forks. I understand that it require some indexing to work, but again, it was alright previously, without config change |
all of the CPUs? or all of a single CPU? that would be the key difference. Indexing will not use all the CPUs and this issue is about all the CPUs.
I'm talking about Phpactor shelling out to these processes. If your iussue is the same one being discussed initially in this issue it would be mitigated by the previously mentioned |
Setting
|
👍 then need to find out why there is > 1 diagnostic process running at a time. |
What is the implication of not outsourcing (when would be a case when you want it on and visa versa)? Does phpactor no longer report phpstan diagnostics? |
Implications are Phpactor doing it's own (sometimes rather intensive and blocking) diagnostics work in the main process which is also needs cycles for completion and other language server tasks. If it works for you then great, but if it's spawning > 1 process.for this then it's certainly a bug. |
What happens if you turn it off then? Does phpactor no longer have diagnostics? |
I tried phpactor again today (it's been a while), installed through Mason in neovim. It kept spawning php processes that each locked up at 100%ish constantly. If I start neovim in the project root, it seems I only get one php process. If I start it in a dir bit nested into the codebase, I get lots. Also, quitting neovim doesn't kill the process(es) - they're still there hogging CPU! |
There is an assumption on my part that neovim be started the root dir of the project, so I'd always recommend that - however it does seem to work pretty well for me when starting in a sub-dir with Neovim, it does not spawn > 1 process. I am:
Any investigation to pinpoint where the problem happens would be appreciated, as suggested above it's very likely to be a bug with the |
Thanks @dantleech I work on plugins inside a bigger project, where each plugin is its own git repo (for example) but the code only makes sense if you look at the entire project. So in my neovim config I set the workspace dir using a function to find the top of the main project, so it's common for me to start in the plugin's dir as that's what I'm working on. Actually, on more testing, the start dir doesn't seem to make a difference: From plugin root: From whole project root
My mason setup: require('mason-lspconfig').setup_handlers({
default_handler,
phpactor = function()
lspconfig.phpactor.setup({
root_dir = function(startPath)
local rp = (require 'lspconfig.util').root_pattern
for _, pattern in pairs({ ".thisIsDocRoot", ".git", "composer.json" }) do
local found = rp({ pattern })(startPath)
if (found and found ~= '') then return found end
end
return nil
end,
phpactor = {
files = { associations = { "*.php", "*.module", "*.inc" } },
},
})
end
}) (I don't even know if that's the right sort of config structure for phpactor, - the files bit is a straight copy from my intelephense config!) ooh, the longer you leave it, the more it eats! Interestingly, on quitting nvim, most of those were killed off. But one remained, still busying itself at 100% CPU until I manually killed it |
I managed to add the
I could then see:
This did seem to restrict it to one new php process. Again, quitting nvim did not kill that process - I had to |
hmm, so I can get Phpactor to spawn > 1 diagnostic process, so I'll have a look at fixing that. What is curious is why it takes so long: can you run
from the project root and report the time it takes and how many LOC the file has? phpactor analysis is currently very slow, a complex file can take ~2-3 seconds, and (when triggered via. the langauge server) Phpactor SHOULD kill the diagnostics process if it takes > 5 seconds. Which makes me speculate if the diagnostics process isn't getting stuck in a loop and can't even be killed for some reason. The logs should also indicate when Phpactor is killing the process. |
Can we try #2558 (will need |
I get the same as @akabakass However I also get
Although
I also did
to check I had the latest main/master; same result. Then I checked out your PR with:
And ... same result! |
the command is actually
about 2 years ago Phpactor included |
using ~/.local/share/nvim/mason/bin/phpactor worse:analyse index.php
Analysing files...
1 [============================]
index.php
+-------------+----------+---------------------------------------------------------+
| range | severity | message |
+-------------+----------+---------------------------------------------------------+
| 3608:3617 | ERROR | Undefined variable "$language", did you mean one of |
| | | "$language", "$languages" |
| 4306:4326 | ERROR | Undefined variable "$current_category_id", did you mean |
| | | "$current_category_id" |
| 4382:4402 | ERROR | Undefined variable "$current_category_id", did you mean |
| | | "$current_category_id" |
| 7813:7833 | ERROR | Undefined variable "$current_category_id", did you mean |
| | | "$current_category_id" |
| 8849:8869 | ERROR | Undefined variable "$current_category_id", did you mean |
| | | "$current_category_id" |
| 14935:14955 | ERROR | Undefined variable "$current_category_id", did you mean |
| | | "$current_category_id" |
| 16214:16234 | ERROR | Undefined variable "$current_category_id", did you mean |
| | | "$current_category_id" |
| 16536:16556 | ERROR | Undefined variable "$current_category_id", did you mean |
| | | "$current_category_id" |
| 18402:18422 | ERROR | Undefined variable "$current_category_id", did you mean |
| | | "$current_category_id" |
| 19072:19092 | ERROR | Undefined variable "$current_category_id", did you mean |
| | | "$current_category_id" |
| 19461:19481 | ERROR | Undefined variable "$current_category_id", did you mean |
| | | "$current_category_id" |
| 21274:21294 | ERROR | Undefined variable "$current_category_id", did you mean |
| | | "$current_category_id" |
| 22995:23015 | ERROR | Undefined variable "$current_category_id", did you mean |
| | | "$current_category_id" |
| 23164:23184 | ERROR | Undefined variable "$current_category_id", did you mean |
| | | "$current_category_id" |
+-------------+----------+---------------------------------------------------------+
14 problems in 1,388.2017 seconds with 1,032,313,952b memory
|
ok, yup mine didn't complete in 10mins so I stopped it. |
ok, so a couple of things:
of course iit's going to keep spinning up that 5 second process but it should only "eat" 1 CPU at this stage if you're working on 1 file. |
also can you give an indication of the complexity of a file that takes 10 minutes to analyse? how many lines of code? as if it's not that complex then it can be a bug with Phpactor. A real example would be great. |
the index file tested above is not that bad, 549 lines, many includes though |
i suspect it could be includes, could you try removing/commenting this block? phpactor/lib/WorseReflection/Core/ServiceLocator.php Lines 152 to 160 in 3f0d15d
that should remove |
it was way better, but still long: ~/.local/share/nvim/mason/bin/phpactor worse:analyse index.php
Analysing files...
1 [============================]
index.php
+-------------+----------+-------------------------------------------+
| range | severity | message |
+-------------+----------+-------------------------------------------+
| 188:194 | ERROR | Undefined variable "$cPath" |
| 212:218 | ERROR | Undefined variable "$cPath" |
| 324:330 | ERROR | Undefined variable "$cPath" |
| 1013:1033 | ERROR | Undefined variable "$current_category_id" |
| 1359:1379 | ERROR | Undefined variable "$current_category_id" |
| 1762:1774 | ERROR | Undefined variable "$cPath_array" |
| 1812:1824 | ERROR | Undefined variable "$cPath_array" |
| 2237:2246 | ERROR | Undefined variable "$language" |
| 2770:2783 | ERROR | Undefined variable "$request_type" |
| 3608:3617 | ERROR | Undefined variable "$language" |
| 3871:3884 | ERROR | Undefined variable "$messageStack" |
| 3914:3927 | ERROR | Undefined variable "$messageStack" |
| 4306:4326 | ERROR | Undefined variable "$current_category_id" |
| 4382:4402 | ERROR | Undefined variable "$current_category_id" |
| 4456:4469 | ERROR | Undefined variable "$languages_id" |
| 5899:5905 | ERROR | Undefined variable "$cPath" |
| 6031:6037 | ERROR | Undefined variable "$cPath" |
| 6054:6060 | ERROR | Undefined variable "$cPath" |
| 6538:6551 | ERROR | Undefined variable "$languages_id" |
| 7247:7260 | ERROR | Undefined variable "$languages_id" |
| 7813:7833 | ERROR | Undefined variable "$current_category_id" |
| 7943:7956 | ERROR | Undefined variable "$languages_id" |
| 8849:8869 | ERROR | Undefined variable "$current_category_id" |
| 11605:11618 | ERROR | Undefined variable "$languages_id" |
| 12978:12991 | ERROR | Undefined variable "$languages_id" |
| 14265:14278 | ERROR | Undefined variable "$languages_id" |
| 14935:14955 | ERROR | Undefined variable "$current_category_id" |
| 15623:15636 | ERROR | Undefined variable "$languages_id" |
| 16214:16234 | ERROR | Undefined variable "$current_category_id" |
| 16536:16556 | ERROR | Undefined variable "$current_category_id" |
| 18109:18122 | ERROR | Undefined variable "$languages_id" |
| 18402:18422 | ERROR | Undefined variable "$current_category_id" |
| 18456:18469 | ERROR | Undefined variable "$languages_id" |
| 19072:19092 | ERROR | Undefined variable "$current_category_id" |
| 19149:19162 | ERROR | Undefined variable "$languages_id" |
| 19461:19481 | ERROR | Undefined variable "$current_category_id" |
| 20800:20813 | ERROR | Undefined variable "$languages_id" |
| 21274:21294 | ERROR | Undefined variable "$current_category_id" |
| 21881:21887 | ERROR | Undefined variable "$cPath" |
| 22995:23015 | ERROR | Undefined variable "$current_category_id" |
| 23164:23184 | ERROR | Undefined variable "$current_category_id" |
| 24218:24224 | ERROR | Undefined variable "$cPath" |
| 26051:26063 | ERROR | Undefined variable "$customer_id" |
| 26644:26655 | ERROR | Undefined variable "$currencies" |
+-------------+----------+-------------------------------------------+
44 problems in 84.3915 seconds with 259,385,768b memory does that bit of code handle both includes and require? and also the _once versions? |
Yes it does... and tbh I'd be happy to remove it or at least make it opt-in. It would be greatnif you could share/create some code that produces this performance issue. |
our code is oscommerce based (changed a lot since 2006 but the idea is here). here is a similar looking page: |
that file crashes phpactor for me :D
will investigate that. analysing that file on the CLI isn't too bad though:
incidentally disabling the |
ok, it crashed for me initially because Neovim (as per the lsp config was using I git cloned the |
ok, just tried it with the repo cloned, and I get about the same as you, ~5 seconds for specials, and 23 seconds for index.php, which is not that bad. |
yep, 21 seconds for |
Sorry for asking a noob question, but with that 'oursource' option - what does it outsource it to? Is that what php-stan is for? |
As previously hinted at it shifts its own diagnostics work to a separate process to avoid blocking the main process. PHPStan and Psalm also provide diagnostics to Phpactor, but these are always in separate processes. |
* GH-2538: Disable the include walker * Update CL
I've disabled the include walker in #2538 - as it didn't actually seem to work in anycase and I didn't want to burn time on it. I noticed also that we lint as soon as "keys are pressed" - when it would make more sense to start linting after a period of inactivity (e.g. 1 second), the current mechanism is optimistic but quite wasteful, maybe introducing a "i'm still typing" delay would help. |
can you try the following and this changes the behavior to only lint the document after the "user is idle" and should also prevent > 1 document being linted at the same time. with this and the removal of the |
here are the results with #2584 ./phpactor/bin/phpactor worse:analyse index.php
Analysing files...
1 [============================]
index.php
+-------------+----------+-------------------------------------------+
| range | severity | message |
+-------------+----------+-------------------------------------------+
| 188:194 | ERROR | Undefined variable "$cPath" |
| 212:218 | ERROR | Undefined variable "$cPath" |
| 324:330 | ERROR | Undefined variable "$cPath" |
...
+-------------+----------+-------------------------------------------+
44 problems in 149.1917 seconds with 436,416,032b memory |
Is it better? The main thing is that it should not kill all the CPUs and only one CPU should be occupied and it should be significantly faster above due to not processing includes Also not sure how it can take 149 seconds on one file without the include processing. |
I'm closing this now as I hope that Phpactor will no longer nuke all the CPUs and it should be faster now we've disabled the Include walker. Phpactor can be very slow in some files but it should never take 149 seconds on any file! The oscommerce example takes 5 seconds for me on |
Hi,
not sure what's happening, but my cpu burn if I try to use phpactor
this is after less than 1 minute on my file.
I'm using neovim with nvim_cmp and lspconfig. I've installed phpactor through mason and set it up using mason_lspconfig.
here is my setup handler:
nothing fancy here
the scenario to get to the thumbnail is this.
when I open a file, one process pops at 100% on the cpu. I thought of indexing and tried to let it do it's thing with no success. it never leave. when i try to type something, everytime the completion pops up, a new process is created which also uses 100% cpu.
so just typing a few words gets to the situation above.
and even when I quit neovim, all the processes stays here and I have to kill them manually.
Any clues on what is happening?
Tell me if you need anything else to diagnostic this
Cheers
The text was updated successfully, but these errors were encountered: