[Python-Dev] optimizing non-local object access (original) (raw)
Skip Montanaro skip@pobox.com (Skip Montanaro)
Thu, 9 Aug 2001 13:05:28 -0500
- Previous message: [Python-Dev] optimizing non-local object access
- Next message: [Python-Dev] optimizing non-local object access
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Jeremy> Imagine we didn't special case ints in BINARY_ADD. If you're
Jeremy> doing mostly string addition, it's just slowing you down anyway
Jeremy> :-). Instead, a function that expected to see ints would check
Jeremy> the types of the relevant args.
Jeremy> def f(x):
Jeremy> return 2*x
Jeremy> would become something like:
Jeremy> def f(x):
Jeremy> if isinstance(x, int):
Jeremy> return 2 * x_as_int
Jeremy> else:
Jeremy> return 2 * x
Jeremy> where the int branch could use opcodes that knew that x was an
Jeremy> integer and could call its __add__ method directly.
Yeah, but all you've really done is extract the current inline test for int arguments into a few more PyVM instructions. You've sacrificed a fairly fast special case test for more passes around the interpreter loop. I'm not sure how this can be a win in the current virtual machine.
Skip
- Previous message: [Python-Dev] optimizing non-local object access
- Next message: [Python-Dev] optimizing non-local object access
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]