Repository navigation
Commit 3f9118f
* Speed up PyObject_CallMethod via _PyObject_GetMethod
PyObject_CallMethod (and _PyObject_CallMethod, PyEval_CallMethod,
_PyObject_CallMethodId and the _SizeT variant) resolved the method with
PyObject_GetAttr, which builds a temporary bound-method object on every call,
then called it.
Resolve the method with _PyObject_GetMethod instead (the same lookup the
interpreter uses for obj.name(...)) and call it directly via
_PyObject_VectorcallPrepend, skipping the bound-method allocation. Behaviour
is unchanged: same attribute semantics, same "attribute of type ... is not
callable" error, and the historical
PyObject_CallMethod(o, m, "O", tuple) -> o.m(*tuple) unpacking.
The shared helper callmethod() and _PyObject_CallMethodFormat() are no longer
needed: their only caller (traceback.c) now uses PyObject_CallFunction, so both
are removed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Use _PyObject_GetMethodStackRef so method calls scale in free-threading
Resolve the method in callmethod_va() via _PyObject_GetMethodStackRef()
instead of _PyObject_GetMethod(). The StackRef variant returns the method
as a deferred reference, avoiding the per-call atomic refcount on the
shared method object that otherwise serializes threads in the
free-threaded build.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* rename to callmethod
* review comments
* review comments
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
1 parent cfd6cf7 commit 3f9118f
3 files changed
Lines changed: 75 additions & 49 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | 60 | | |
67 | 61 | | |
68 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
612 | 612 | | |
613 | 613 | | |
614 | 614 | | |
615 | | - | |
616 | | - | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
617 | 618 | | |
618 | | - | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
619 | 634 | | |
620 | 635 | | |
621 | 636 | | |
622 | 637 | | |
623 | | - | |
| 638 | + | |
624 | 639 | | |
625 | 640 | | |
626 | | - | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
627 | 679 | | |
628 | 680 | | |
629 | 681 | | |
| |||
635 | 687 | | |
636 | 688 | | |
637 | 689 | | |
638 | | - | |
639 | | - | |
| 690 | + | |
| 691 | + | |
640 | 692 | | |
641 | 693 | | |
642 | 694 | | |
643 | 695 | | |
644 | 696 | | |
645 | | - | |
| 697 | + | |
646 | 698 | | |
647 | 699 | | |
648 | | - | |
| 700 | + | |
649 | 701 | | |
650 | 702 | | |
651 | 703 | | |
| |||
660 | 712 | | |
661 | 713 | | |
662 | 714 | | |
663 | | - | |
664 | | - | |
| 715 | + | |
| 716 | + | |
665 | 717 | | |
666 | 718 | | |
667 | 719 | | |
668 | 720 | | |
669 | 721 | | |
670 | | - | |
| 722 | + | |
671 | 723 | | |
672 | 724 | | |
673 | | - | |
| 725 | + | |
674 | 726 | | |
675 | 727 | | |
676 | 728 | | |
| |||
684 | 736 | | |
685 | 737 | | |
686 | 738 | | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | 739 | | |
693 | 740 | | |
694 | | - | |
| 741 | + | |
695 | 742 | | |
696 | 743 | | |
697 | | - | |
698 | 744 | | |
699 | 745 | | |
700 | 746 | | |
| |||
710 | 756 | | |
711 | 757 | | |
712 | 758 | | |
713 | | - | |
| 759 | + | |
714 | 760 | | |
715 | | - | |
| 761 | + | |
716 | 762 | | |
717 | 763 | | |
718 | 764 | | |
719 | 765 | | |
720 | 766 | | |
721 | | - | |
| 767 | + | |
722 | 768 | | |
723 | 769 | | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
737 | 770 | | |
738 | 771 | | |
739 | 772 | | |
| |||
749 | 782 | | |
750 | 783 | | |
751 | 784 | | |
752 | | - | |
753 | | - | |
| 785 | + | |
| 786 | + | |
754 | 787 | | |
755 | 788 | | |
756 | 789 | | |
757 | 790 | | |
758 | 791 | | |
759 | | - | |
| 792 | + | |
760 | 793 | | |
761 | 794 | | |
762 | | - | |
| 795 | + | |
763 | 796 | | |
764 | 797 | | |
765 | 798 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
400 | | - | |
401 | 400 | | |
402 | 401 | | |
403 | 402 | | |
| |||
437 | 436 | | |
438 | 437 | | |
439 | 438 | | |
440 | | - | |
| 439 | + | |
441 | 440 | | |
442 | 441 | | |
443 | 442 | | |
| |||
0 commit comments