Skip to content

Commit 842e492

Browse files
ilevkivskyihauntsaninja
authored andcommitted
Always disable sync in SQLite cache (#21184)
Fixes #21176 This seems to resolve all the HDD performance issues. Although this makes cache less durable, this is fine, as FS is not perfect in this sense either (and it doesn't really need to be that durable).
1 parent e82a046 commit 842e492

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

mypy/build.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ def __init__(
874874
]
875875
)
876876

877-
self.metastore = create_metastore(options, parallel_worker)
877+
self.metastore = create_metastore(options)
878878

879879
# a mapping from source files to their corresponding shadow files
880880
# for efficient lookup
@@ -1613,13 +1613,10 @@ def exclude_from_backups(target_dir: str) -> None:
16131613
pass
16141614

16151615

1616-
def create_metastore(options: Options, parallel_worker: bool = False) -> MetadataStore:
1616+
def create_metastore(options: Options) -> MetadataStore:
16171617
"""Create the appropriate metadata store."""
16181618
if options.sqlite_cache:
1619-
# We use this flag in both coordinator and workers to speed up commits,
1620-
# see mypy.metastore.connect_db() for details.
1621-
sync_off = options.num_workers > 0 or parallel_worker
1622-
mds: MetadataStore = SqliteMetadataStore(_cache_dir_prefix(options), sync_off=sync_off)
1619+
mds: MetadataStore = SqliteMetadataStore(_cache_dir_prefix(options))
16231620
else:
16241621
mds = FilesystemMetadataStore(_cache_dir_prefix(options))
16251622
return mds

mypy/metastore.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,20 @@ def close(self) -> None:
154154
"""
155155

156156

157-
def connect_db(db_file: str, sync_off: bool = False) -> sqlite3.Connection:
157+
def connect_db(db_file: str) -> sqlite3.Connection:
158158
import sqlite3.dbapi2
159159

160160
db = sqlite3.dbapi2.connect(db_file)
161-
if sync_off:
162-
# This is a bit unfortunate (as we may get corrupt cache after e.g. Ctrl + C),
163-
# but without this flag, commits are *very* slow, especially when using HDDs,
164-
# see https://www.sqlite.org/faq.html#q19 for details.
165-
db.execute("PRAGMA synchronous=OFF")
161+
# This is a bit unfortunate (as we may get corrupt cache after e.g. Ctrl + C),
162+
# but without this flag, commits are *very* slow, especially when using HDDs,
163+
# see https://www.sqlite.org/faq.html#q19 for details.
164+
db.execute("PRAGMA synchronous=OFF")
166165
db.executescript(SCHEMA)
167166
return db
168167

169168

170169
class SqliteMetadataStore(MetadataStore):
171-
def __init__(self, cache_dir_prefix: str, sync_off: bool = False) -> None:
170+
def __init__(self, cache_dir_prefix: str) -> None:
172171
# We check startswith instead of equality because the version
173172
# will have already been appended by the time the cache dir is
174173
# passed here.
@@ -177,7 +176,7 @@ def __init__(self, cache_dir_prefix: str, sync_off: bool = False) -> None:
177176
return
178177

179178
os.makedirs(cache_dir_prefix, exist_ok=True)
180-
self.db = connect_db(os_path_join(cache_dir_prefix, "cache.db"), sync_off=sync_off)
179+
self.db = connect_db(os_path_join(cache_dir_prefix, "cache.db"))
181180

182181
def _query(self, name: str, field: str) -> Any:
183182
# Raises FileNotFound for consistency with the file system version

0 commit comments

Comments
 (0)