When compiling a program with g++ (installed via brew) on MacOS Sequoia (Apple Silicon), the first run in VS Code’s integrated terminal is visibly delayed. In comparison, the same program, when compiled and run within Terminal.app, isn't delayed at all. What could cause such behavior? How to get rid of this delay? The delay time is not consistent (anything from 0.2s to 2s).
g++ abc.cpp -o abc -O2 -Wall -Wextra
time ./abc
Example program:
#include <iostream>
int main() {
std::cout<<"hello"<<std::endl;
return 0;
}
Tried messing around with xattr
and signing the executable, yet to no avail. Expected the delay to disappear.
Also tried doing the same in Iterm and Alacritty. The delay persisted.
Removing the com.apple.provenance
attribute didn’t fix the issue. (Taken from "First execution after compiling is slow in mac" on 'Super User'.)
A window flashes and quickly disappears (a tiny rectangle, with width >>> height and a progress bar). I’d like to have this behavior disabled. I don’t need my OS to scan a program I wrote for safety.
(first run) % time ./abc hello ./abc 0.02s user 0.01s system 10% cpu 0.205 total
(next runs) % time ./abc hello ./abc 0.02s user 0.01s system 89% cpu 0.028 total
In MacOS settings (tested on Sequoia) one can search for "Allow applications to use developer tools". After adding Iterm to this list of apps, I didn't notice any delays when running my executables there for the first time after compilation. Same for VS Code. Hopefully, this answer will be helpful for others. :)