Squashing migrations speeded up tests - and not just the database setup part

Viewed 121

I have been struggling with slow tests - really slow tests. I thought that was probably due to inefficient data setup within my tests. I did some 'before' time measurements and then, for unrelated reasons, squashed all my migrations. Then I ran my tests again. I did not change any of the test code - only the migrations - but the tests are dramatically faster. I had expected some improvement in the database setup number reported with --timing but I had not expected much change in the speed with which the tests themselves run. Can anyone offer an explanation for this?

Before

Method DB setup DB teardown Running Test Total elapsed
MySQL 124.2s 3.6s 794.5s 925.0s
MySQL keepdb 1 123.8s 0s 742.5s 869.2s
MySQL keepdb 2 4.3s 0s 742.2s 759.1s
SQLite run 1 4.9s 0s 886.7s 896.3s
SQLite run 2 4.3s 0s 778.1s 785.2s

After squashing migration

Method DB setup DB teardown Running Test Total elapsed
MySQL 107.8s 6.5s 200.0s 319.5s
MySQL 109.3s 6.9s 205.3s 326.4s
SQLite run 1 34.3s 0s 128.2s 166.9s
SQLite run 2 1.5s 0s 124.6s 130.3s
1 Answers

Update. I did some more testing of my assumptions - checking out code from right before the migration squashing (and from the time period where I had taken the original data). In both cases I am now seeing the older code running tests in a more reasonable time frame - with the main differences being in the database setup times. My only explanation is that I must have had something else running on my laptop the day I took the original dismal timings.

Right before the squash

Method DB setup DB teardown Running Test Total elapsed
MySQL 191.2s 8.1s 207.4s 415.5s

Code from same period as the "before" measurements in my question

Method DB setup DB teardown Running Test Total elapsed
MySQL 183.8s 6.5s 190.5s 386.4s
Related