Xmx, excludes, and low memory notifications working together
A large Magento monorepo with several hundred modules quickly pushes PhpStorm past its default settings. Deliberately tuning Xmx and Xms, consistently using directory excludes, and correctly reading low memory warnings buys back noticeable responsiveness.
Table of Contents
- 1. Why large Magento monorepos overwhelm the default configuration
- 2. The vmoptions file and how it is structured
- 3. Finding the right heap size for your own monorepo
- 4. Reading low memory notifications correctly
- 5. How heap size and directory excludes work together
- 6. Narrowing down indexing scopes deliberately
- 7. Typical symptoms of a wrong heap configuration
- 8. Using the built-in diagnostic tools
- 9. A recommended fine-tuning workflow for monorepos
- 10. Summary
- 11. FAQ
1. Why large Magento monorepos overwhelm the default configuration
A typical Magento monorepo with the core, several third-party modules, and a growing set of custom extensions quickly reaches several hundred thousand files. PhpStorm indexes PHP classes, XML layouts, Composer autoloading, and JavaScript assets all at once, which in many cases outgrows the default heap size of 2048 megabytes.
The result is noticeable stutter while typing, delayed code completion, and occasional freezes of the entire interface once the garbage collector starts working under memory pressure. These symptoms are often wrongly blamed on disk speed or the Docker environment, even though the real cause lies in the IDE's own JVM heap. What makes this particularly deceptive is that the problems usually only surface after extended work sessions, once more and more files accumulate in memory, so a fresh IDE restart makes the symptoms disappear temporarily and the real cause is easily overlooked.
2. The vmoptions file and how it is structured
PhpStorm itself runs on the Java Virtual Machine and reads its memory limits from a vmoptions file, which can be opened and edited directly from the IDE via Help, Edit Custom VM Options. Importantly, this creates a user-specific file that survives future PhpStorm updates. The original vmoptions file shipped in the installation directory should not be edited directly, since it gets overwritten on every update and any customizations would otherwise be lost without a trace.
The key parameters are -Xms for the initially reserved heap size and -Xmx for the maximum allowed size. A too-low Xms causes the JVM to keep re-reserving memory during work, which causes small pauses of its own, while a too-low Xmx simply is not enough for large monorepos and leads to frequent garbage collection cycles. It is also worth checking -XX:ReservedCodeCacheSize, which separately from the heap limits the memory for the JVM's own compiled JIT code, and can likewise become a bottleneck on very large projects.
# phpstorm64.vmoptions (user-specific)
-Xms1024m
-Xmx4096m
-XX:ReservedCodeCacheSize=512m
-XX:+UseG1GC
-XX:SoftRefLRUPolicyMSPerMB=50
3. Finding the right heap size for your own monorepo
Instead of blindly raising the Xmx value, it is worth checking the built-in Memory Indicator in the status bar, which, once enabled via Settings, Appearance, shows the IDE's current memory usage. Clicking it triggers a manual garbage collection run and reveals how much memory actually stays permanently occupied.
As a rough rule of thumb, very large monorepos benefit from an Xmx between 4096 and 8192 megabytes, depending on the machine's available physical RAM. It matters to leave enough memory for the operating system and other applications, such as the Docker containers of the Magento setup itself, since an Xmx set too high on a machine with only 16 gigabytes of RAM can push the whole system into swapping. On laptops with 32 gigabytes of RAM or more, there is considerably more headroom, and it is worth working upward gradually in 1024-megabyte steps rather than jumping straight to the upper end of the rule of thumb.
4. Reading low memory notifications correctly
PhpStorm automatically shows a Low Memory notification once memory usage gets close to the configured Xmx limit and the garbage collector spends an unusual amount of time cleaning up. This warning is a direct signal that the current heap size is too tight for the open project.
A common mistake is simply dismissing this notification without addressing the underlying cause. It is better to open the vmoptions directly from the notification, raise the Xmx value in 1024-megabyte steps, and restart the IDE afterward to check the effect.
5. How heap size and directory excludes work together
A higher heap size alone does not solve the problem if PhpStorm keeps indexing directories that are irrelevant to actual development work. Vendor directories of third-party packages, generated var folders, and node_modules should consistently be marked as Excluded under Settings, Directories, so they are neither indexed nor kept in the heap.
Especially in Magento monorepos, it pays to permanently exclude the generated folder as well as var/cache, var/log, and var/view_preprocessed, since these directories get refilled on every cache flush and contain no project-relevant source code anyway. Properly configured excludes often reduce memory demand more than raising Xmx alone.
<!-- .idea/[modulename].iml -->
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/src/generated" />
<excludeFolder url="file://$MODULE_DIR$/src/var/cache" />
<excludeFolder url="file://$MODULE_DIR$/src/var/log" />
<excludeFolder url="file://$MODULE_DIR$/src/var/view_preprocessed" />
<excludeFolder url="file://$MODULE_DIR$/src/pub/static" />
</content>
6. Narrowing down indexing scopes deliberately
Beyond full excludes, PhpStorm also supports graded indexing scopes: a directory can be marked as a content root without full-text indexing, so it remains visible for filesystem navigation but does not go through heavy symbol indexing. This suits areas you occasionally need but do not want included in every code completion.
For PHP-specific analysis, the PHP Include Path under Settings, PHP can additionally be narrowed so that only genuinely relevant vendor packages are considered for type inference, instead of the entire vendor directory. This not only reduces memory demand but also noticeably speeds up code completion.
7. Typical symptoms of a wrong heap configuration
A too-low Xmx typically shows up as short but frequent freezes while typing, occurring exactly when a full garbage collection cycle briefly halts the entire IDE. Characteristically, these stalls increase with project size and initially disappear after an IDE restart, only to reappear after a few hours of active work.
An Xmx set too high relative to physical RAM shows up differently: the entire system slows down, not just PhpStorm, because the operating system starts paging memory to disk. This pattern can be told apart from genuine IDE-internal problems via the operating system's system monitor, since other applications also become sluggish in that case.
8. Using the built-in diagnostic tools
Via Help, Diagnostic Tools, Capture Memory Snapshot, a heap dump can be generated during acute memory problems, revealing which internal structures actually occupy the memory. For everyday use, the simpler route via Help, Show Log, combined with the already mentioned Memory Indicator in the status bar, is usually enough.
It is also worth checking Help, Collect Troubleshooting Information, which automatically bundles relevant log files, the current vmoptions configuration, and system information. For recurring problems in a large monorepo, this bundle is the fastest basis for identifying the actual cause instead of just the symptoms.
# Checking current memory status (Help > Show Log for details)
# Status bar shows e.g.: 3421M of 4096M
# Clicking the indicator triggers a manual GC run
9. A recommended fine-tuning workflow for monorepos
The most sensible sequence does not start with heap size, but with consistent excludes for generated directories and vendor code that is not actively edited. Only after that does a moderate Xmx increase follow, in small steps, each followed by an IDE restart and an observation period of at least one full working day.
Anyone who goes through this sequence systematically finds a stable configuration for their specific monorepo that neither wastes memory unnecessarily nor causes too-frequent garbage collection pauses. In practice, the combination of clean excludes and an appropriate Xmx delivers more than simply raising the memory limit.
| Symptom | Likely cause | Action | Expected effect |
|---|---|---|---|
| Short, frequent freezes while typing | Xmx too low for project size | Raise Xmx in 1024 MB steps | Fewer full GC pauses |
| Entire system becomes slow | Xmx too high relative to RAM | Lower Xmx, check the system monitor | No more swapping |
| Long indexing time after opening the project | Missing excludes for generated folders | Exclude generated, var, node_modules | Shorter indexing |
| Sluggish code completion in vendor code | PHP Include Path too broad | Narrow the include path to relevant packages | Faster autocompletion |
Mironsoft
PhpStorm setup, Docker integration, and team productivity
PhpStorm that actually runs optimally for Magento and PHP projects?
We review existing PhpStorm setups for slow indexing, unused Docker integration, and missing team conventions, then set up a configuration that is productive from the first second.
Setup Review
Optimizing indexing, interpreter, and memory settings for large Magento projects.
Docker Integration
Cleanly connecting Xdebug, PHPUnit, and database tools to the Docker setup.
Team Conventions
Standardizing inspection profiles, code style, and live templates project-wide.
10. Summary
Heap Tuning for Magento Monorepos: The Essentials at a Glance
Core tool
Help, Edit Custom VM Options opens the user-specific vmoptions file for Xmx/Xms.
Rule of thumb
Xmx between 4096 and 8192 megabytes for very large monorepos, depending on physical RAM.
Most important addition
Excludes for generated, var, and node_modules often help more than raising Xmx alone.
Diagnosis
The status bar Memory Indicator and Collect Troubleshooting Information for solid analysis.