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></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>
[](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: [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]