Description
On Windows, std
calls WSACleanup
at exit if it called WSAStartup
, to uninitialize Windows sockets:
rust/library/std/src/sys/net/connection/socket/windows.rs
Lines 137 to 144 in 15825b7
This is an unnecessary expense--the process is going away, so there's nothing WSACleanup
can do that won't also be done by the kernel when the process terminates. In a short-lived process, the call takes about 60us if you've only used TCP. If you also have used AF_UNIX and AF_HYPERV, for example, it takes about 400us--this is because it has to unload some DLLs that were dynamically loaded. If some of the data is cold, it has the potential to take much longer. None of this is necessary to "cleanly" terminate a process.
Now, arguably, you might want to call WSACleanup
on DLL unload, to ensure you've cleaned everything up. But Rust does not do this today, AFAICT, just as it doesn't drop statics, either on DLL unload or on clean exit from main
. So this WSACleanup
behavior seems inconsistent.
@ChrisDenton wdyt?