I have to agree with Marteen. >From my experience what really slow down the migrate and makemigrations command is the rendering of model states into concrete model classes. This is something I concluded from my work on adding the plan object to pre_migrate and post_migrate signals.
As soon as an operation accesses state.apps the rendering kicks in which triggers the dynamic creation of multiple model classes and the computation of reverse relationships. There are mechanisms in place to prevent the whole project model classes from being rendered again when a model state is altered but if the operation is performed on a model referenced by many others the relationship chain might force a large number of them to be rendered again causing massive slow downs. Markus Holtermann has been working on teaching the migration framework how to perform database operations without relying on state.apps which should solve the remaining performance issues of the migrate command. In the case of makemigrations the last remaining issue in the master branch should be solved by stopping to rely on state.apps in RenameModel.state_forwards[1]. Patryk, many improvement landed in 1.9 and 1.10 to speed up the commands dealing with migrations. Are you still seeing the same slowdown on these versions? Simon [1] https://github.com/django/django/pull/7468 Le dimanche 6 novembre 2016 00:32:04 UTC+1, Marten Kenbeek a écrit : > > On Saturday, November 5, 2016 at 4:53:49 PM UTC+1, Patryk Zawadzki wrote: >> >> 1. Dependency resolution that turns the migration dependency graph into >> an ordered list happens every time you try to create or execute a >> migration. If you have several hundred migrations it becomes quite slow. >> I'm talking multiple minutes kind of slow. As you can imagine working with >> multiple branches or perfecting your migrations quickly becomes a tedious >> task. >> > > Did the dependency resolution actually come up in benchmarks/profiles as a > bottleneck? When I optimized and benchmarked the dependency graph code, it > had no trouble ordering ~1000 randomly generated migrations with lots of > inter-app dependencies in less than a second. I'd be surprised if this had > any significant impact on the overall performance of migrations. > > An easy way to test this is the `showmigrations` command, which will only > generate the graph without any model state changes or model rendering > taking place. It does some other things, but nothing that should take in > the order of minutes. > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/4a012e54-fae5-4bba-97a9-f323f38e53bc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.