From 0c36bff7f06607e84253b0cffccb2c4f367b6ad8 Mon Sep 17 00:00:00 2001 From: Deban Kumar Sahu Date: Sun, 30 Aug 2026 22:00:26 +0530 Subject: [PATCH 1/5] refactor: Added slots=True into dataclasses so they use slots to reduce memory usage --- src/archunitpython/common/types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/archunitpython/common/types.py b/src/archunitpython/common/types.py index 4e1839c..24b51c6 100644 --- a/src/archunitpython/common/types.py +++ b/src/archunitpython/common/types.py @@ -13,7 +13,7 @@ MatchType = Literal["exact", "partial"] -@dataclass(frozen=True) +@dataclass(frozen=True, slots=True) class PatternMatchingOptions: """Options controlling how a pattern is matched against file paths.""" @@ -21,7 +21,7 @@ class PatternMatchingOptions: matching: MatchType = "partial" -@dataclass(frozen=True) +@dataclass(frozen=True, slots=True) class Filter: """A compiled regex filter with matching options.""" From c6f9ff99c8e6d02a520c83cb2c15bca3a3fe8c7e Mon Sep 17 00:00:00 2001 From: Deban Kumar Sahu Date: Sun, 30 Aug 2026 22:02:13 +0530 Subject: [PATCH 2/5] refactor: Made sure LoggingOptions dataclass use slots --- src/archunitpython/common/logging/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/archunitpython/common/logging/types.py b/src/archunitpython/common/logging/types.py index fc0d744..f54eab8 100644 --- a/src/archunitpython/common/logging/types.py +++ b/src/archunitpython/common/logging/types.py @@ -8,7 +8,7 @@ LogLevel = Literal["debug", "info", "warn", "error"] -@dataclass(frozen=True) +@dataclass(frozen=True, slots=True) class LoggingOptions: """Options for controlling logging during architecture checks.""" From f95e5419044d817674f6f4f484b1625fddde4662 Mon Sep 17 00:00:00 2001 From: Deban Kumar Sahu Date: Sun, 30 Aug 2026 22:03:53 +0530 Subject: [PATCH 3/5] refactor: Made sure CheckOptions dataclass use slots --- src/archunitpython/common/fluentapi/checkable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/archunitpython/common/fluentapi/checkable.py b/src/archunitpython/common/fluentapi/checkable.py index 10f216c..ec555fb 100644 --- a/src/archunitpython/common/fluentapi/checkable.py +++ b/src/archunitpython/common/fluentapi/checkable.py @@ -9,7 +9,7 @@ from archunitpython.common.logging.types import LoggingOptions -@dataclass(frozen=True) +@dataclass(frozen=True, slots=True) class CheckOptions: """Options for controlling rule check execution.""" From c100262bfca32fca2ce6987f80df0c2a4b75afb1 Mon Sep 17 00:00:00 2001 From: Deban Kumar Sahu Date: Sun, 30 Aug 2026 22:07:35 +0530 Subject: [PATCH 4/5] refactor: Made sure DeclarationCounts dataclass use slots --- src/archunitpython/common/util/declaration_detector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/archunitpython/common/util/declaration_detector.py b/src/archunitpython/common/util/declaration_detector.py index 7997eeb..d9186fc 100644 --- a/src/archunitpython/common/util/declaration_detector.py +++ b/src/archunitpython/common/util/declaration_detector.py @@ -6,7 +6,7 @@ from dataclasses import dataclass -@dataclass +@dataclass(slots=True) class DeclarationCounts: """Counts of different declaration types in a Python file.""" From 959f81810248c02bc19cfd7128320483228b5b00 Mon Sep 17 00:00:00 2001 From: Deban Kumar Sahu Date: Mon, 31 Aug 2026 11:45:09 +0530 Subject: [PATCH 5/5] perf: Improved the code_declarations function --- .../common/util/declaration_detector.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/archunitpython/common/util/declaration_detector.py b/src/archunitpython/common/util/declaration_detector.py index d9186fc..5d85983 100644 --- a/src/archunitpython/common/util/declaration_detector.py +++ b/src/archunitpython/common/util/declaration_detector.py @@ -88,24 +88,18 @@ def count_declarations(source: str) -> DeclarationCounts: if is_abstract_method(item): counts.abstract_methods += 1 - elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): + for node in tree.body: + if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): # Only count module-level functions - if _is_module_level(node, tree): - counts.total += 1 - counts.functions += 1 - - elif isinstance(node, ast.Assign) and _is_module_level(node, tree): + counts.functions += 1 counts.total += 1 + if isinstance(node, ast.Assign): counts.variables += 1 + counts.total += 1 return counts -def _is_module_level(node: ast.AST, tree: ast.Module) -> bool: - """Check if a node is directly in the module body.""" - return node in tree.body - - def _get_name(node: ast.expr) -> str: """Extract a name from an AST node.""" if isinstance(node, ast.Name):