[Patches] [ python-Patches-474532 ] avoid resizes in _PyString_Resize()
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 07 Nov 2001 14:43:35 -0800
Patches item #474532, was opened at 2001-10-24 09:44
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=474532&group_id=5470
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Markus F.X.J. Oberhumer (mfx)
Assigned to: Nobody/Anonymous (nobody)
Summary: avoid resizes in _PyString_Resize()
Initial Comment:
The patch below (against CVS 2001-10-24) avoids
unnecessary calls to PyObject_REALLOC in
_PyString_Resize if the size of the string does
not change.
When running the regression test with this patch on
my Linux machine it shows that 53339 out of 323003
resizes can be avoided - this is more than 15%.
Additionally I've added sanity checks in
_PyStringResize to test for virgin values
of ob_shash and ob_sinterned. Better safe
than sorry.
Markus
--- Markus.F.X.J. Oberhumer <markus@oberhumer.com>
--- author of PySol
----------------------------------------------------------------------
>Comment By: Martin v. Löwis (loewis)
Date: 2001-11-07 14:43
Message:
Logged In: YES
user_id=21627
I recommend to reject this patch. If pymalloc is ever
enabled by default, it will definitely find out that this is
a noop fairly quickly.
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-10-24 15:15
Message:
Logged In: YES
user_id=31435
Hmm. I'm asking about speed, and you're counting how many
calls are made. Not the same thing. I expect a production-
quality realloc is doing its own "it's the same size -- I'm
done" early-out test, in which case adding a new test to
Python every time costs more every time, but the only
payback is saving the dirt-cheap realloc calls.
It would be much more interesting (to me) to determine why
useless calls to _PyString_Resize() are getting made so
often in PySol, and optimize those away instead.
----------------------------------------------------------------------
Comment By: Markus F.X.J. Oberhumer (mfx)
Date: 2001-10-24 14:54
Message:
Logged In: YES
user_id=12151
Well, the motivation is that I came across this is that I'm
playing around with some malloc implementation where a
realloc() is relatively expensive.
For some other statistics, starting up and playing PySol for
about one minute gives 7400 out of 15800 resizes with the
same size, so in this case the gain is almost 50%...
And the acutal speed cost is just one "if". The two other
checks were only added because they are obviously missing
(or maybe _PyString_Resize should reset ob_shash and
ob_interned).
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-10-24 12:05
Message:
Logged In: YES
user_id=31435
Markus, why do you care how ofen realloc is called? More
importantly, why should we <wink>?
This would be more interesting if you had evidence of a
measurable, significant speedup. The test suite runs a lot
of peculiar code, and I've got no reason to believe that
the 15% difference you saw running that is typical, or even
enough to make up for the new costs of the additional
failure tests you added here.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=474532&group_id=5470