bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.56k stars 92 forks source link

intelephense indexing take too long time #2882

Open AHMED-GAMAL-AG opened 1 month ago

AHMED-GAMAL-AG commented 1 month ago

Describe the bug A clear and concise description of what the bug is.

the intelephense indexing take too long time in VScode when having multiple projects open in the workspace

image

To Reproduce A code snippet (NOT a screenshot of a code snippet) or steps to reproduce the issue

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

image

Platform and version OS and Intelephense version.

Windows 11, Intelephense v1.10.4

phuchip commented 1 month ago

I also have the same problem and I haven't been able to resolve it on my computer

mthrink commented 1 month ago

I had the same situation with laravel. I tried updating Composer and it was fixed. Please give it a try.

archon810 commented 1 month ago

I have the same issue, but only when the project is a remote PHP project via SSH. Local finishes fine on the same code (it's a typical Wordpress site).

In fact, I'm pretty sure it crashes node on the remote server https://github.com/microsoft/vscode/issues/213173.

archon810 commented 1 month ago

VSC closed my ticket above, but maybe @bmewburn could take a look as I posted the crash backtrace there. The process seems to be running out of RAM, perhaps there's a bug somewhere.

stoneC0der commented 3 weeks ago

I had the same situation with laravel. I tried updating Composer and it was fixed. Please give it a try.

I tried this, but still the same

OS: Kali 2024.1 (Gnome 46) Actually I stopped using Vscode because this has been going on for quite long (over 4 months), tought it was system.

ERROR <--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
[Error - 1:43:54 PM] The intelephense server crashed 5 times in the last 3 minutes. The server will not be restarted.
See the output for more information.

UPDATE:

I had two extension crashing: SonarLint & this one

So I look through the settings and saw the setting below Screenshot from 2024-06-08 15-12-13

First I just had 0 after the initial value that is 256MB, so 2560MB The indexing of the project completed without any issue

Then I decrease it again to the initial size 256MB, open another project with laravel/vue

I finally got it to index the project with the value in the screenshot above: 1024MB.

Conclusion, increasing the Max Memory solved the issue for me

archon810 commented 2 weeks ago

My setting for max memory just says 0, which I assume is no limit, yet I still see almost daily crashes.

image

stoneC0der commented 2 weeks ago

I am not sure 0 means unlimited, unless the plugin author can confirm, but it is usually -1 in those case, and description said the minimum should be 256MB, have tried with a higher value? @archon810

archon810 commented 2 weeks ago

Looks like 0 means default node.js max-old-space-size setting, which may be 512MB.

https://github.com/search?q=repo%3Abmewburn%2Fvscode-intelephense+max-old-space-size&type=code https://stackoverflow.com/a/62650303/47680

Not sure how mine ended up being 0, but I've upped it to 16384 and am waiting to see if it'll crash again. It hasn't yet as of right now.

stoneC0der commented 1 week ago

Looks like it, I never had to set a value for it myself, but I started getting those crashes a couple months back after those vscode updates that broke a lot of popular extensions. So I never tried to fix as I was using phpStorm until recently.

However, the snippet below, is clear, unless the memory is at least 256, the extension will always crash, and base on the size of project & file to index, the memory need to be set higher.

    if (memory && memory >= 256) {
       let maxOldSpaceSize = '--max-old-space-size=' + memory.toString();
       serverOptions.run.options = { execArgv: [maxOldSpaceSize] };
       serverOptions.debug.options.execArgv.push(maxOldSpaceSize);
   }

Some of my projects work fine with 256, some with needs 1024, etc.

archon810 commented 1 week ago

16384 was too much for my server, it started running out of memory and other services started crashing. I set it to 2GB and at that point core files started showing up again. The core files are 2GB, whereas with "0" they were 4GB, so I'm deducing from this that the default value for node's max-old-space-size on my server is around 4GB.

So 4GB isn't enough, which is crazy. There has to be a bug somewhere. The message about intelephense syncing never goes away, it always spins. The log file isn't helpful - it just shows some files that are being ignored anyway (like log files) being updated. @bmewburn if you'd like to fix the memory leak, I'd love to help in any way I can.

bmewburn commented 1 week ago

@archon810 do you have symlinks that may cause excess files to be indexed? How big is the workspace. Does opening a smaller workspace cause the same issue?

archon810 commented 1 week ago

@bmewburn The project is a remote ssh dev installation of Wordpress. There are some symlinks, but nothing particularly crazy. There's a node_modules dir for node plugins (as I understand it should be excluded) and another dir with some python files and a localized python env (which I also added to exclude). The rest is PHP, logs (which I excluded by extension), and some binary files (mostly APK files), which intelephense has no business looking at anyway and I assume excludes by default).

There's also a .git dir, and a git pull runs every minute (.git is ignored as I understand) which 99.99% results in no files getting pulled.

A local project (not remote ssh) that is similar but doesn't have as many binary APK files finishes just fine, it's just the remote ssh one that has this issue.

One thing I'm trying to understand after enabling detailed logging is whether seeing workspace/didChangeWatchedFiles is expected for files and dirs that are ignored. Is it actually downloading and looking at these files that it noticed changed or not? Or I guess node runs remotely, so there's nothing to download, but it could be spending time looking at 10GB of log files if there's a bug, I suppose. I'm not seeing anything particularly helpful in the log file that would pinpoint the issue.

I'll drop you an email right now with my contacts in case you want to do a shared debugging session.

Edit: Oh, and another thing I'm not clear on - if I modify the exclude pattern on the User level and add a dir, then add a few more dirs on the project level, do they all get merged into a big list, given that it's a list of dirs/files? Or does one override the other?

bmewburn commented 1 week ago

is whether seeing workspace/didChangeWatchedFiles is expected for files and dirs that are ignored. Is it actually downloading and looking at these files that it noticed changed or not?

All files/dirs get watched but should be ignored when the notification is received if it matches the exclude globs.

if I modify the exclude pattern on the User level and add a dir, then add a few more dirs on the project level, do they all get merged into a big list, given that it's a list of dirs/files? Or does one override the other?

It overrides. There is no merging.

bmewburn commented 1 week ago

@archon810 you could try adding an exclude glob for the symbolic links and see if that helps.

archon810 commented 1 week ago

It overrides. There is no merging.

Oh, wow, that's not what I expected. Alright, I modified the exclude list and confirmed it's what's being used by the extension using its debug output. Unfortunately, it didn't fix the OOM crashes.

@archon810 you could try adding an exclude glob for the symbolic links and see if that helps.

How do you exclude all symbolic links? I'm not sure what the pattern would be here, shouldn't it be an extension setting instead? Or do you mean itemize all of them by name in our specific case? And anyway it wouldn't do anything as all the dirs containing symlinks are already excluded with the exception of several 4 simple symlinked files.

archon810 commented 2 days ago

To see if this also happens to another PHP plugin, I disabled intelephense and enabled PHP DEVSENSE.phptools-vscode https://marketplace.visualstudio.com/items?itemName=DEVSENSE.phptools-vscode.

With this plugin, the plugin detects changes every minute (due to the git pull and composer install running every minute via cron to pull any changes in automatically) and insists there are several thousand files to index, but it does so very quickly, within seconds each time, and the memory usage seems negligible. No OOM crashes over the past few days.

@bmewburn I'd still love to help you figure out the memory leak, please let me know if you're interested and contact me on Telegram, etc.

bmewburn commented 2 days ago

@archon810 , try the 1.11.1 pre-release to see if this fixes your issue. It has some extra debugging in the output tab which may help if there is still an issue. I also recommend clearing your intelephense settings to the defaults to try and narrow the problem down.