HarshMehta112 opened a new issue, #9143:
URL: https://github.com/apache/gravitino/issues/9143

   ### What would you like to be improved?
   
   - orElse(...) eagerly evaluates its argument, meaning the fallback 
expression is computed even when the Optional contains a value.
   - In this method, that causes the lookup and mapping for GRAVITINO_HOME to 
run unnecessarily whenever GRAVITINO_CONF_DIR is set.
   
   - Using orElseGet(...) (or the or(...) API) avoids this by evaluating the 
fallback only when needed, making the code more efficient and idiomatic.
   
   
https://github.com/apache/gravitino/blob/eaba9a23c507e91e116b826332c7df9cf7eddf64/common/src/main/java/org/apache/gravitino/Config.java#L85
   
   ### How should we improve?
   
   Suggested improvement (lazy evaluation)
   ```
   String confDir =
       Optional.ofNullable(System.getenv("GRAVITINO_CONF_DIR"))
           .orElseGet(() ->
               Optional.ofNullable(System.getenv("GRAVITINO_HOME"))
                   .map(s -> s + File.separator + "conf")
                   .orElse(null)
           );
   ```


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

Reply via email to