[Python-Dev] FAT Python (lack of) performance (original) (raw)

Paul Moore p.f.moore at gmail.com
Wed Jan 27 04:28:15 EST 2016


On 27 January 2016 at 05:23, Sjoerd Job Postmus <sjoerdjob at sjec.nl> wrote:

On Mon, Jan 25, 2016 at 11:58:12PM +0100, Victor Stinner wrote:

... Oh, they are a lot of things to do! ... Just wondering, do you also need a set of (abusive) test-cases which check 100% conformity to the CPython semantics? I'm sure many of us would be able to whip up some ideas of things that are possible with Python and are of the kind "but you should not do that! That's bad programming!" which may or may not break the optimizations (especially specialized functions). I'm thinking of things like def overridelengthfunctiontest(): global len value = len("abc") len = lambda obj: ord(obj[0])) value += len("abc") assert value == 3 + 97, "Outdated len used." And also cases where len was changed not in the function itself, but in another function that was called indirectly (maybe 4 functions down, one of which was monkey-patched in after the compilation step): modulea.py def testfunc(callback): value = len("abc") callback() value += len("abc") assert value == 3 + 97, "Outdated len used." moduleb.py import modulea def overridelengthfunctiontest(): def callback(): modulea.len = lambda obj: ord(obj[0]) assert modulea.testfunc(callback) == 3 + 97, "Outdated len used." (I'm sure some of the other readers of this list can be even more creative in trying to show that making optimizations like this can break semantics.) Other fun tricks I'd like to try is overriding the len method from a signal handler, what happens when you monkey-patch a dependent method, having _getitem_ and _getattr_ on some value override len. Basically: trying things that I normally should not try during my working hours, on account of wanting to still have a job the next day. Kind regards, Sjoerd Job

Maybe I'm just nasty, but IMO those kinds of "torture tests" are just as valuable in general, so I'd encourage people to submit patches to the main Python test suite to add them.

Paul



More information about the Python-Dev mailing list