Why are you calling os.path.join 27636 times ? These are the questions
you could be asking yourself ...

On Nov 18, 10:55 am, Dre <dreb...@gmail.com> wrote:
> I thought my code was faulty, but the admin interface is also very
> slow.
> It takes 8096 msec for a model with 1000 database rows to be opened
> using the admin interface with debug-toolbar enabled. It is paginated
> to
> 100 entries per page, and SQL makes 339 queries in 128.77 msec.
> I have two foreign keys on this model to models with < 20 entries
> each.
>
> After turning on additional profiling using hotshot/debug toolbar, it
> takes
> 61 sec (additional profiling code being run). SQL makes 675 queries in
> 297.63 msec.
>
> Profiling result:
>
>          1320805 function calls (1285639 primitive calls) in 12.122
> CPU seconds
>
>    Ordered by: internal time, call count
>    List reduced from 916 to 100 due to restriction <100>
>
>    ncalls  tottime  percall  cumtime  percall
> filename:lineno(function)
>    219094    2.790    0.000    3.576    0.000 /usr/lib/python2.7/
> posixpath.py:130(islink)
>    206072    2.248    0.000    2.248    0.000 /usr/lib/python2.7/
> posixpath.py:60(join)
> 27636/14223    1.751    0.000    8.587    0.001 /usr/lib/python2.7/
> posixpath.py:355(realpath)
>    219094    0.545    0.000    0.786    0.000 /usr/lib/python2.7/
> stat.py:55(S_ISLNK)
>     28294    0.494    0.000    0.494    0.000 /usr/lib/python2.7/
> posixpath.py:312(normpath)
>     13413    0.343    0.000    1.108    0.000 /usr/lib/python2.7/
> posixpath.py:378(_resolve_link)
>     14562    0.324    0.000    0.324    0.000 /usr/lib/python2.7/
> linecache.py:43(checkcache)
>       339    0.253    0.001    8.910    0.026 /usr/lib/pymodules/
> python2.7/debug_toolbar/panels/sql.py:31(tidy_stacktrace)
>    219098    0.240    0.000    0.240    0.000 /usr/lib/python2.7/
> stat.py:24(S_IFMT)
> 18480/4037    0.202    0.000    0.502    0.000 /usr/lib/python2.7/
> copy.py:145(deepcopy)
>       339    0.181    0.001    0.598    0.002 /usr/lib/python2.7/
> traceback.py:280(extract_stack)
>     55930    0.132    0.000    0.132    0.000 /usr/lib/python2.7/
> posixpath.py:51(isabs)
>       301    0.094    0.000    0.293    0.001 /usr/lib/pymodules/
> python2.7/debug_toolbar/panels/sql.py:49(get_template_info)
>     15393    0.075    0.000    0.075    0.000 /usr/lib/pymodules/
> python2.7/django/utils/functional.py:274(__getattr__)
>     18138    0.075    0.000    0.075    0.000 /usr/lib/python2.7/
> copy.py:267(_keep_alive)
>     31585    0.072    0.000    0.072    0.000 /usr/lib/pymodules/
> python2.7/django/views/debug.py:18(linebreak_iter)
>       339    0.072    0.000   10.087    0.030 /usr/lib/pymodules/
> python2.7/debug_toolbar/panels/sql.py:88(execute)
>     14225    0.070    0.000    0.338    0.000 /usr/lib/python2.7/
> posixpath.py:341(abspath)
> 2353/2018    0.069    0.000    0.279    0.000 /usr/lib/pymodules/
> python2.7/django/utils/tree.py:55(__deepcopy__)
> 311    0.064    0.000    0.128    0.000 /usr/lib/pymodules/python2.7/
> django/template/loaders/app_directories.py:52(load_template_source)
>      1009    0.060    0.000    0.585    0.001 /usr/lib/pymodules/
> python2.7/django/db/models/sql/query.py:229(clone)
>       968    0.057    0.000    0.111    0.000 /usr/lib/pymodules/
> python2.7/django/db/models/base.py:273(__init__)
>     14562    0.054    0.000    0.093    0.000 /usr/lib/python2.7/
> linecache.py:13(getline)
>       339    0.052    0.000    0.052    0.000 /usr/lib/pymodules/
> python2.7/django/db/backends/mysql/base.py:263(_valid_connection)
> 9376/8557    0.050    0.000    4.411    0.001 /usr/lib/pymodules/
> python2.7/django/utils/encoding.py:54(force_unicode)
>       339    0.050    0.000    0.070    0.000 /usr/lib/pymodules/
> python2.7/MySQLdb/cursors.py:273(_do_query)
> 2689/1344    0.050    0.000    0.233    0.000 /usr/lib/python2.7/
> copy.py:234(_deepcopy_tuple)
>      6365    0.044    0.000    0.044    0.000 /usr/lib/python2.7/
> encodings/utf_8.py:15(decode)
>      1200    0.041    0.000   10.759    0.009 /usr/lib/pymodules/
> python2.7/django/contrib/admin/templatetags/admin_list.py:
> 129(items_for_result)
>       932    0.037    0.000   11.203    0.012 /usr/lib/pymodules/
> python2.7/django/db/models/fields/related.py:286(__get__)
>   700/100    0.033    0.000    0.108    0.001 /usr/lib/pymodules/
> python2.7/django/db/models/query.py:1144(get_cached_row)
>      2713    0.030    0.000    0.032    0.000 /usr/lib/pymodules/
> python2.7/django/utils/datastructures.py:89(__init__)
>       468    0.027    0.000    0.033    0.000 /usr/lib/pymodules/
> python2.7/django/db/backends/mysql/compiler.py:4(resolve_columns)
>       600    0.026    0.000    0.044    0.000 /usr/lib/pymodules/
> python2.7/django/contrib/admin/util.py:321(display_for_field)
>      3231    0.025    0.000    0.025    0.000 /usr/lib/pymodules/
> python2.7/django/utils/safestring.py:89(mark_safe)
>     14562    0.024    0.000    0.039    0.000 /usr/lib/python2.7/
> linecache.py:33(getlines)
>      1442    0.024    0.000    0.036    0.000 /usr/lib/pymodules/
> python2.7/django/db/models/options.py:270(get_field)
>       806    0.023    0.000   10.661    0.013 /usr/lib/pymodules/
> python2.7/django/db/models/query.py:212(iterator)
>     252/1    0.022    0.000   11.084   11.084 /usr/lib/pymodules/
> python2.7/django/template/__init__.py:792(render)
>       343    0.021    0.000    0.038    0.000 /usr/lib/pymodules/
> python2.7/django/db/models/sql/compiler.py:215(get_default_columns)
>       806    0.020    0.000   10.456    0.013 /usr/lib/pymodules/
> python2.7/django/db/models/sql/compiler.py:670(results_iter)
>      1692    0.020    0.000    3.724    0.002 /usr/lib/pymodules/
> python2.7/django/utils/functional.py:254(wrapper)
>      1349    0.020    0.000    0.139    0.000 /usr/lib/python2.7/
> copy.py:306(_reconstruct)
>      1447    0.019    0.000    3.701    0.003 /usr/lib/pymodules/
> python2.7/django/utils/html.py:30(escape)
>     109/6    0.019    0.000    0.122    0.020 /usr/lib/pymodules/
> python2.7/django/template/defaulttags.py:124(render)
>      1938    0.019    0.000    0.043    0.000 /usr/lib/pymodules/
> python2.7/django/dispatch/dispatcher.py:149(send)
>       339    0.019    0.000    0.033    0.000 /usr/lib/pymodules/
> python2.7/django/db/backends/__init__.py:197(last_executed_query)
>       339    0.019    0.000    0.177    0.001 /usr/lib/pymodules/
> python2.7/django/db/models/sql/compiler.py:47(as_sql)
>       339    0.019    0.000    0.151    0.000 /usr/lib/pymodules/
> python2.7/MySQLdb/cursors.py:129(execute)
>       338    0.019    0.000    0.031    0.000 /usr/lib/pymodules/
> python2.7/django/db/models/sql/query.py:105(__init__)
>         1    0.019    0.019    0.032    0.032 /usr/lib/python2.7/
> gettext.py:262(_parse)
>       336    0.018    0.000    0.064    0.000 /usr/lib/pymodules/
> python2.7/django/db/models/sql/query.py:987(add_filter)
>     92/80    0.017    0.000    0.041    0.001 /usr/lib/pymodules/
> python2.7/django/utils/importlib.py:18(import_module)
>       337    0.017    0.000   10.607    0.031 /usr/lib/pymodules/
> python2.7/django/db/models/query.py:72(__len__)
> 5715/5045    0.017    0.000    0.151    0.000 /usr/lib/python2.7/
> copy.py:226(_deepcopy_list)
>       339    0.016    0.000    0.043    0.000 /usr/lib/pymodules/
> python2.7/MySQLdb/cursors.py:282(_fetch_row)
>      1008    0.015    0.000    0.605    0.001 /usr/lib/pymodules/
> python2.7/django/db/models/query.py:762(_clone)
>      2713    0.015    0.000    0.015    0.000 /usr/lib/pymodules/
> python2.7/django/utils/datastructures.py:84(__new__)
>        40    0.015    0.000    0.015    0.000 /usr/lib/python2.7/
> linecache.py:68(updatecache)
>      1100    0.014    0.000    6.948    0.006 /usr/lib/pymodules/
> python2.7/django/contrib/admin/util.py:254(lookup_field)
>      1585    0.014    0.000    0.039    0.000 /usr/lib/pymodules/
> python2.7/django/template/__init__.py:550(resolve)
>      2037    0.014    0.000    0.026    0.000 /usr/lib/pymodules/
> python2.7/MySQLdb/connections.py:189(string_decoder)
>       338    0.013    0.000    0.017    0.000 /usr/lib/pymodules/
> python2.7/django/db/models/sql/query.py:1190(setup_joins)
>       339    0.013    0.000    0.057    0.000 /usr/lib/pymodules/
> python2.7/django/db/models/sql/compiler.py:135(get_columns)
>       339    0.013    0.000    0.101    0.000 /usr/lib/pymodules/
> python2.7/django/db/backends/__init__.py:73(cursor)
>      4039    0.013    0.000    0.013    0.000 /usr/lib/pymodules/
> python2.7/django/utils/tree.py:18(__init__)
>      1010    0.012    0.000    0.035    0.000 /usr/lib/pymodules/
> python2.7/django/utils/datastructures.py:108(__deepcopy__)
>      1243    0.012    0.000    0.064    0.000 /usr/lib/pymodules/
> python2.7/django/template/debug.py:87(render)
>  1014/678    0.012    0.000    0.081    0.000 /usr/lib/pymodules/
> python2.7/django/db/models/sql/where.py:75(as_sql)
>       336    0.012    0.000    0.047    0.000 /usr/lib/pymodules/
> python2.7/django/db/models/sql/where.py:319(process)
>       339    0.012    0.000    0.012    0.000 /usr/lib/pymodules/
> python2.7/MySQLdb/cursors.py:40(__init__)
>      1266    0.012    0.000    0.015    0.000 /usr/lib/pymodules/
> python2.7/django/utils/formats.py:104(localize)
>      2706    0.011    0.000    0.017    0.000 /usr/lib/pymodules/
> python2.7/django/db/models/sql/compiler.py:31(quote_name_unless_alias)
>       339    0.011    0.000    0.020    0.000 /usr/lib/pymodules/
> python2.7/MySQLdb/cursors.py:107(_do_get_result)
>       336    0.011    0.000    0.069    0.000 /usr/lib/pymodules/
> python2.7/django/db/models/sql/where.py:131(make_atom)
>       339    0.011    0.000    0.011    0.000 /usr/lib/python2.7/dist-
> packages/simplejson/encoder.py:222(iterencode)
>       334    0.011    0.000   10.986    0.033 /usr/lib/pymodules/
> python2.7/django/db/models/query.py:334(get)
>       338    0.010    0.000    0.085    0.000 /usr/lib/pymodules/
> python2.7/django/db/models/sql/query.py:1139(add_q)
>       339    0.010    0.000   10.375    0.031 /usr/lib/pymodules/
> python2.7/django/db/models/sql/compiler.py:708(execute_sql)
>       969    0.010    0.000    0.016    0.000 /usr/lib/pymodules/
> python2.7/django/dispatch/dispatcher.py:214(_live_receivers)...
>
> read more »

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to