codeant-ai-for-open-source[bot] commented on code in PR #40681:
URL: https://github.com/apache/superset/pull/40681#discussion_r3339814362


##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/transformProps.ts:
##########
@@ -86,8 +86,8 @@ const processComparisonTotals = (
   totals.map((totalRecord: DataRecord) =>
     Object.keys(totalRecord).forEach(key => {
       if (totalRecord[key] !== undefined && !key.includes(comparisonSuffix)) {
-        transformedTotals[`Main ${key}`] =
-          parseInt(transformedTotals[`Main ${key}`]?.toString() || '0', 10) +
+        transformedTotals[`${t('Main')} ${key}`] =
+          parseInt(transformedTotals[`${t('Main')} ${key}`]?.toString() || 
'0', 10) +

Review Comment:
   **Suggestion:** Translation lookup is performed repeatedly inside the totals 
loop for every key and every row, and twice per iteration for the same string, 
which adds avoidable overhead on large result sets. Compute `t('Main')` once 
before iterating and reuse it to avoid repeated i18n calls in a hot path. 
[performance]
   
   <details>
   <summary><b>Severity Level:</b> Minor ๐Ÿงน</summary>
   
   ```mdx
   - โš ๏ธ Minor extra CPU work computing time-comparison totals.
   - โš ๏ธ Overhead limited to totals rows, usually very small.
   - โš ๏ธ No functional impact; only micro-optimization potential.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction โœ… </b></summary>
   
   ```mdx
   1. For Table V2 with aggregation mode and `show_totals` enabled, the 
frontend issues an
   extra totals query via `extraQueries.push({ ...queryObject, columns: [], 
row_limit: 0, ...
   })` in 
`superset-frontend/plugins/plugin-chart-ag-grid-table/src/buildQuery.ts:254-260`.
   The totals response is returned as `totalQuery?.data`.
   
   2. In `transformProps`
   
(`superset-frontend/plugins/plugin-chart-ag-grid-table/src/transformProps.ts:300-305`),
   when `showTotals` is true, `queryMode === QueryMode.Aggregate`, and
   `isUsingTimeComparison` is true, the code computes totals via
   `processComparisonTotals(comparisonSuffix, totalQuery?.data)`.
   
   3. `processComparisonTotals` is defined in the same file at lines 78-109. 
For each row in
   `totals` and each key in that row, it executes the block at lines 86-104. 
Inside this
   loop, `t('Main')` is evaluated twice per key: once to update
   `transformedTotals[`${t('Main')} ${key}`]` (lines 89-91) and again when 
calling
   `calculateDifferences` with `transformedTotals[`${t('Main')} ${key}`]` 
(lines 98-100).
   
   4. On any render where time comparison totals are requested, this 
translation lookup work
   is repeated for each metric key in the totals response. Although the totals 
query is
   typically small (configured via `buildQuery.ts:254-260` with `columns: [], 
row_limit: 0`
   to get overall aggregates, so usually one row), the repeated `t('Main')` 
calls per key are
   unnecessary. Computing `const mainLabel = t('Main');` once before the loop 
and reusing
   `mainLabel` inside lines 89-100 would slightly reduce per-render overhead in 
this
   transformation path.
   ```
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0390c9b4d0644e408bae896a89814d36&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=0390c9b4d0644e408bae896a89814d36&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/plugins/plugin-chart-ag-grid-table/src/transformProps.ts
   **Line:** 89:90
   **Comment:**
        *Performance: Translation lookup is performed repeatedly inside the 
totals loop for every key and every row, and twice per iteration for the same 
string, which adds avoidable overhead on large result sets. Compute `t('Main')` 
once before iterating and reuse it to avoid repeated i18n calls in a hot path.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40681&comment_hash=ef5dd922bcab0447f130d813b2a5fa12e46e8d6b13e5b9b40599ca5e98021649&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40681&comment_hash=ef5dd922bcab0447f130d813b2a5fa12e46e8d6b13e5b9b40599ca5e98021649&reaction=dislike'>๐Ÿ‘Ž</a>



-- 
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]

Reply via email to