Skip to content
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

[PHP] UI freeze for over 2 minutes when attempting to use "Fix Imports" #6039

Closed
czukowski opened this issue Jun 5, 2023 · 10 comments · Fixed by #6237
Closed

[PHP] UI freeze for over 2 minutes when attempting to use "Fix Imports" #6039

czukowski opened this issue Jun 5, 2023 · 10 comments · Fixed by #6237
Assignees
Labels
kind:bug Bug report or fix PHP [ci] enable extra PHP tests (php/php.editor) Regression This used to work!
Milestone

Comments

@czukowski
Copy link
Contributor

Apache NetBeans version

Apache NetBeans 18

What happened

Right after invoking "Fix Imports" (Ctrl+Shift+I), the whole UI freezes for a prolonged period of time. During all that time a whole CPU core is at 100% use by the IDE. Eventually the dialog appears with the suggestions, the UI unfreezes and can be used again. Repeated use freeze the UI for about the same time.

I work on a fairly large project, it does take a toll on the overall IDE performance, but the same action in NetBeans 17 usually took at most a couple of seconds.

How to reproduce

Just invoke "Fix Imports" (Ctrl+Shift+I)

Did this work correctly in an earlier version?

Apache NetBeans 17

Operating System

Windows 10

JDK

18.0.2.1; OpenJDK 64-Bit Server VM 18.0.2.1+1-1

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

It's a fresh NetBeans install, user and cache directories just finished initializing.

Release notes for NetBeans 18 mentions several changes to Fix Imports function, perhaps one of them is causing a performance issue.

According to Process Explorer, memory usage remained stable, also no significant I/O access occurred for the duration.

I've taken an IDE profiling snapshot in case it helps, where may I upload it?

Are you willing to submit a pull request?

No

@czukowski czukowski added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Jun 5, 2023
@junichi11 junichi11 added the PHP [ci] enable extra PHP tests (php/php.editor) label Jun 9, 2023
@junichi11
Copy link
Member

@czukowski Could you provide an example code to reproduce it?

@junichi11 junichi11 removed the needs:triage Requires attention from one of the committers label Jun 9, 2023
@czukowski
Copy link
Contributor Author

czukowski commented Jun 12, 2023

@junichi11 it happens with any PHP file from my project, no matter how big or small. Unfortunately I cannot share the project because of an NDA. I am currently trying to see if I can reproduce the same issue with any kind of large open source project.

As a side note, in the mean time I tried to examine IDE with Process Monitor and I noticed a few unexpected things that might affect performance, however it is probably unrelated to this specific issue, unless there were some changes affecting these parts since NB 17:

  • When scanning sources, NetBeans frequently scans directories that belong to other projects, even those that are no longer open. It also scans directories that are specifically marked as ignored in project properties. In my project, some of these ignored directories contain many thousands of PHPStan cache files that are in PHP format. I can't tell whether NetBeans ends up parsing these files or not, if it does, then it could be a big performance hit.
  • It reads cache files from NetBeans cache directory (eg. *.fdt) by 1024 bytes while some of these are large up to 100 MB. Depending on the implementation, the buffer size may or may not make a difference.
  • There are frequent requests for NotifyChangeDirectory on a root drive C:\ that might cause NetBeans to receive more file system notifications than it needs.

@junichi11 junichi11 added the Regression This used to work! label Jul 4, 2023
@junichi11
Copy link
Member

I've reverted changes related to "Fix Imports" once, then I've fixed some issues without complicated changes again.
So, I hope that this regression is resolved in NB19.

Please give it a try when NB19-rc is released if possible.

@czukowski
Copy link
Contributor Author

Thanks @junichi11

I've tried to reproduce the issue with the largest open source PHP based project I know (Magento) but I wasn't able to reach similar results. I was able to partially mitigate the issue in NB18 by adding most of the vendor folder to Ignored directories, to the point that "Fix Imports" is usable again.

I'll post an update when NB19 is out, however I fear that the main cause of the issue is the operating system and its notoriously slow (or so they say) file system, multiplied by the project size and amount of data to parse and changes to "Fix Imports" only helped to manifest that more. Perhaps there is a space for some optimizations in that field, but it seems like a lot of work and definitely outside of the scope of this issue.

@czukowski
Copy link
Contributor Author

I've tried "Fix Imports" with NB19-r1 after removing vendor from Ignored directories and waiting for indices to update. I can't seem to get consistent results. Files of similar lengths and code structure seem to behave quite differently, with "Fix Imports" working almost instantly or within reasonable time for some files and with freezes for other, however result seems to be consistent for a specific given file.

Just as with NB18, the "Lengthy operation in progress" message did not appear and restarting the IDE didn't help it either.

I tried the same files with NB18 again and I discovered the same kind of consistency, that some files appear to be "better" than others, but overall NB19-r1 is seemingly a little better than NB18.

In comparison, with NB17 "Fix Imports" works instantly on all of the same set of files. I've only tried files with up to 500 lines and up to 50 use statements (50 was maximum, on average maybe just about 10).

In all cases I waited for the initial "Background Scanning" to finish to make sure it didn't interfere.

I'll post an update if I figure out anything else. Thanks again for looking into it!

@czukowski
Copy link
Contributor Author

@junichi11 I think I'm onto something. The issue seems to be related to doc-comments parser. It suffices to add a @return comment with a 'generic type' syntax to freeze "Fix Imports" function, for example: @return array<int, Whatever>. However, the project size must be large enough so that it has to check many classes.

I used Magento for testing. The steps to reproduce are to clone its repo, initialize Composer dependencies and then beef it up some more by adding additional dependencies known to be rather large (I could tell a difference even without additional dependencies but it wasn't so severe):

git clone https://github.com/magento/magento2.git .

composer install

composer require aws/aws-php-sns-message-validator:* facebook/graph-sdk:* facebook/php-business-sdk:* google/apiclient:* nikic/php-parser:* phing/phing:* php-coord/php-coord:* phpoffice/phpspreadsheet:*

I searched for a function that returned array and the first file I found was app/code/Magento/ReleaseNotification/Model/ResourceModel/Viewer/Logger.php and its method loadLatestLogData. It is probably not very important which file or function to use though. At this point, fixing imports worked as it should, even if I tried edits resulting in new use statements being added. I found the following edits to cause the freezes:

  • @return array<int, Whatever>
  • @return array<int>
  • @return list<int>
  • @return Whatever<int>
  • @return Whatever<max>
  • etc

But not this:

  • @return int<0, 100>
  • @return int<0, max>
  • @return array{int, int}

@junichi11
Copy link
Member

@czukowski Thanks for investigating it. I'll try it later.

@junichi11 junichi11 self-assigned this Jul 20, 2023
@junichi11 junichi11 added this to the NB19 milestone Jul 20, 2023
junichi11 added a commit to junichi11/netbeans that referenced this issue Jul 20, 2023
- apache#6039
- Remove `<>` and `{}` from type name
- Ignore an empty type name to avoid getting all types
- Add unit tests
@junichi11 junichi11 linked a pull request Jul 21, 2023 that will close this issue
@junichi11
Copy link
Member

Your information was helpful. Thanks.

neilcsmith-net added a commit that referenced this issue Jul 21, 2023
Avoid getting all types with an empty type name #6039
@junichi11
Copy link
Member

Please give it a try when NB19-rc2 is released.

@czukowski
Copy link
Contributor Author

Confirmed as fixed in rc3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Bug report or fix PHP [ci] enable extra PHP tests (php/php.editor) Regression This used to work!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants