Unverified Commit 14bcf93a authored by ZiTian.Zhao's avatar ZiTian.Zhao Committed by GitHub
Browse files

Optimize logger init performance by using module-level constants (#22373)


Signed-off-by: default avatarzitian.zhao <zitian.zhao@tencentmusic.com>
parent ecbea55c
...@@ -102,6 +102,14 @@ class _VllmLogger(Logger): ...@@ -102,6 +102,14 @@ class _VllmLogger(Logger):
_print_warning_once(self, msg, *args) _print_warning_once(self, msg, *args)
# Pre-defined methods mapping to avoid repeated dictionary creation
_METHODS_TO_PATCH = {
"debug_once": _print_debug_once,
"info_once": _print_info_once,
"warning_once": _print_warning_once,
}
def _configure_vllm_root_logger() -> None: def _configure_vllm_root_logger() -> None:
logging_config = dict[str, Any]() logging_config = dict[str, Any]()
...@@ -144,13 +152,7 @@ def init_logger(name: str) -> _VllmLogger: ...@@ -144,13 +152,7 @@ def init_logger(name: str) -> _VllmLogger:
logger = logging.getLogger(name) logger = logging.getLogger(name)
methods_to_patch = { for method_name, method in _METHODS_TO_PATCH.items():
"debug_once": _print_debug_once,
"info_once": _print_info_once,
"warning_once": _print_warning_once,
}
for method_name, method in methods_to_patch.items():
setattr(logger, method_name, MethodType(method, logger)) setattr(logger, method_name, MethodType(method, logger))
return cast(_VllmLogger, logger) return cast(_VllmLogger, logger)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment