• Marius Wachtler's avatar
    microptimization: mark _PyGC_generation0 as having a const address · 938b0190
    Marius Wachtler authored
    this is an advantage for _PyObject_GC_TRACK
    which before compiled to something like this:
            cmpq    $-2, -16(%rdi)
            jne     .LBB0_2
            movq    $-3, -16(%rdi)
            movq    _PyGC_generation0(%rip), %rax
            movq    %rax, -32(%rdi)
            movq    _PyGC_generation0(%rip), %rax
            movq    8(%rax), %rax
            movq    %rax, -24(%rdi)
            leaq    -32(%rdi), %rcx
            movq    %rcx, (%rax)
            movq    _PyGC_generation0(%rip), %rax
            movq    %rcx, 8(%rax)
    
    and now compiles to
            cmpq    $-2, -16(%rdi)
            jne     .LBB0_2
            movq    $-3, -16(%rdi)
            movq    _PyGC_generation0(%rip), %rax
            movq    %rax, -32(%rdi)
            movq    8(%rax), %rcx
            movq    %rcx, -24(%rdi)
            leaq    -32(%rdi), %rdx
            movq    %rdx, (%rcx)
            movq    %rdx, 8(%rax)
    
    notice that it had to load _PyGC_generation0 three times because the compiler had to assume that because of aliasing it got motified.
    (and this loads actually showed up in profiling as somewhat expensive)
    938b0190
gcmodule.c 51 KB