c++ - 为什么这个 C++ 结构(具有固定长度数组)会导致巨大的编译时间
问题描述
我在静态 c/c++ 库中有这个 c 结构:
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_NUMBER_EXPECTATIONS 2048
struct MIRExpectation
{
uint32_t id;
uint32_t note;
double time;
double duration;
};
typedef struct MIRExpectation MIRExpectation;
struct MIRScheduledExpectation
{
double musicalReferenceTime;
MIRExpectation expectation;
};
typedef struct MIRScheduledExpectation MIRScheduledExpectation;
struct MIRTask
{
MIRScheduledExpectation expectations[MAX_NUMBER_EXPECTATIONS];
};
typedef struct MIRTask MIRTask;
#ifdef __cplusplus
}
#endif
并在链接 c/c++ 库的 swift 应用程序中像这样使用它:
var mirgaTask = MIRTask()
现在,当我快速使用这一行时,这Compile Swift Source Files
一步需要很长时间。
- 它与 的计数几乎成线性关系
MAX_NUMBER_EXPECTATIONS
。1
需要 51 秒。- 在
2048
它需要721秒。
- 所有时间都包括相当大的“周边应用程序”。但是编译时间的差异是可以通过改变一个数组大小来重现的
- 调试构建很好,它的存档步骤需要很长时间,所以我假设它的一些优化在这里需要相当长的时间。
有什么想法吗?快速编译器在做什么?它是否在某种程度上将固定大小的数组快速映射到固定大小的数组?
编译器版本:
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode11.7.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
解决方案
推荐阅读
- python - pygame中没有显示在表面上的图像
- react-native - React Native Text Element - 使用同名导入
- android - 无法用camerakit拍照
- laravel - Laravel 5 - 使用数据库值和旧值预填充 HTML 选择
- java - 使用@IdClass 复合主键时创建查询方法失败
- python - 如何通过 Python OpenCV 单击检测到的边缘?
- linux - 如何在 bash 中存储 32 位小端有符号整数?
- obiee - 如何根据日期获得不同的计数
- java - 在线程调度程序中为等待并通知的线程设置优先级
- wordpress - 使用 nginx 服务容器化的 wordpress