Skip to content

[Vsintegration] Solution open: no VACUUM of the code model database - #2191

Merged
RobertvanderHulst merged 1 commit into
X-Sharp:devfrom
hpetriffer:hpetriffer/startup_speedup
Nov 21, 2026
Merged

RobertvanderHulst merged 1 commit into
X-Sharp:devfrom
hpetriffer:hpetriffer/startup_speedup

Conversation

@hpetriffer

Copy link
Copy Markdown
Contributor

Summary

Opening a solution froze Visual Studio while the code model database was opened: SetPragmas ran a VACUUM for every connection, and CreateOrOpenDatabase opens the disk database twice. That is two full rewrites of the .xsdb on the UI thread for every solution that opens, in both project systems (MPFproj and CPS).

 XSolution.Open                          # UI thread
   XDatabase.CreateOrOpenDatabase
     OpenFile(disk)                      # for ValidateSchema
       SetPragmas
         foreign_keys, SetCollation
-        VACUUM                          # 3.3 s
     ValidateSchema                      # rejects a file of the other SQLite provider (Db_Version.MsSqlite)
     OpenFile(disk)                      # for the restore
       SetPragmas
-        VACUUM                          # 12.0 s
     RestoreFromDisk                     # 0.3-0.6 s
+    ReindexAfterRestore                 # Microsoft.Data.Sqlite only: REINDEX NOCASE on the in memory copy
     DeleteOrphanFiles, DeleteMissingFiles
  • The VACUUM at open also re-sorted the NOCASE indexes of a file that the other SQLite provider wrote ([Vsintegration] XDatabase: register the collation before the VACUUM #2132). Since 9b3fe5f ValidateSchema rejects such a file, so with System.Data.SQLite (built-in NOCASE) the VACUUM had nothing left to do. SaveToDisk still compacts the file after every backup.
  • Microsoft.Data.Sqlite registers a NOCASE that compares with the current culture, so the order of an index can still differ from the one the file was written with. For that provider the NOCASE indexes of the in memory copy are rebuilt after the restore, which is what the VACUUM did at that point.

Evidence

VS 2022 (17.14) experimental instance, SDK-style solution with 94 X# projects x 2 target frameworks, 45,800 files, 284 MB X#Model.xsdb, warm open, System.Data.SQLite. UI responsiveness probed every 250 ms with SendMessageTimeout; database times from the X# log (one run each).

before after (2 runs)
UI thread blocked ~20 s (until second 27) ~2-3 s, scattered
load finished, CPU quiet at ~48 s at ~25 s
CreateOrOpenDatabase (log) 20.7 s 1.4 s
  • Before: UI-thread stacks at 8, 12, 18 and 20 s after start all show XDatabase.SetPragmas <- OpenFile <- CreateOrOpenDatabase <- XSolution.Open.
  • After: same 92,332 AddFile calls, no errors in the log, no re-parse of the sources: the database is taken over completely.
  • "before" is the build that was deployed in the instance the day before, "after" a build of this branch; the database times in the log show the effect directly.

Microsoft.Data.Sqlite was not run inside Visual Studio. Outside, with that provider and the custom NOCASE on a copy of the same file (written with the built-in NOCASE): PRAGMA integrity_check reports row 236 missing from index ReferencedTypes_Name after the restore, REINDEX NOCASE takes 6.0 s, and the check then returns ok.

Merge Danger

Door: two-way

No change to the database format or schema version; reverting the commit restores the old behaviour.

Blast Radius: code model database open

With Microsoft.Data.Sqlite (ARM, or the option) the open still costs one REINDEX (6 s on this database) on the UI thread, instead of two VACUUMs. Dropping that as well needs a culture marker in the file or a culture independent collation, which changes the database format and is left out here.

🤖 Generated with Claude Code

SetPragmas ran a VACUUM for every connection, and CreateOrOpenDatabase opens
the disk database twice: two full rewrites of the file on the UI thread for
every solution that opens (15 s for a 284 MB database).

SaveToDisk compacts the file after every backup, and a file written by the
other SQLite provider is rejected by ValidateSchema (Db_Version.MsSqlite).
For Microsoft.Data.Sqlite, whose NOCASE depends on the culture, the NOCASE
indexes of the in memory copy are rebuilt after the restore instead.

Co-Authored-By: Claude <noreply@anthropic.com>
@RobertvanderHulst
RobertvanderHulst merged commit a8f3657 into X-Sharp:dev Nov 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants