Skip to content

Commit adc4122

Browse files
authored
Implement Lazy Graph Compute Mode (#652)
# Motivation <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [ ] I have added tests for my changes - [ ] I have updated the documentation or added new documentation as needed
1 parent f5565e6 commit adc4122

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/codegen/configs/models/codebase.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def __init__(self, prefix: str = "CODEBASE", *args, **kwargs) -> None:
1616
ignore_process_errors: bool = True
1717
disable_graph: bool = False
1818
disable_file_parse: bool = False
19+
exp_lazy_graph: bool = False
1920
generics: bool = True
2021
import_resolution_paths: list[str] = Field(default_factory=lambda: [])
2122
import_resolution_overrides: dict[str, str] = Field(default_factory=lambda: {})

src/codegen/sdk/codebase/codebase_context.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ def __init__(
144144
from codegen.sdk.core.parser import Parser
145145

146146
self.progress = progress or StubProgress()
147-
self._graph = PyDiGraph()
147+
self.__graph = PyDiGraph()
148+
self.__graph_ready = False
148149
self.filepath_idx = {}
149150
self._ext_module_idx = {}
150151
self.generation = 0
@@ -189,7 +190,8 @@ def __init__(
189190
logger.warning("Some features may not work as expected. Advanced static analysis will be disabled but simple file IO will still work.")
190191

191192
# Build the graph
192-
self.build_graph(context.repo_operator)
193+
if not self.config.exp_lazy_graph:
194+
self.build_graph(context.repo_operator)
193195
try:
194196
self.synced_commit = context.repo_operator.head_commit
195197
except ValueError as e:
@@ -203,10 +205,22 @@ def __init__(
203205
def __repr__(self):
204206
return self.__class__.__name__
205207

208+
@property
209+
def _graph(self) -> PyDiGraph[Importable, Edge]:
210+
if not self.__graph_ready:
211+
logger.info("Lazily Computing Graph")
212+
self.build_graph(self.projects[0].repo_operator)
213+
return self.__graph
214+
215+
@_graph.setter
216+
def _graph(self, value: PyDiGraph[Importable, Edge]) -> None:
217+
self.__graph = value
218+
206219
@stopwatch_with_sentry(name="build_graph")
207220
@commiter
208221
def build_graph(self, repo_operator: RepoOperator) -> None:
209222
"""Builds a codebase graph based on the current file state of the given repo operator"""
223+
self.__graph_ready = True
210224
self._graph.clear()
211225

212226
# =====[ Add all files to the graph in parallel ]=====

0 commit comments

Comments
 (0)