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

Signed-off-by: zitian.zhao <zitian.zhao@tencentmusic.com>
This commit is contained in:
ZiTian.Zhao 2025-08-07 11:32:19 +08:00 committed by GitHub
parent ecbea55ca2
commit 14bcf93a6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -102,6 +102,14 @@ class _VllmLogger(Logger):
_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:
logging_config = dict[str, Any]()
@ -144,13 +152,7 @@ def init_logger(name: str) -> _VllmLogger:
logger = logging.getLogger(name)
methods_to_patch = {
"debug_once": _print_debug_once,
"info_once": _print_info_once,
"warning_once": _print_warning_once,
}
for method_name, method in methods_to_patch.items():
for method_name, method in _METHODS_TO_PATCH.items():
setattr(logger, method_name, MethodType(method, logger))
return cast(_VllmLogger, logger)