Defender does the scanning on CloseHandle() calls in untrusted code which can block the thread for even up to ~10ms (including other NTFS filter drivers) which is significant if you do open() close() pairs a lot.
More info about the similar issue and solution is apparently to sign the application [1]
[1] https://github.com/rust-lang/rustup/issues/1540#issuecomment...