diff options
| author | Bert JW Regeer <bertjw@regeer.org> | 2016-09-29 01:46:16 -0600 |
|---|---|---|
| committer | Bert JW Regeer <bertjw@regeer.org> | 2016-09-29 02:15:19 -0600 |
| commit | d902761d6b77a061d98939901729f3a3028b7a5e (patch) | |
| tree | 7863ba782b60219ed9b3d6326d8d019fd8f78fee | |
| parent | 310477ff453011194275c7e897a48cacab95d0c6 (diff) | |
| download | webob-bugfix/exc_performance.tar.gz | |
Move the _lazified class out of the lazify functionbugfix/exc_performance
Capturing the function, and returning a new object from a class that is
defined within the capturing function seems to cause some sort of really
pathological behavior that causes lazify() to take up a bunch of CPU
time, especially when it is part of a hot code path.
Thanks to Martijn Faassen for reporting!
Closes #282
| -rw-r--r-- | webob/exc.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/webob/exc.py b/webob/exc.py index b615cd4..deffc64 100644 --- a/webob/exc.py +++ b/webob/exc.py @@ -185,13 +185,18 @@ tag_re = re.compile(r'<.*?>', re.S) br_re = re.compile(r'<br.*?>', re.I | re.S) comment_re = re.compile(r'<!--|-->') +class _lazified(object): + def __init__(self, func, value): + self.func = func + self.value = value + + def __str__(self): + return self.func(self.value) + def lazify(func): - class _lazyfied(object): - def __init__(self, s): - self._s = s - def __str__(self): - return func(self._s) - return _lazyfied + def wrapper(value): + return _lazified(func, value) + return wrapper def no_escape(value): if value is None: |
