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


##########
superset-frontend/plugins/plugin-chart-table/src/transformProps.ts:
##########
@@ -244,6 +245,9 @@ const processColumns = memoizeOne(function processColumns(
       const config = columnConfig[key] || {};
       // for the purpose of presentation, only numeric values are treated as 
metrics
       // because users can also add things like `MAX(str_col)` as a metric.
+      const isFilterable = columnConfigs.find(
+        c => c.column_name === key,
+      )?.filterable;

Review Comment:
   **Suggestion:** This does a linear search through all datasource columns for 
every result column, creating O(n²) work during prop transformation. With wider 
tables this becomes noticeably expensive; build a one-time lookup map keyed by 
column name and read filterability in O(1). [performance]
   
   <details>
   <summary><b>Severity Level:</b> Minor 🧹</summary>
   
   ```mdx
   - ⚠️ Table chart transformProps does redundant linear searches per column.
   - ⚠️ Render cost grows with columns and metadata size.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open any dashboard or Explore view that uses a Table chart (registered in
   `src/visualizations/presets/MainPreset.ts:24` as `new 
TableChartPlugin().configure({ key:
   VizType.Table })`), e.g. the "video game sales" dashboard mentioned in the 
PR description.
   
   2. `ChartRenderer` (`src/components/Chart/ChartRenderer.tsx:538-548`) renders
   `<SuperChart>` with `vizType={VizType.Table}`, passing the dataset metadata 
as
   `datasource` and query results as `queriesResponse`.
   
   3. `SuperChart` builds `chartProps` and invokes the Table plugin's 
`transformProps`
   function, which calls `processColumns` in
   `plugins/plugin-chart-table/src/transformProps.ts:200-343`. There, 
`colnames` (length N,
   one per result column) and `props.datasource.columns` (length M, one per 
dataset column)
   are read.
   
   4. For each entry in `(colnames || [])` at lines 237-243, `processColumns` 
executes `const
   isFilterable = columnConfigs.find(c => c.column_name === key)?.filterable;` 
at lines
   248-250, performing a linear search over the M datasource columns for each 
of the N result
   columns, yielding O(N*M) work on every Table chart render. With wider tables 
(large N and
   M) and frequent rerenders this adds unnecessary CPU overhead in the 
transform stage,
   though it is unlikely to be a critical bottleneck for typical Superset 
datasets.
   ```
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fplugins%2Fplugin-chart-table%2Fsrc%2FtransformProps.ts%0A%2A%2ALine%3A%2A%2A%20248%3A250%0A%2A%2AComment%3A%2A%2A%0A%09%2APerformance%3A%20This%20does%20a%20linear%20search%20through%20all%20datasource%20columns%20for%20every%20result%20column%2C%20creating%20O%28n%C2%B2%29%20work%20during%20prop%20transformation.%20With%20wider%20tables%20this%20becomes%20noticeably%20expensive%3B%20build%20a%20one-time%20lookup%20map%20keyed%20by%20column%20name%20and%20read%20filterability%20in%20O%281%29.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user
 
%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fplugins%2Fplugin-chart-table%2Fsrc%2FtransformProps.ts%0A%2A%2ALine%3A%2A%2A%20248%3A250%0A%2A%2AComment%3A%2A%2A%0A%09%2APerformance%3A%20This%20does%20a%20linear%20search%20through%20all%20datasource%20columns%20for%20every%20result%20column%2C%20creating%20O%28n%C2%B2%29%20work%20during%20prop%20transformation.%20With%20wider%20tables%20this%20becomes%20noticeably%20expensive%3B%20build%20a%20one-time%20lookup%20map%20keyed%20by%20column%20name%20and%20read%20filterability%20in%20O%281%29.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%
 
20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(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-table/src/transformProps.ts
   **Line:** 248:250
   **Comment:**
        *Performance: This does a linear search through all datasource columns 
for every result column, creating O(n²) work during prop transformation. With 
wider tables this becomes noticeably expensive; build a one-time lookup map 
keyed by column name and read filterability in O(1).
   
   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%2F30827&comment_hash=680a87a7acf64bf7628760f23679fd3f066e3b47067a05c1c094f2f1b41c75da&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F30827&comment_hash=680a87a7acf64bf7628760f23679fd3f066e3b47067a05c1c094f2f1b41c75da&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