Analyzing/Indexing/Autocomplete performance issues for LWC & Aura components

Issue #2281 resolved
Irritator created an issue

I have 1000+ LWC components and 300+ aura ones, and I’m facing performance issues while opening any of those components: “analyzing…“ status is hanging in the top right corner.

The activity monitor demonstrates a high CPU load which also discharges the battery. Any tries to go to custom components with Ctrl + click cause an infinite “Resolving reference“ modal to appear. Same with pressing Ctrl+Space for getting autocomplete suggestions.

I can provide logs if needed.

Comments (17)

  1. Scott Wells repo owner

    Typically unending indexing is a sign of one of two things: 1) invalid/corrupted/stale indices; 2) a bug that’s keeping indexing from completing properly. Let’s try to rule out the first possibility. Please use File>Invalidate Caches and then allow the IDE to restart. Once indexing completes, see if the same behavior occurs. If it does, please send me your idea.log for review using Help>Show Log in Explorer/Finder/Files. If that doesn’t show anything useful, I’ll likely have you capture a CPU profiling snapshot, but let’s start with those two steps.

  2. Irritator reporter

    Don’t see anything useful in idea.log. BTW, LightningWebComponentsImportFrameworkIndexingHandler looks suspicious in the thread dump. I’m attaching both idea.log and thread dump.

    Invalidate Caches didn’t help(

  3. Scott Wells repo owner

    Thanks. Let’s go ahead and get a profiling snapshot as well:

    1. Make sure that the Performance Testing plugin is enabled.
    2. Right before you're going to reproduce the performance issue, click Help>Diagnostic Tools>Start CPU Usage Profiling.
    3. Reproduce the issue a few times...enough so that the profiling snapshot has a large enough sample set.
    4. When you feel that you've reproduced it sufficiently, click Help>Diagnostic Tools>Stop CPU Usage Profiling.
    5. In the bottom-right of the IDE window, you'll see a notification like "Captured snapshot. '<snapshot-filename>' is placed in the user home directory." Attach that snapshot for review.

    Hopefully that combined with the diagnostics you’ve already attached will provide sufficient insight into what's going on.

  4. Scott Wells repo owner

    Thanks. I can see some promising information in the provided CPU snapshot. I’m pretty much wrapped up for the week but will dig into this Monday morning. I may post some test builds here with prospective fixes/improvements for you to try (since you’re definitely seeing this behavior) before I commit something for an official build.

  5. Scott Wells repo owner

    Okay, here's a custom build that's effectively the current released build with some prospective LWC optimizations based on the provided CPU profiling snapshot. To install, download the attached archive (don't extract it) and use Settings / Preferences > Plugins > Install plugin from disk (under the gear drop-down menu), then restart the IDE.

    Try to reproduce the behavior with no CPU profiling active first just to see how things look. I'm not just looking for whether things are improved from a perf perspective but also that nothing that worked previously no longer works. I wouldn't expect that as these are pretty straightforward optimizations, but it's good to know whether I've traded off speed for correctness.

    If things aren't performing adequately, please produce another CPU profiling snapshot and attach it so I can see where the time is now being spent. If things aren't behaving properly, please let me know about that as well.

  6. Irritator reporter

    Just tried it out. Indexing works much better now. It still takes a few minutes, but that's at least measurable time. BTW, analyzing hangs only on the first LWC/Aura component opening after IDE restart. You can see a fresh CPU profiling in the attachments. Profiling scenario: open IDE -> enable profiling -> navigate to LWC component -> wait a few minutes for "Analyzing..." in the top right corner to disappear -> switch to other components few times -> stop profiling. After that, I can switch freely between LWC and Aura components without large delays. I don't know how that analysis works under the hood, but maybe it can be cached to store results between different sessions?

  7. Scott Wells repo owner

    Thanks. In the new snapshot pretty much all of the time (~90%) is being spent collecting type information for the declared component properties in its JS file so that they can be incorporated into the custom component definition itself in a strongly-typed manner for braced expressions. That information is already cached aggressively once computed, though as you point out, only for the current session. It might be possible to incorporate that into a file-based index so that it’s available across sessions, though that’s not something that could happen as quickly as some of the other changes. I’ll take a look, but with the pending holidays my guess is that it won’t happen until after the new year. I’ll keep you posted, particularly if I’m wrong and it’s actually something that comes together more quickly.

  8. Scott Wells repo owner

    Okay, the bad news is that a quick and naïve attempt to add a file-based index for LWC custom component attributes hit several major obstacles, the primary one being a direct dependency on the JetBrains IDE's own JavaScript plugin indices to construct the most detailed type information. I think that's going to be a no-go, so some other type of cross-session cache would be needed. I put that on pause because it (somewhat expectedly) became a much larger piece of work.

    However, I have implemented something that might help in the newest attached build. My guess is that it won't make of a difference, though, if any at all. Without going into extreme detail, these new changes allow the IDE to "interrupt" the population of these caches that are taking a long time for you and retry them at another point when things are less busy. It should be doing that already, but sometimes it actually can help significantly to add explicit directions saying "you can cancel at this point if you'd like and retry later".

    Installation instructions are the going to be the same. I'll be curious to hear if it helps at all, and of course if you want to provide a new CPU profiling snapshot for analysis, please feel free to do so.

  9. Irritator reporter

    Thank you so much! I am really happy to see the indexes calculation taking 5 minutes instead of the whole night, so now I can easily wait couple month for patch. Hope, file-based idex is feasible)

  10. Scott Wells repo owner

    Here's a new build based on 2.2.5.0 but with all of the same prospective optimizations integrated since they're not part of the official build yet. That way you can stay on the latest-and-greatest but not lose those optimizations until I get a chance to revisit them.

  11. Scott Wells repo owner

    All prior progress on this has been integrated into the standard build as of 2.2.5.2.

  12. Log in to comment