Django version 1.9 has some form of memory leak when it runs its migrations. The two points of friction I have noticed are: 1 The calculation of the dependency graph seems unusually slow 2 The sql operations seem to leak in memory and in execution time

##Slow graph

In order to improve speed, simplifying the dependencies seems to be the ideal solution. If you happen to have a data migrations only app, using __latest__ in the dependencies delays the migrations for that app. Similarly, if regular migrations apply, instead of using __latest__ just point to the last migration. All of this will allow squashed migrations to be effective.

depedencies = (('same_app', '0001_before'),
               ('another_app', '__latest__'))

slow SQL Operations

If the sql operations get slower over time and the memory consumption goes up, the way to fix it is to squash the migrations and then remove the redundant lines that django squashmigrations doesn’t handle. An example of this would be:

    operations = [CreateTable table1 ...,
                  RunPython(x),
                  AlterField(table1, field1, ....)
                 ]

Django can’t know if the python migration code requires the table to be created with the original or altered field, so if possible this:

    operations = [CreateTable table1 ...,
                  RunPython(x),
                 ]

will improve the performance by avoiding an extra AlterField