⚡ Optimize const_roll_table::init by removing redundant loop#8
Conversation
Remove redundant std::accumulate call over the weights array, and instead accumulate the sum in the very next loop that iterates over the same array. This saves one complete pass over the data. Co-authored-by: perim <436583+perim@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: Moved the
sumcalculation from a separatestd::accumulatepass into the subsequentfor (int i : weights)loop.🎯 Why: The
weightsarray was being iterated twice in rapid succession. Combining these loops removes a redundant O(N) pass, saving CPU cycles when initializing theconst_roll_table.📊 Measured Improvement: Created a standalone benchmark that initializes a
const_roll_tablewith 5,000 items, 10,000 times.PR created automatically by Jules for task 7655614140059197926 started by @perim