[RF] Avoid quadratic copying in CodegenContext::buildArg(std::span<const double>) #24297
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.41) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.41 · 210 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.320
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #24297"
general
weight: 0.35
guitargeek
[RF] Avoid quadratic copying in CodegenContext::buildArg(std::span<const double>)
Changes or fixes:
buildArg()called_xlArr.reserve(_xlArr.size() + n)before appending each array. Reserving exactly the new size defeats the vector's geometric growth, so every call reallocated and copied the whole constants array. The total cost was quadratic in the number of calls and the array size.This shows up for large HistFactory models with codegen, where each sample appends its nominal and variation arrays. For an ATLAS model with ~36 channels, "Function JIT time" grew from 29 s (18 channels) to 35 min (36 channels). A backtrace showed the time spent in memcpy under
vector::reserve()with_xlArrholding 24.6 M doubles (~200 MB), i.e. copying that much on every call.The fix appends with
_xlArr.insert(_xlArr.end(), arr.begin(), arr.end()), without the reserve. The generated code and the contents ofxlArrare unchanged.Assisted-by: claude:claude-opus-5-5. The AI wrote the commits and their messages and I tested them locally.
Checklist:
Timing studies
I studied the time spent in roofit codegen for different numbers of regions in the workspace (the full workspace has 150 regions). I observed that the time for the function JIT time has a strong non-linear scaling.
The timings are plotted in the following figure. The points for fits with 6, 18 and 36 regions are without this fix, the points with 72 and 150 regions are with this fix applied.
<img width="764" height="562" alt="image" src="https://github.com/user-attachments/assets/54a2e497-a2eb-44cb-bb71-9628838c0531" />