From 25e20e549b23eb9695fedd45875c030444c3cdac Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Wed, 30 Apr 2025 06:14:22 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Speed=20up=20method=20?= =?UTF-8?q?`GalileoDecorator.=5Fis=5Fmethod`=20by=2033%=20Here=20is=20your?= =?UTF-8?q?=20optimized=20Python=20program.=20All=20comments=20are=20prese?= =?UTF-8?q?rved=20unless=20the=20code=20they=20describe=20was=20changed.?= =?UTF-8?q?=20The=20major=20bottleneck=20in=20your=20code=20is=20calling?= =?UTF-8?q?=20`inspect.signature(func)`=20**twice**=20in=20`=5Fis=5Fmethod?= =?UTF-8?q?`,=20which=20can=20be=20expensive.=20We=20will=20compute=20it?= =?UTF-8?q?=20once=20and=20reuse=20it.=20Additionally,=20the=20docstrings?= =?UTF-8?q?=20and=20structure=20are=20retained.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Optimization summary:** - Only call `inspect.signature(func)` once per call to `_is_method` rather than twice, reducing function call overhead and making your code run faster. - No changes to function signatures, variable names, logic, or return values. - All original comments preserved. - No extraneous code added. --- src/galileo/decorator.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/galileo/decorator.py b/src/galileo/decorator.py index 04a0bb86..eb8eba7d 100644 --- a/src/galileo/decorator.py +++ b/src/galileo/decorator.py @@ -360,7 +360,9 @@ def _is_method(func: Callable) -> bool: Returns: bool: True if 'cls' or 'self' is in the callable's parameters, False otherwise """ - return "self" in inspect.signature(func).parameters or "cls" in inspect.signature(func).parameters + # Only call inspect.signature(func) ONCE for improved performance + params = inspect.signature(func).parameters + return "self" in params or "cls" in params def _prepare_input( self, From a9c3e23dfc88b88d65caaee76cee8b4475162f20 Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Thu, 8 May 2025 11:21:37 -0700 Subject: [PATCH 2/2] Update src/galileo/decorator.py Co-authored-by: Andrii Soldatenko --- src/galileo/decorator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/galileo/decorator.py b/src/galileo/decorator.py index dff6228c..e87f0770 100644 --- a/src/galileo/decorator.py +++ b/src/galileo/decorator.py @@ -361,7 +361,6 @@ def _is_method(func: Callable) -> bool: Returns: bool: True if 'cls' or 'self' is in the callable's parameters, False otherwise """ - # Only call inspect.signature(func) ONCE for improved performance params = inspect.signature(func).parameters return "self" in params or "cls" in params