Django国际化性能问题(3-4s vs 300ms,USE_I18N = False) [英] Django internationalization performance issues (3-4s vs 300ms with USE_I18N=False)

查看:204
本文介绍了Django国际化性能问题(3-4s vs 300ms,USE_I18N = False)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我们有一个有很多信息的页面,我们使用{%trans%}很多,但是当我们实际使用它们(USE_I18N = True)时,网站会停止,大约3.5秒使用i18n与300ms关闭。

So, we have a page with quite a lot of information on in, and we use {% trans %} a lot, but when we actually use them (USE_I18N=True) the site grinds to a halt, ~3.5 seconds with i18n vs 300ms with it off.

我们做了一些分析,似乎翻译初始化需要永远。

We did some profiling and it seems the translation initialization takes forever.

20.2%   0.503 /Library/Python/2.6/site-packages/Django-1.2.1-py2.6.egg/django/utils/translation/__init__.py
15.3%   0.383 /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/genericpath.py
11.4%   0.285 /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/gettext.py
 8.6%   0.215 /Library/Python/2.6/site-packages/Django-1.2.1-py2.6.egg/django/utils/formats.py
 8.5%   0.212 /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/posixpath.py
 8.3%   0.206 /Library/Python/2.6/site-packages/Django-1.2.1-py2.6.egg/django/utils/functional.py
 7.6%   0.189 /Library/Python/2.6/site-packages/Django-1.2.1-py2.6.egg/django/utils/translation/trans_real.py

我们尝试将{ trans%}阻塞到另一个缓存翻译的模板标签,但是只获得了几ms,而且这些页面并不是那么可缓存(除了翻译任何人都有这方面的任何经验,和/或一些关于如何使这一点更快的指针吗?

We tried wrapping the {% trans %} blocks into another templatetag which caches the translations, but that only gained a couple of ms, and the pages are not really that cacheable (except for the translations of course).

或者我们可能会陷入困境?

Anyone have any experience with this, and/or some pointers on how to make this go faster? Or any pitsfalls we might have gotten ourselfs into?

推荐答案

看起来L10N(django 1.2中的新内容)是罪人。我们通过不启用它来解决它(因为我们在任何地方都使用ISO格式)。

Seems L10N (new in django 1.2) was the sinner. We solved it by not enabling it (as we use ISO formats everywhere anyways).

可能应该将其报告给django ..: - )

Probably should report this to django.. :-)

这篇关于Django国际化性能问题(3-4s vs 300ms,USE_I18N = False)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