[Patches] [ python-Patches-1349274 ] [PATCH] 100x optimization for ngettext

SourceForge.net noreply at sourceforge.net
Mon Nov 7 22:41:07 CET 2005


Patches item #1349274, was opened at 2005-11-06 00:18
Message generated for change (Comment added) made by piman
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1349274&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Joe Wreschnig (piman)
Assigned to: Nobody/Anonymous (nobody)
Summary: [PATCH] 100x optimization for ngettext

Initial Comment:
Currently gettext.ngettext scans the filesystem
whenever you call it. This makes it ridiculously slow.
But if one uses gettext.install to initialize gettext,
gettext.ngettext is the cleanest way to do plural
translation.

This patch makes gettext.install install both "_" and
"ngettext" into the builtin namespace, which means
using "ngettext" won't have to do the filesystem
lookup. My benchmarks show this is about 100 times faster.

----------------------------------------------------------------------

>Comment By: Joe Wreschnig (piman)
Date: 2005-11-07 21:41

Message:
Logged In: YES 
user_id=796

Well, I did write my own install function; that's the patch
you see below. I figured I'd submit it in the interest of
other users (that's the point of a standard library, right?)
but if the Pythonic thing to do is choose between ugly or
slow, I guess I'll just keep using my own.

----------------------------------------------------------------------

Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-11-07 20:30

Message:
Logged In: YES 
user_id=1188172

I didn't mean to overload the calling of "_", but I can
think of "_.gettext()", "_.ngettext()" etc. Of course with
"_()" staying  the same.

Other than that, if you need ngettext in builtins, why don't
you write your own install function?

----------------------------------------------------------------------

Comment By: Joe Wreschnig (piman)
Date: 2005-11-06 20:59

Message:
Logged In: YES 
user_id=796

It seems to me that the time to complain about namespace
clutter was when gettext.install was written. Besides, it's
only "clutter" if you're not using it, and if you're not
using it, just don't call install.

Making _ dispatch on the number of arguments would break all
the existing string extraction tools. It's also unintuitive
for anyone coming from gettext in other languages. It's also
messy semantic overloading.

----------------------------------------------------------------------

Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-11-06 19:21

Message:
Logged In: YES 
user_id=1188172

The problem you diagnosed is valid, but I don't think the
patch is a proper way to salvage it (by cluttering the
builtin namespace).

I'd rather have the installed name "_" point to a wrapper
object that gives one access to the other translation functions.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1349274&group_id=5470


More information about the Patches mailing list