mrhhsg commented on code in PR #68258:
URL: https://github.com/apache/doris/pull/68258#discussion_r4056828125
##########
be/src/exprs/function/math.cpp:
##########
@@ -643,6 +643,15 @@ class FunctionMathBinary : public IFunction {
auto& a = column_left_ptr->get_data();
auto& c = column_result->get_data();
size_t size = a.size();
+ if constexpr (std::is_same_v<Impl, PowImpl>) {
+ // Dispatch once per block, keeping libm calls out of the
squaring loop.
+ if (column_right_ptr->template get_value<Impl::type>() == 2.0)
{
Review Comment:
在提交 `e879abb29782aca892d74ef9e41c7d99a3d85030`
中继续完成了性能优化,而不是停留在撤回快路径。此次没有恢复无条件 `x*x`:
- 仅在常量指数 2、FE_TONEAREST 下,对 block 开头满足 `x` 为整数且 `|x| <= 2^26`
的连续前缀使用乘法。这些平方可由 binary64 精确表示。遇到第一个不安全值后,整个后缀保持 libm,并使用 volatile exponent
防止编译器把 fallback 再折叠为乘法。
- 原小数反例 `1.1500729535343723e-17` 保持 libm;还加入整数反例
`94906297`,证明只有“整数”条件也不够,必须限制安全范围。四个别名、全部 const mask、Nullable/Non-Nullable
均按位对比运行时 libm oracle,四种舍入模式均覆盖。
- 在本地 x86_64 RELEASE BE 中穷举了 `[0, 67108864]` 所有整数的正负两种符号,与未修改的
vector-exponent 路径逐行比较;指数交错 2/3 以保留 materialized vector。所有平方行一致,只有预期的立方对照行不同。FE
folding 和其他形态未修改,没有引入新的数值语义或 execution-version 切换;未声称实际运行过混合版本集群或其他架构。
- 实际优化已验证:单 pipeline、关闭 SQL cache,2 次预热 + 7 次测量,2,000 万行整数 POW 的 RELEASE
中位数从 0.560169 s 降至 0.080025 s(约 7.00 倍),接近直接乘法 0.075739 s。非整数、混合输入和指数 3 对照仅约
1–2% 波动,不宣称这些路径得到优化。
验证:52 个 MathFunctionTest 通过,1 个既有 release-only 用例在 ASAN 跳过;ASAN/RELEASE BE
构建,以及两个配置下的 test_pow_square、test_math_function 回归通过;格式、build hygiene、diff
check、changed-line clang-tidy 通过。clang-tidy 使用 PR body 中披露的本地工具兼容处理,未修改无关源码。
关键自审结论:只改共享 PowImpl 的 vector/constant 热路径;结果长度、NULL
包装和所有权不变;没有新增共享状态、生命周期、配置、FE/BE 变量、持久化或事务路径;特殊条件与 fallback
均有边界和负例覆盖。性能提升仅适用于安全整数前缀,不推广到任意 DOUBLE。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]