Skip to content

DB reset too slow with PG 16 db #3360

@finestructure

Description

@finestructure

First seen in #3278, using a PG 16 test db to run the tests makes them run really slowly (~6min vs 1.5min).

This is due to the function _resetDb, which TRUNCATEs all tables, taking much longer. I added

    let start = Date()
    defer { print("Resetting database took: \(Date().timeIntervalSince(start))s") }

to the start of the function and then ran the AnalyzeErrorTests (4 tests):

swift test --disable-automatic-resolution --filter AnalyzeErrorTests

With PG 13 we get

Resetting database took: 0.06859397888183594s
Resetting database took: 0.08555293083190918s
Resetting database took: 0.0502779483795166s
Resetting database took: 0.045484066009521484s
Resetting database took: 0.05070698261260986s

And with PG 16

Resetting database took: 0.3590719699859619s
Resetting database took: 0.44095301628112793s
Resetting database took: 0.3530939817428589s
Resetting database took: 0.34445297718048096s
Resetting database took: 0.3584989309310913s

i.e. about a factor of ~5-6 slower.

We can't stay on PG 13 forever but we can't accept a x5 regression in test speed, either. I've asked around and it looks like folks use a createdb strategy to create and restore db snapshots with a blank schema instead of truncating tables. That should solves this and might even be faster than the original version 🤞

Also notable: this test class has four tests, yet there are five log statements. For some reason we're running reset one extra time per test class. (That's because we call _resetDb recursively once in order to populate the table names cache.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions