korbit-ai[bot] commented on code in PR #35886:
URL: https://github.com/apache/superset/pull/35886#discussion_r2479024832


##########
superset-frontend/src/dashboard/reducers/nativeFilters.ts:
##########
@@ -69,7 +69,13 @@ function handleFilterChangesComplete(
 ) {
   const modifiedFilters = { ...state.filters };
   filters.forEach(filter => {
-    modifiedFilters[filter.id] = filter;
+    const existingFilter = modifiedFilters[filter.id];
+
+    modifiedFilters[filter.id] = {
+      ...filter,
+      chartsInScope: filter.chartsInScope ?? existingFilter?.chartsInScope,
+      tabsInScope: filter.tabsInScope ?? existingFilter?.tabsInScope,
+    };
   });

Review Comment:
   ### Unnecessary object operations in filter loop <sub>![category 
Performance](https://img.shields.io/badge/Performance-4f46e5)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The code performs unnecessary object spreading and property access for every 
filter in the loop, even when the fallback values are not needed.
   
   
   ###### Why this matters
   This creates performance overhead when processing large numbers of filters, 
as it spreads the entire filter object and accesses existingFilter properties 
unconditionally, regardless of whether the nullish coalescing operator will 
actually use the fallback values.
   
   ###### Suggested change ∙ *Feature Preview*
   Only perform the expensive operations when the fallback values are actually 
needed:
   
   ```typescript
   filters.forEach(filter => {
     if (filter.chartsInScope != null && filter.tabsInScope != null) {
       modifiedFilters[filter.id] = filter;
     } else {
       const existingFilter = modifiedFilters[filter.id];
       modifiedFilters[filter.id] = {
         ...filter,
         chartsInScope: filter.chartsInScope ?? existingFilter?.chartsInScope,
         tabsInScope: filter.tabsInScope ?? existingFilter?.tabsInScope,
       };
     }
   });
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice 
Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/957b030e-39eb-448a-af33-e12bf3a97e76/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/957b030e-39eb-448a-af33-e12bf3a97e76?what_not_true=true)
  [![Not in 
Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/957b030e-39eb-448a-af33-e12bf3a97e76?what_out_of_scope=true)
 [![Not in coding 
standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/957b030e-39eb-448a-af33-e12bf3a97e76?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/957b030e-39eb-448a-af33-e12bf3a97e76)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:9141be94-31fd-441e-ac74-ed0d668ec466 -->
   
   
   [](9141be94-31fd-441e-ac74-ed0d668ec466)



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