diff --git a/CHANGES.rst b/CHANGES.rst index 92e8571d5..86c1ddb88 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -29,6 +29,9 @@ Unreleased data files. Now they are always ignored, fixing `issue 1605`_. Thanks to Brad Smith for suggesting fixes and providing detailed debugging. +- On Python 3.12+, we now disable SQLite writing journal files, which should be + a little faster. + .. _issue 1605: https://github.com/nedbat/coveragepy/pull/1605 .. _issue 1684: https://github.com/nedbat/coveragepy/issues/1684 .. _pull 1685: https://github.com/nedbat/coveragepy/pull/1685 diff --git a/coverage/sqlitedb.py b/coverage/sqlitedb.py index 4d15b5b50..c9e7aee30 100644 --- a/coverage/sqlitedb.py +++ b/coverage/sqlitedb.py @@ -55,8 +55,18 @@ def _connect(self) -> None: self.con.create_function("REGEXP", 2, lambda txt, pat: re.search(txt, pat) is not None) + # Turning off journal_mode can speed up writing. It can't always be + # disabled, so we have to be prepared for *-journal files elsewhere. + # In Python 3.12+, we can change the config to allow journal_mode=off. + if hasattr(sqlite3, "SQLITE_DBCONFIG_DEFENSIVE"): + # Turn off defensive mode, so that journal_mode=off can succeed. + self.con.setconfig( # type: ignore[attr-defined] + sqlite3.SQLITE_DBCONFIG_DEFENSIVE, False + ) + # This pragma makes writing faster. It disables rollbacks, but we never need them. self.execute_void("pragma journal_mode=off") + # This pragma makes writing faster. It can fail in unusual situations # (https://github.com/nedbat/coveragepy/issues/1646), so use fail_ok=True # to keep things going.