为什么 MinGW 很慢?

发布于 2024-07-22 19:19:10 字数 296 浏览 6 评论 0原文

我正在 Windows 上使用带有 GCC/MinGW 的 Code::Blocks IDE,并且我正在尝试构建一个具有 ca 的 wxWidgets 应用程序。 20k 行和 40 个源模块。 而且它的构建速度非常非常慢。

编译一个C++模块需要2-5秒,链接甚至需要2-3分钟。

它是可移植的代码,并且该代码在 Linux 上编译得非常快。 我无法跟踪构建消息窗口...整个过程持续不到 20 秒。

我尝试了常见的调整(例如,预编译头、关闭优化等),但没有任何效果。

为什么这么慢?

I'm using the Code::Blocks IDE with GCC/MinGW on Windows, and I'm trying to build a wxWidgets application which has ca. 20k lines and 40 source modules. And it builds very very slow.

Compiling a C++ module lasts 2-5 seconds, and linking lasts even 2-3 minutes.

It's a portable code, and this code compiles very fast on Linux. I can't follow the build message window... The entire process lasts less than 20 seconds.

I tried the common tweaks (for example, precompiled header, turn optimizations off, etc.), but nothing worked.

Why is it so slow?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

囍孤女 2024-07-29 19:19:10

MinGW 上的许多“unixy”东西都慢得令人痛苦,因为 Windows 没有 fork()。 Windows只有CreateProcess(),这是完全不同的。 Unix shell 和 GNU Make 进行了大量的分叉,因此在 MinGW 下运行这些会导致“模拟”分叉,这非常慢。

另一个受此困扰的是 GNU Autotools,因此在从源代码构建“unixy”应用程序时运行 ./configure 脚本也非常慢。 如果您需要多次执行此操作(例如在配置配置以查找所有库时遇到困难),这可能会变得非常烦人。

这个答案更详细地解释了 Cygwin 和 MinGW 如何用来模拟 fork(),并且这个答案有更多最新的解释。

Many "unixy" things on MinGW are painfully slow, because Windows has no fork(). Windows only has CreateProcess(), which is quite different. Unix shells and GNU Make do a lot of forking, so running these under MinGW results in "emulated" forks, which are really slow.

Another thing which suffers from this is GNU Autotools, so running ./configure scripts when building "unixy" applications from sources is also very slow. This can get really annoying if you need to do it many times (for example when having troubles with with getting configure to find all the libraries).

This answer explains in more detail how Cygwin and MinGW used to simulate fork(), and this answer has more up to date explanation.

决绝 2024-07-29 19:19:10

您可以尝试使用该工具集的更新版本。 我发现这很有用:
http://nuwen.net/mingw.html
它在一个大包中包含 MinGW 使用的所有工具和通用 API。
从网站:

我的 MinGW 发行版(“发行版”)是 x64 原生的,当前包含
GCC 6.1.0 和 Boost 1.61.0。

MinGW 是 GCC 到 Windows 的端口。 它是免费且简单的
使用(嗯,就像工具链一样简单)。 它产生独立的
可以以任何方式分发的 Windows 可执行文件。

You can try to use a more recent version of the toolset. I found this to be useful:
http://nuwen.net/mingw.html
It has all the tools used by MinGW and common APIs in a single big package.
From the site:

My MinGW distribution ("distro") is x64-native and currently contains
GCC 6.1.0 and Boost 1.61.0.

MinGW is a port of GCC to Windows. It is free of charge and simple to
use (well, as simple as toolchains ever get). It produces standalone
Windows executables which may be distributed in any manner.

痴者 2024-07-29 19:19:10

您是否位于 Active Directory 域中,但未立即连接到该域?

虽然我不知道为什么 MinGW 会很慢,但根据我的经验,属于 AD 域但无法到达 AD 控制器的计算机在启动可执行文件时会出现延迟(例如rxvt.exe)和当前正在运行的程序会遇到暂停或卡顿(例如使用 MinGW 构建的 emacs)。

我仍在调查以确定此行为的实际原因,但我想我会提及它,以防它适用于您。

Are you on an Active Directory domain, but not immediately connected to it?

While I don't have the "answer" as to why MinGW would be slow, it has been my experience that computers which belong to an AD domain, but are unable to reach the AD controller, have a delay in starting executables (such as rxvt.exe) and currently running ones experience a pause or stutter (such as emacs, which is built using MinGW).

