Skip to content

Implement Lazy Graph Compute Mode #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/codegen/configs/models/codebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, prefix: str = "CODEBASE", *args, **kwargs) -> None:
ignore_process_errors: bool = True
disable_graph: bool = False
disable_file_parse: bool = False
exp_lazy_graph: bool = False
generics: bool = True
import_resolution_paths: list[str] = Field(default_factory=lambda: [])
import_resolution_overrides: dict[str, str] = Field(default_factory=lambda: {})
Expand Down
18 changes: 16 additions & 2 deletions src/codegen/sdk/codebase/codebase_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def __init__(
from codegen.sdk.core.parser import Parser

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

# Build the graph
self.build_graph(context.repo_operator)
if not self.config.exp_lazy_graph:
self.build_graph(context.repo_operator)
try:
self.synced_commit = context.repo_operator.head_commit
except ValueError as e:
Expand All @@ -203,10 +205,22 @@ def __init__(
def __repr__(self):
return self.__class__.__name__

@property
def _graph(self) -> PyDiGraph[Importable, Edge]:
if not self.__graph_ready:
logger.info("Lazily Computing Graph")
self.build_graph(self.projects[0].repo_operator)
return self.__graph

@_graph.setter
def _graph(self, value: PyDiGraph[Importable, Edge]) -> None:
self.__graph = value

@stopwatch_with_sentry(name="build_graph")
@commiter
def build_graph(self, repo_operator: RepoOperator) -> None:
"""Builds a codebase graph based on the current file state of the given repo operator"""
self.__graph_ready = True
self._graph.clear()

# =====[ Add all files to the graph in parallel ]=====
Expand Down
Loading