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


##########
superset-websocket/src/config.ts:
##########
@@ -142,6 +140,40 @@ function applyEnvOverrides(config: ConfigType): ConfigType 
{
 }
 
 export function buildConfig(): ConfigType {
-  const config = _merge(defaultConfig(), configFromFile());
-  return applyEnvOverrides(config);
+  const defaultConfig = getDefaultConfig();
+  const configFromFile = getConfigFromFile();
+  const mergedConfig: ConfigType = {
+    port: configFromFile.port ?? defaultConfig.port,
+    logLevel: configFromFile.logLevel ?? defaultConfig.logLevel,
+    logToFile: configFromFile.logToFile ?? defaultConfig.logToFile,
+    logFilename: configFromFile.logFilename ?? defaultConfig.logFilename,
+    statsd: {
+      host: configFromFile.statsd?.host ?? defaultConfig.statsd.host,
+      port: configFromFile.statsd?.port ?? defaultConfig.statsd.port,
+      globalTags:
+        configFromFile.statsd?.globalTags ?? defaultConfig.statsd.globalTags,
+    },
+    redis: configFromFile.redis ?? defaultConfig.redis,
+    redisStreamPrefix:
+      configFromFile.redisStreamPrefix ?? defaultConfig.redisStreamPrefix,
+    redisStreamReadCount:
+      configFromFile.redisStreamReadCount ?? 
defaultConfig.redisStreamReadCount,
+    redisStreamReadBlockMs:
+      configFromFile.redisStreamReadBlockMs ??
+      defaultConfig.redisStreamReadBlockMs,
+    jwtAlgorithms: configFromFile.jwtAlgorithms ?? defaultConfig.jwtAlgorithms,
+    jwtSecret: configFromFile.jwtSecret ?? defaultConfig.jwtSecret,
+    jwtCookieName: configFromFile.jwtCookieName ?? defaultConfig.jwtCookieName,
+    jwtChannelIdKey:
+      configFromFile.jwtChannelIdKey ?? defaultConfig.jwtChannelIdKey,
+    socketResponseTimeoutMs:
+      configFromFile.socketResponseTimeoutMs ??
+      defaultConfig.socketResponseTimeoutMs,
+    pingSocketsIntervalMs:
+      configFromFile.pingSocketsIntervalMs ??
+      defaultConfig.pingSocketsIntervalMs,
+    gcChannelsIntervalMs:
+      configFromFile.gcChannelsIntervalMs ?? 
defaultConfig.gcChannelsIntervalMs,
+  };
+  return applyEnvOverrides(mergedConfig);
 }

Review Comment:
   ### Memoization Missing for Config Builder <sub>![category 
Performance](https://img.shields.io/badge/Performance-4f46e5)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The configuration is being rebuilt from scratch on every call to 
buildConfig(), including reading from file system and creating new objects.
   
   ###### Why this matters
   Each call creates new objects and performs file I/O operations, which can 
impact performance if called frequently. Configuration values typically don't 
change during runtime.
   
   ###### Suggested change ∙ *Feature Preview*
   Cache the built configuration using memoization to avoid repeated file I/O 
and object creation:
   
   ```typescript
   let memoizedConfig: ConfigType | null = null;
   
   export function buildConfig(): ConfigType {
     if (memoizedConfig !== null) {
       return memoizedConfig;
     }
     
     const defaultConfig = getDefaultConfig();
     const configFromFile = getConfigFromFile();
     memoizedConfig = applyEnvOverrides({
       port: configFromFile.port ?? defaultConfig.port,
       // ... rest of the merging logic
     });
     
     return memoizedConfig;
   }
   ```
   
   
   </details>
   
   <sub>
   
   [![Report a problem with this 
comment](https://img.shields.io/badge/Report%20a%20problem%20with%20this%20comment-gray.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmNWVjMDAiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBjbGFzcz0ibHVjaWRlIGx1Y2lkZS10cmlhbmdsZS1hbGVydCI+PHBhdGggZD0ibTIxLjczIDE4LTgtMTRhMiAyIDAgMCAwLTMuNDggMGwtOCAxNEEyIDIgMCAwIDAgNCAyMWgxNmEyIDIgMCAwIDAgMS43My0zIi8+PHBhdGggZD0iTTEyIDl2NCIvPjxwYXRoIGQ9Ik0xMiAxN2guMDEiLz48L3N2Zz4=)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/a2e8c53d-633f-4a9d-b621-6038f5e2aa54?suggestedFixEnabled=true)
   
   💬 Chat with Korbit by mentioning @korbit-ai.
   </sub>
   
   <!--- korbi internal id:aeb861ed-171d-4073-a428-20b5595b6532 -->
   



-- 
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: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to