Although my Mac comes with an NVMe drive and 64 Gigabyte of RAM, Eclipse IDE takes quite some time to rebuild projects. Each time I switch between branches, I usually run composer install as well. Thus, I want Eclipse IDE to rebuild my project so that auto-completion and code suggest works.
Looking through some performance tips, many people recommend using a RAM disk. It surprises me, that in 2022, with all the new hardware and technology, new versions of operating systems, a RAM disk is actually a huge performance benefit. The reason for the extra performance is quite simple: although my NVMe drive can read and write about 2.5 GB/s, the RAM (2400 MHz DDR4) delivers 5 GB/s read and write performance and access times are much faster, too.
So what do we need?
- A tiny script that runs a bash script on every login
- A bash script that does all the work: create the RAM disk, install Eclipse and the latest JRE, sync my persistent storage workspace to the volatile RAM disk
- An eclipse.ini with adjusted JRE paths and other performance tweaks
- Some extra privileges for my macOS user
- A cronjob, that syncs the volatile workspace back to the persistent one on my SSD every 5 minutes using rsync
Let’s open up Terminal and start by creating a folder where we can place files that we need for this.
cd ~ mkdir .toolscd .tools
Getting the installers
Now we want to download the full installers for the latest Java JRE and Eclipse. You can download Java from https://adoptium.net/temurin/releases/?version=18 or from https://github.com/adoptium/temurin18-binaries/releases. Download the latest version of the Java JRE pkg installer and save it to your new ~/.tools folder. Alternatively, if you want to stay in Terminal, you can also get the actual download URL with this:
curl -XGET 'https://api.adoptium.net/v3/assets/latest/18/hotspot?os=mac&architecture=x64&image_type=jre&' #intelcurl -XGET 'https://api.adoptium.net/v3/assets/latest/18/hotspot?os=mac&architecture=aarch64&image_type=jre&' #apple arm
In the JSON response look for the installer link, copy the URL and download it, in my case:
curl -O -J 'https://github.com/adoptium/temurin18-binaries/releases/download/jdk-18.0.1%2B10/OpenJDK18U-jre_x64_mac_hotspot_18.0.1_10.pkg'
Now to download Eclipse PDT 2022-06 do one of:
curl -O -J 'https://ftp.linux.org.tr/eclipse//technology/epp/downloads/release/2022-06/R/eclipse-php-2022-06-R-macosx-cocoa-x86_64.dmg' # intelcurl -O -J 'https://ftp.snt.utwente.nl/pub/software/eclipse/technology/epp/downloads/release/2022-06/R/eclipse-php-2022-06-R-macosx-cocoa-aarch64.dmg' #apple arm
Open the Script Editor and paste this line
do shell script "$HOME/.tools/worker.sh"
Click on File > Save… choose the ~/.tools folder as destination, name it worker.app and choose the file format Application.
Now open your System Preferences. Go to Users & GroupsLogin Items tab. Now click + and add the ~/.tools/worker.app.
What this does is run your new app every time you login to your account, the app just executes the bash script.
Save a modified eclipse.ini to the ~/.tools folder.
Note that I added a relative path for the VM, so no JAVA_HOME or PATH needs to be set in your profile.
# Creates RAM Volume - choose sizes 8388608 (4GB), 16777216 (8GB) or 33554432 (16GB) as fits your needsdiskutil erasevolume HFS+ 'Volatile Disk' `hdiutil attach -nobrowse -nomount ram://33554432`# prevent Spotlight from indexing our volatile diskmdutil -i off -d /Volumes/Volatile\ Disk# Install Eclipse PDTmkdir /Volumes/Volatile\ Disk/Applicationshdiutil attach ~/.tools/eclipse-php-2022-06-R-macosx-cocoa-x86_64.dmg cp -r /Volumes/Eclipse/Eclipse.app /Volumes/Volatile\ Disk/Applicationshdiutil detach $(hdiutil info | grep /Volumes/Eclipse | grep -Eo "^(.*?)\t" | grep -m1 "")codesign --force --deep --sign - /Volumes/Volatile\ Disk/Applications/Eclipse.appxattr -d -r com.apple.quarantine /Volumes/Volatile\ Disk/Applications/Eclipse.appchmod +x /Volumes/Volatile\ Disk/Applications/Eclipse.app/Contents/MacOs/eclipsecp ~/.tools/eclipse.ini /Volumes/Volatile\ Disk/Applications/Eclipse.app/Contents/Eclipse# Install latest JRE 18sudo /usr/sbin/installer -pkg ~/.tools/OpenJDK18U-jre_x64_mac_hotspot_18.0.1_10.pkg -target /Volumes/Volatile\ Disk/# Set up workspacecp -r ~/workspace /Volumes/Volatile\ Diskchown -R $(whoami):staff /Volumes/Volatile\ Disk/workspace# (optional) add workspace to valetcd /Volumes/Volatile\ Disk/workspace && sudo $(which valet) park
Let’s go over this file briefly. We create the RAM disk, then mount the Eclipse installer, we copy Eclipse over to the RAM disk and unmount the installer volume afterwards.
With codesign, xattr and chmod we make sure the App can be launched. We copy our
eclipse.ini to its location inside the App.
Once that is done, we install the Java 18 JRE package onto the RAM disk. Now we copy the entire workspace (you might want to adjust this path) from the SSD over to the RAM disk. Keep in mind, that your workspace needs to fit into the RAM disk. If it doesn’t, you can either increase the size of the RAM disk or remove projects you no longer work on.
codesign will require an admin password. In order to run this without user interaction, we will edit the sudoers file. This is done with
sudo visudo. After the line starting with %admin, add a new one and replace
<user> with your actual username.
sudo visudo to open the sudoers file with the default editor (likely to be vim), or with
EDITOR=nano sudo visudo to open it with nano.
<user> ALL = (ALL) NOPASSWD: /usr/sbin/installer,/usr/sbin/codesign,/usr/local/bin/valet
A Cronjob to sync Workspaces
In order not to loose any data, it’s important to frequently sync your workspace from the volatile RAM disk back to your permanent storage, most likely an internal SSD.
For this we will copy and paste the following line into the crontab file.
*/5 * * * * rsync -r -l -a --safe-links /Volumes/Volatile\ Disk/workspace/* ~/workspace
The rsync will run every 5 minutes. The -l parameter makes sure symlinks are respected. The -a parameter instructs rsync to set modification timestamps once, so that subsequent are incremental. Only files that have been modified will be copied, which speeds this up a lot.
This is it. Restart your Mac and some 30 seconds after you log your should be able to open Eclipse from your Volatile Disk > Applications folder, at full RAM speeds. For me, Eclipse starts in 3 seconds now, which was about 10 seconds before. Complete workspace and project builds now finish in 20-40 seconds. For projects with large codebase, this previously took several minutes.
Another tip, I haven’t seen anywhere else ist to exclude your permanent and volatile workspace folders from Spotlight, so that changes to your projects don’t trigger the Spotlight indexer, which consumes quite some CPU. Go to System Preferences > Spotlight > Open the Privacy tab and add your workspace folders.
We now have Java and Eclipse installed on the RAM disk. The workspace is also on the RAM disk. All of this is setup automatically when you login. A cronjob copies your workspace to your SSD in the background.
Neither Eclipse nor any Java JDK or JRE needs to be installed onto your SSD.