Skip to content

Commit 14bcf93

Browse files
authored
Optimize logger init performance by using module-level constants (#22373)
Signed-off-by: zitian.zhao <[email protected]>
1 parent ecbea55 commit 14bcf93

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

vllm/logger.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ def warning_once(self, msg: str, *args: Hashable) -> None:
102102
_print_warning_once(self, msg, *args)
103103

104104

105+
# Pre-defined methods mapping to avoid repeated dictionary creation
106+
_METHODS_TO_PATCH = {
107+
"debug_once": _print_debug_once,
108+
"info_once": _print_info_once,
109+
"warning_once": _print_warning_once,
110+
}
111+
112+
105113
def _configure_vllm_root_logger() -> None:
106114
logging_config = dict[str, Any]()
107115

@@ -144,13 +152,7 @@ def init_logger(name: str) -> _VllmLogger:
144152

145153
logger = logging.getLogger(name)
146154

147-
methods_to_patch = {
148-
"debug_once": _print_debug_once,
149-
"info_once": _print_info_once,
150-
"warning_once": _print_warning_once,
151-
}
152-
153-
for method_name, method in methods_to_patch.items():
155+
for method_name, method in _METHODS_TO_PATCH.items():
154156
setattr(logger, method_name, MethodType(method, logger))
155157

156158
return cast(_VllmLogger, logger)

0 commit comments

Comments
 (0)