Skip to content

Commit 26f9592

Browse files
committed
WIP
1 parent 03c3593 commit 26f9592

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/dbt_core_interface/project.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def __init__(
149149

150150
self._pool: ThreadPoolExecutor | None = None
151151

152-
self.__compilation_cache: dict[str, str] = {}
152+
self.__compilation_cache: dict[str, CompilationResult] = {}
153153

154154
if load:
155155
self._parse_project()
@@ -352,11 +352,20 @@ def execute_raw_sql(self, sql: str) -> ExecutionResult:
352352
)
353353

354354
def compile_sql(self, sql: str) -> CompilationResult:
355-
"""Compile SQL without execution."""
355+
"""Compile SQL without execution.
356+
357+
Leverages a compilation cache to avoid redundant parsing.
358+
"""
359+
if sql in self.__compilation_cache:
360+
return self.__compilation_cache[sql]
356361
with self._manifest_lock:
357362
temp_node, cleanup = self._create_temp_node(sql)
358363
try:
359-
return self.compile_from_node(temp_node, update_depends_on=False)
364+
response = self.compile_from_node(temp_node, update_depends_on=False)
365+
self.__compilation_cache[sql] = response
366+
if len(self.__compilation_cache) > 128:
367+
_ = self.__compilation_cache.pop(next(iter(self.__compilation_cache)))
368+
return response
360369
finally:
361370
cleanup()
362371

0 commit comments

Comments
 (0)