C++26 adds standard ways to enumerate a struct's fields, among them static reflection (P2996, with P3394 annotations) and structured-binding packs (P1061), alongside hand-written code, X-macros and libraries (Boost.PFR, reflect-cpp, Glaze) that now ship pre-C++26 and C++26 paths. We time each in a struct serializer with byte-identical output on GCC 16.2.0, at the front end and at -O2, in randomized interleaved rounds with code-level checks of every single-factor contrast. At the front end, inline native enumeration in the form used in several of P2996's own examples, an expansion statement over the std::span of define_static_array, costs about as much per struct of 16 scalar fields as Boost.PFR and 7.96x a P1061 pack, itself about as cheap as hand-written code. The same loop over a constant array costs 0.47x as much: about half of the span form's cost comes with the span. The ratio to P1061 shrinks on a heterogeneous type graph and at -O2. In a whole translation unit at the front end the library outweighs the mechanism: 200 structs take 0.59 s with inline native enumeration, 0.56 s with Boost.PFR and 3.86-4.13 s with the C++26 paths of reflect-cpp and Glaze, whose visitors also compute field names. Per type, each library's C++26 path is cheaper than its pre-C++26 path at 16 fields, but Glaze's gain reverses at 128 fields (pinned release v9.1.0); Boost.PFR's C++17 path grows almost quadratically with the number of types. Hand-written serializers sharing one overloaded name grow superlinearly with the number of types. The -freflection flag alone makes reflection-free code up to 1.264x costlier per type on GCC 16.2.0 and up to 2.578x on 16.1.0, so comparisons between mechanisms depend on the point release. Part of the span form's cost grows with the number of structs, which we trace to GCC registering block-scope statics in quadratic time (reported as GCC PR128928).


翻译:暂无翻译

0
下载
关闭预览

相关内容

GCC(GNU Compiler Collection,GNU 编译器套装),是一套由 GNU 开发的编程语言编译器。
ICML 2026教程:用KET统一Attention与Diffusion
专知会员服务
12+阅读 · 7月10日
基于KG+LLM的联合作战计划智能生成方法
专知会员服务
45+阅读 · 2025年1月9日
【Manning新书】C++并行实战,592页pdf,C++ Concurrency in Action
【2020新书】C++20 特性 第二版,A Problem-Solution Approach
专知会员服务
60+阅读 · 2020年4月26日
【泡泡点云时空】FlowNet3D:学习三维点云中的场景流
泡泡机器人SLAM
41+阅读 · 2019年5月19日
深度学习中Attention Mechanism详细介绍:原理、分类及应用
深度学习与NLP
10+阅读 · 2019年2月18日
Focal Loss for Dense Object Detection
统计学习与视觉计算组
12+阅读 · 2018年3月15日
国家自然科学基金
0+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
最新内容
《评估人机编队性能的标准指标》
专知会员服务
8+阅读 · 11月30日
《美陆军装甲排的自动化任务分配模型》59页
专知会员服务
6+阅读 · 11月30日
乌克兰海陆空无人力量
专知会员服务
3+阅读 · 11月30日
超越技术:美战争部的AI变革管理
专知会员服务
7+阅读 · 11月27日
北约400亿美元反无人机能力投资建设
专知会员服务
7+阅读 · 11月25日
反小型无人机系统方案评估(27页)
专知会员服务
15+阅读 · 11月25日
相关VIP内容
ICML 2026教程:用KET统一Attention与Diffusion
专知会员服务
12+阅读 · 7月10日
基于KG+LLM的联合作战计划智能生成方法
专知会员服务
45+阅读 · 2025年1月9日
【Manning新书】C++并行实战,592页pdf,C++ Concurrency in Action
【2020新书】C++20 特性 第二版,A Problem-Solution Approach
专知会员服务
60+阅读 · 2020年4月26日
相关基金
国家自然科学基金
0+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员