From e317414ce11a66f6e653ce382f5d987b0c0191bd Mon Sep 17 00:00:00 2001 From: Bram Wasti Date: Fri, 10 Oct 2025 15:47:34 -0700 Subject: [PATCH] Cache the environment variable check for batch invariance (#26510) Signed-off-by: Bram Wasti --- csrc/core/batch_invariant.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/csrc/core/batch_invariant.hpp b/csrc/core/batch_invariant.hpp index 19e422e4b80cd..e769e1a25ac0e 100644 --- a/csrc/core/batch_invariant.hpp +++ b/csrc/core/batch_invariant.hpp @@ -8,9 +8,12 @@ namespace vllm { // vllm_kernel_override_batch_invariant(); returns true // if env VLLM_KERNEL_OVERRIDE_BATCH_INVARIANT=1 inline bool vllm_kernel_override_batch_invariant() { - std::string env_key = "VLLM_KERNEL_OVERRIDE_BATCH_INVARIANT"; - const char* val = std::getenv(env_key.c_str()); - return (val && std::atoi(val) != 0) ? 1 : 0; + static bool cached = []() { + std::string env_key = "VLLM_KERNEL_OVERRIDE_BATCH_INVARIANT"; + const char* val = std::getenv(env_key.c_str()); + return (val && std::atoi(val) != 0) ? 1 : 0; + }(); + return cached; } } // namespace vllm