[Python-ideas] multiple objects handling

Peter V. Saveliev peet at altlinux.ru
Sat Aug 13 00:18:37 CEST 2011

On 13.08.2011 01:47, Scott Dial wrote:
<skip />
> Really? Your runtime is dominated by a *single* dict lookup and a
> *single* method call?

No, surely :))) But it is one of the problems.

> What do you do with these objects that takes so
> little time that such a micro-optimization will have a "significant
> speed up" to your program?
> Have you actually profiled the performance of your program? I would
> guess that the time spent dispatching through a dictionary is dwarfed by
> the time spent constructing those event objects and the ultimate
> processing of them.

You're right, but having really huge stream of packets I try to minimize
any overhead — using C modules, ctypes library and so on. But I hope to
save high-level logic in Python, and before to reject a chance to speed
up parsing, I asked for some alternatives and contras. I believe that
method calls here are unnecessary while the «if» statements tree makes
the code hard to support.

>> But can we have another separate codeop, e.g. something like
>> JUMP_BY_TOS, that takes offset (or absolute address) from the top of the
>> stack?
> How would you use such a opcode? There is no syntax available that would
> allow you to get the offset (or absolute address) of any given line in a
> function. To have a "goto" statement, you have to have labels, we don't
> have those either.
> Or, are you proposing that CPython optimize large if/elif blocks into
> dispatch tables? That sounds more interesting, but the performance win
> would have to worth the additional code complexity.

'Cause there can be any expression used in «if» statement, I see no way
to create pre-computed hash :( Maybe something like «switch» would work,
as Bruce says, but it is rejected for now.

Peter V. Saveliev

More information about the Python-ideas mailing list