matlab-actions / setup-matlab

Set up your GitHub Actions workflow with a specific version of MATLAB.
BSD 3-Clause "New" or "Revised" License
76 stars 10 forks source link

`MEX` is much slower on macOS than on Linux #30

Closed zaikunzhang closed 2 years ago

zaikunzhang commented 2 years ago

Hello!

I did some timing of MEX on macOS and Linux using GitHub Actions. It turns out that MEX is much slower on macOS than on Linux: slow to set up, slow to mexify, and the MEX function is slow to run. In particular, it is about 250 times slower to set up MEX for Fortran on macOS than on Linux.

Below is the data (time in seconds). More details are available at the action. Is this a problem of macOS, the virtual environment of GitHub-hosted runners, Intel oneAPI, or MATLAB? Thank you very much for checking it.

System: GNU/Linux | Language: C | MATLAB: 2021b | Time: 2022.02.26 05:46:36
MEX configured to use 'gcc' for C language compilation.
- Time for setting MEX up: 0.477950 seconds
- Time for mexifying timestwo: 4.500026 seconds
- Time for 100 runs of timestwo: 0.003845 seconds

System: Windows | Language: C | MATLAB: 2021b | Time: 2022.02.26 05:47:56
MEX configured to use 'Microsoft Visual C++ 2019 (C)' for C language compilation.
- Time for setting MEX up: 2.518557 seconds
- Time for mexifying timestwo: 4.416958 seconds
- Time for 100 runs of timestwo: 0.004215 seconds

System: macOS | Language: C | MATLAB: 2021b | Time: 2022.02.26 05:49:01
MEX configured to use 'Xcode with Clang' for C language compilation.
- Time for setting MEX up: 17.602277 seconds
- Time for mexifying timestwo: 5.979585 seconds
- Time for 100 runs of timestwo: 0.130843 seconds

System: GNU/Linux | Language: Fortran | MATLAB: 2021b | Time: 2022.02.26 05:46:20
MEX configured to use 'gfortran' for FORTRAN language compilation.
- Time for setting MEX up: 0.835881 seconds
- Time for mexifying timestwo: 2.768746 seconds
- Time for 100 runs of timestwo: 0.003279 seconds

System: Windows | Language: Fortran | MATLAB: 2021b | Time: 2022.02.26 05:51:04
MEX configured to use 'Intel oneAPI 2021 for Fortran with Microsoft Visual Studio 2019' for FORTRAN language compilation.
- Time for setting MEX up: 1.660305 seconds
- Time for mexifying timestwo: 3.495534 seconds
- Time for 100 runs of timestwo: 0.003299 seconds

System: macOS | Language: Fortran | MATLAB: 2021b | Time: 2022.02.26 05:49:47
MEX configured to use 'Intel Fortran Composer XE' for FORTRAN language compilation.
- Time for setting MEX up: 248.263933 seconds
- Time for mexifying timestwo: 87.093711 seconds

See discussions on MATLAB Answers and StackOverflow.

mcafaro commented 2 years ago

Hi @zaikunzhang,

The approach we use to set up MATLAB on macOS GitHub-hosted runners is generally inferior to the approach we use on Linux (which is why macOS support remains undocumented). macOS also has an increasing number of security protections which can slow first launch and execution of newly installed apps.

I suspect if you ran these benchmarks locally, the results would be more consistent between the platforms.

Best, Mark

zaikunzhang commented 2 years ago

Hello @mcafaro Mark,

Thank you very much for the very quick response and explanation.

I do not have a Mac, so I cannot try the timing locally, but your explanation sounds reasonable.

Would you expect that the performance of MATLAB on macOS (concerning MEX particularly) will improve in the future?

Thank you very much again! Your work of making MATLAB available on GitHub Actions is life-changing for me. I am very grateful for it.

Best regards, Zaikun

mcafaro commented 2 years ago

Hi @zaikunzhang,

I believe the performance of MEX on macOS is comparable to other operating systems outside of GitHub Actions. I do not expect the performance on GitHub Actions to change significantly in the near future. It is something we are looking into for the next major release.

Best, Mark

zaikunzhang commented 2 years ago

Hello @mcafaro ,

Thank you very much for the explanation and updates!

Best regards, Zaikun