mathworks-ref-arch / matlab-dockerfile

Create a docker container that contains a MATLAB install
Other
335 stars 96 forks source link

mpm is quite slow on macOS (when used interactively) #114

Open versionbayjc opened 2 months ago

versionbayjc commented 2 months ago

I believe macOS does some time consuming scanning of binaries when first running them, which makes using mpm interactively on macOS quite slow.

Running mpm a second time is just as slow as the first: on my Intel Core i7 Mac Mini (2018) it takes >40s to run mpm on macOS Sonoma (14.5), even to get the version number or the help text. I think this is because every time you run mpm, it will extract to a temp dir and then run it from there and then it removes its extracted self. And as such the XProtectService is rechecking the mpm application every time again. You could argue, there should be a more efficient way to this by macOS, but I also don't think it makes that much sense for a CLI to always extract itself and remove itself after every invocation.

❯ time ./mpm --version
MATLAB Package Manager 2024.2.1 (maci64)
./mpm --version  2.12s user 2.56s system 10% cpu 44.035 total
❯ time ./mpm --version
MATLAB Package Manager 2024.2.1 (maci64)
./mpm --version  2.10s user 2.43s system 10% cpu 42.043 total

If I copy the folder that mpm created in my temp dir (while XProtectService is scanning it) and run it from there, the second time is much faster:

❯ time ./mpmCOPY/bin/maci64/mpm --version
MATLAB Package Manager 2024.2.1 (maci64)
./mpmCOPY/bin/maci64/mpm --version  0.62s user 0.03s system 61% cpu 1.060 total

One idea I had, could mpm (also!) be distributed in a different way for macOS, such that the installation takes care of extraction and as such that only when first time running, it will be scanned?

My first thought would be to use homebrew for macOS, but maybe another package manager that is cross platform would also be useful for Windows and/or Linux?

It may sound a bit weird, to use a package manager to install another package manager, and it doesn't seem very useful in the case of CI pipelines, but for troubleshooting and interactive use cases, a 40s delay for a CLI is somewhat frustrating. And if mpm can be installed via another package manager, it can then also keep mpm up to date by checking all outdated packages installed by that package manager.