I am still investigating to determine the actual cause of this behavior, but thought I would mention it in case it applies to you.

缱绻入梦 2024-07-29 19:19:10

MSYS 1.0.19-1 开始,如果用户帐户位于 Active Directory 域中并且无法访问域控制器 (DC),则 MSYS DLL 将引入较长的延迟在启动任何 MSYS 可执行文件(使用 MSYS DLL)之前。 这会影响 MSYS make 以及 CoreUtils 包中的所有命令行实用程序,例如通常安装在 C 中的 ls 、 rm 等:\MinGW\msys\1.0\bin。

观察结果:

  • 当从 MSYS bash shell 启动实用程序时,只有 shell 的启动受到延迟影响。 从 shell 启动的实用程序不会受到影响。

  • 延迟可能会有所不同,在我的例子中为 21 秒。

  • 在延迟命令后 10-20 秒内运行任何 MSYS 实用程序都将启动,而不会出现新的延迟。
  • 当计算机连接到不同的网络时,或者与域断开连接时,或者当域控制器主机名更改时(我的情况下出现问题)时,就会出现问题。 要检查 DC 是否可达,请打开 cmd 并输入 echo %LOGONSERVER%,然后使用 pingnet view DC 的主机名。

为什么这么慢:

  • uinfo.ccInternal_getlogin()MSYS DLL的代码进行了两次系统调用来获取用户信息。 第一次调用 NetUserGetInfo() 从本地计算机检索用户帐户。 它对于域用户失败,因此它使用从 LOGONSERVER 变量获取的 DC 服务器第二次调用它。 如果不能立即访问该主机,则会引入很长的延迟,直到调用超时失败。 该应用程序将很快开始。

如何避免此问题,有几种解决方法:

  • 从 MSYS shell 运行所有内容,或者
  • 如果原因是 DC 主机名发生更改,则重新启动或重新登录将解决该问题。 Windows 将自动使用正确的 DC 主机更新 LOGONSERVER
  • 如果从 Windows cmd 或脚本调用 MSYS 工具,请将 LOGONSERVER 设置为本地主机以避免网络访问。 例如 set LOGONSERVER=\\LOCALHOST 对我有用。 注意:此变量是在登录时设置的,与在 cmd 或脚本中设置相比,在 Windows 环境变量窗口中全局更改它没有效果。
  • 我认为这是 MinGW/MSYS 中的一个错误。 MSYS2和Cygwin中的代码是不同的。 我检查了MSYS2,没有这样的问题。

As of MSYS 1.0.19-1, if the user account is in Active Directory domain and the Domain Controller (DC) is unreachable, then MSYS DLL will introduce a long delay before starting any MSYS executable (that uses MSYS DLL). This affects MSYS make and all the command-line utilities from CoreUtils package such as ls, rm etc that are typically installed in C:\MinGW\msys\1.0\bin.

Observations:

  • When launching utilities from MSYS bash shell, only the shell's startup is hit by the delay. Utilities launched from the shell are not impact.

  • The delay can vary, in my case it is 21sec.

  • Running any MSYS utility within 10-20sec after the delayed command will launch without a new delay.
  • Problem occurs when the machine is connected to a different network, or when disconnected from its domain, or when Domain Controller hostname changes (problem in my case). To check if DC is reachable, open cmd and type echo %LOGONSERVER%, then ping or net view with the host name of the DC.

Why is it so slow:

  • The code of MSYS DLL in uinfo.cc internal_getlogin() makes two system calls to get user information. First time it calls NetUserGetInfo() to retrive the user account from the local machine. It fails for domain users, so it calls it second time with the DC server taken from LOGONSERVER variable. If this host is not immediately accessible, it will introduce a long delay until the call fails on timeout. The application will start shortly after.

How to avoid this problem, several workarounds:

  • Either run everything from MSYS shell, or
  • If the reason is the change in DC hostname, then a restart or re-login will resolve the issue. Windows will automatically update LOGONSERVER with the correct DC host.
  • If MSYS tools are called from Windows cmd or a script, then set LOGONSERVER to a localhost to avoid network access. E.g. set LOGONSERVER=\\LOCALHOST worked for me. Note: this variable is set at logon and changing it globally in Windows Environment Variables window has no effect compared to setting it in cmd or a script.
  • I consider this a bug in MinGW/MSYS. The code in MSYS2 and Cygwin is different. I checked MSYS2 and it has no such issue.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文