Django (?) really slow with large datasets after doing some python profiling

前端 未结 4 720
小蘑菇
小蘑菇 2021-02-10 02:48

I was comparing an old PHP script of mine versus the newer, fancier Django version and the PHP one, with full spitting out of HTML and all was functioning faster. MUCH faster to

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-10 02:59

    When dealing with large sets of data, you can also save a lot of CPU and memory by using the ValuesQuerySet that accesses the query results more directly instead of creating a model object instance for each row in the result.

    It's usage looks a bit like this:

    Blog.objects.order_by('id').values()
    

提交回复
热议问题