> If it's not too much work to coax the compiler to do so, then I don't see a > strong reason to avoid it. Granted, there are probably much more expensive > parts of the StringInfo support functions (e.g., palloc()), but these are > hot enough code paths that IMHO it's worth saving whatever cycles we can.
Ok, I have created v3 patch to do more inlining as you suggested. With the patch I confirmed that there's no call to functions except palloc in makeStringInfo, makeStringInfoExt, initStringInfo and initStringInfoExt in the asm codes (see attached stringinfo.s). Best reagards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp
v3-0001-Add-new-StringInfo-APIs-to-allow-callers-to-speci.patch
Description: Binary data
.file "stringinfo.c"
.text
.p2align 4
.globl makeStringInfo
.type makeStringInfo, @function
makeStringInfo:
.LFB100:
.cfi_startproc
endbr64
pushq %r12
.cfi_def_cfa_offset 16
.cfi_offset 12, -16
movl $24, %edi
call palloc@PLT
movl $1024, %edi
movq %rax, %r12
call palloc@PLT
movl $1024, 12(%r12)
movq %rax, (%r12)
movb $0, (%rax)
movq %r12, %rax
movl $0, 8(%r12)
movl $0, 16(%r12)
popq %r12
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE100:
.size makeStringInfo, .-makeStringInfo
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "src/common/stringinfo.c"
.LC1:
.string "initsize > 0"
.text
.p2align 4
.globl makeStringInfoExt
.type makeStringInfoExt, @function
makeStringInfoExt:
.LFB101:
.cfi_startproc
endbr64
pushq %r12
.cfi_def_cfa_offset 16
.cfi_offset 12, -16
pushq %rbx
.cfi_def_cfa_offset 24
.cfi_offset 3, -24
movl %edi, %ebx
movl $24, %edi
subq $8, %rsp
.cfi_def_cfa_offset 32
call palloc@PLT
testl %ebx, %ebx
jle .L7
movslq %ebx, %rdi
movq %rax, %r12
call palloc@PLT
movl %ebx, 12(%r12)
movq %rax, (%r12)
movb $0, (%rax)
movq %r12, %rax
movl $0, 8(%r12)
movl $0, 16(%r12)
addq $8, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 24
popq %rbx
.cfi_def_cfa_offset 16
popq %r12
.cfi_def_cfa_offset 8
ret
.L7:
.cfi_restore_state
movl $43, %edx
leaq .LC0(%rip), %rsi
leaq .LC1(%rip), %rdi
call ExceptionalCondition@PLT
.cfi_endproc
.LFE101:
.size makeStringInfoExt, .-makeStringInfoExt
.p2align 4
.globl initStringInfo
.type initStringInfo, @function
initStringInfo:
.LFB102:
.cfi_startproc
endbr64
pushq %rbx
.cfi_def_cfa_offset 16
.cfi_offset 3, -16
movq %rdi, %rbx
movl $1024, %edi
call palloc@PLT
movl $1024, 12(%rbx)
movq %rax, (%rbx)
movb $0, (%rax)
movl $0, 8(%rbx)
movl $0, 16(%rbx)
popq %rbx
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE102:
.size initStringInfo, .-initStringInfo
.p2align 4
.globl initStringInfoExt
.type initStringInfoExt, @function
initStringInfoExt:
.LFB103:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
pushq %rbx
.cfi_def_cfa_offset 24
.cfi_offset 3, -24
subq $8, %rsp
.cfi_def_cfa_offset 32
testl %esi, %esi
jle .L13
movq %rdi, %rbx
movslq %esi, %rdi
movl %esi, %ebp
call palloc@PLT
movl %ebp, 12(%rbx)
movq %rax, (%rbx)
movb $0, (%rax)
movl $0, 8(%rbx)
movl $0, 16(%rbx)
addq $8, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 24
popq %rbx
.cfi_def_cfa_offset 16
popq %rbp
.cfi_def_cfa_offset 8
ret
.L13:
.cfi_restore_state
movl $43, %edx
leaq .LC0(%rip), %rsi
leaq .LC1(%rip), %rdi
call ExceptionalCondition@PLT
.cfi_endproc
.LFE103:
.size initStringInfoExt, .-initStringInfoExt
.section .rodata.str1.1
.LC2:
.string "str->maxlen != 0"
.text
.p2align 4
.globl resetStringInfo
.type resetStringInfo, @function
resetStringInfo:
.LFB104:
.cfi_startproc
endbr64
movl 12(%rdi), %edx
testl %edx, %edx
je .L19
movq (%rdi), %rax
movb $0, (%rax)
movl $0, 8(%rdi)
movl $0, 16(%rdi)
ret
.L19:
pushq %rax
.cfi_def_cfa_offset 16
movl $129, %edx
leaq .LC0(%rip), %rsi
leaq .LC2(%rip), %rdi
call ExceptionalCondition@PLT
.cfi_endproc
.LFE104:
.size resetStringInfo, .-resetStringInfo
.section .rodata.str1.1
.LC3:
.string "str != NULL"
.text
.p2align 4
.globl appendStringInfoVA
.type appendStringInfoVA, @function
appendStringInfoVA:
.LFB106:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
pushq %rbx
.cfi_def_cfa_offset 24
.cfi_offset 3, -24
subq $8, %rsp
.cfi_def_cfa_offset 32
testq %rdi, %rdi
je .L26
movq %rdi, %rbx
movslq 8(%rdi), %rdi
movl $32, %eax
movl 12(%rbx), %r8d
subl %edi, %r8d
cmpl $15, %r8d
jle .L20
movslq %r8d, %rbp
movq %rdx, %rcx
addq (%rbx), %rdi
movq %rsi, %rdx
movq %rbp, %rsi
call pvsnprintf@PLT
cmpq %rax, %rbp
ja .L27
movslq 8(%rbx), %rdx
movq (%rbx), %rcx
movb $0, (%rcx,%rdx)
.L20:
addq $8, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 24
popq %rbx
.cfi_def_cfa_offset 16
popq %rbp
.cfi_def_cfa_offset 8
ret
.p2align 4,,10
.p2align 3
.L27:
.cfi_restore_state
addl %eax, 8(%rbx)
addq $8, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 24
xorl %eax, %eax
popq %rbx
.cfi_def_cfa_offset 16
popq %rbp
.cfi_def_cfa_offset 8
ret
.L26:
.cfi_restore_state
movl $192, %edx
leaq .LC0(%rip), %rsi
leaq .LC3(%rip), %rdi
call ExceptionalCondition@PLT
.cfi_endproc
.LFE106:
.size appendStringInfoVA, .-appendStringInfoVA
.section .rodata.str1.8,"aMS",@progbits,1
.align 8
.LC4:
.string "invalid string enlargement request size: %d"
.align 8
.LC5:
.string "string buffer exceeds maximum allowed length (%zu bytes)"
.align 8
.LC6:
.string "Cannot enlarge string buffer containing %d bytes by %d more
bytes."
.section .text.unlikely,"ax",@progbits
.LCOLDB7:
.text
.LHOTB7:
.p2align 4
.globl enlargeStringInfo
.type enlargeStringInfo, @function
enlargeStringInfo:
.LFB112:
.cfi_startproc
endbr64
pushq %r12
.cfi_def_cfa_offset 16
.cfi_offset 12, -16
pushq %rbp
.cfi_def_cfa_offset 24
.cfi_offset 6, -24
pushq %rbx
.cfi_def_cfa_offset 32
.cfi_offset 3, -32
movl 12(%rdi), %eax
testl %eax, %eax
je .L46
movl %esi, %r12d
testl %esi, %esi
js .L42
movq %rdi, %rbp
movslq 8(%rdi), %rdi
movl $1073741823, %edx
movslq %r12d, %rcx
subq %rdi, %rdx
cmpq %rdx, %rcx
jnb .L43
leal 1(%rdi,%r12), %edx
cmpl %edx, %eax
jge .L28
.p2align 4,,10
.p2align 3
.L45:
addl %eax, %eax
cmpl %eax, %edx
jg .L45
cmpl $1073741823, %eax
movl $1073741823, %ebx
movq 0(%rbp), %rdi
cmovle %eax, %ebx
movslq %ebx, %rsi
call repalloc@PLT
movl %ebx, 12(%rbp)
movq %rax, 0(%rbp)
.L28:
popq %rbx
.cfi_remember_state
.cfi_def_cfa_offset 24
popq %rbp
.cfi_def_cfa_offset 16
popq %r12
.cfi_def_cfa_offset 8
ret
.L46:
.cfi_restore_state
movl $342, %edx
leaq .LC0(%rip), %rsi
leaq .LC2(%rip), %rdi
call ExceptionalCondition@PLT
.cfi_endproc
.section .text.unlikely
.cfi_startproc
.type enlargeStringInfo.cold, @function
enlargeStringInfo.cold:
.LFSB112:
.L43:
.cfi_def_cfa_offset 32
.cfi_offset 3, -32
.cfi_offset 6, -24
.cfi_offset 12, -16
xorl %esi, %esi
movl $21, %edi
call errstart_cold@PLT
testb %al, %al
je .L32
movl $261, %edi
call errcode@PLT
movl $1073741823, %esi
leaq .LC5(%rip), %rdi
xorl %eax, %eax
call errmsg@PLT
movl 8(%rbp), %esi
movl %r12d, %edx
xorl %eax, %eax
leaq .LC6(%rip), %rdi
call errdetail@PLT
leaq __func__.5254(%rip), %rdx
movl $360, %esi
leaq .LC0(%rip), %rdi
call errfinish@PLT
.L32:
call abort@PLT
.L42:
xorl %esi, %esi
movl $21, %edi
call errstart_cold@PLT
testb %al, %al
je .L32
movl %r12d, %esi
leaq .LC4(%rip), %rdi
xorl %eax, %eax
call errmsg_internal@PLT
leaq __func__.5254(%rip), %rdx
movl $351, %esi
leaq .LC0(%rip), %rdi
call errfinish@PLT
jmp .L32
.cfi_endproc
.LFE112:
.text
.size enlargeStringInfo, .-enlargeStringInfo
.section .text.unlikely
.size enlargeStringInfo.cold, .-enlargeStringInfo.cold
.LCOLDE7:
.text
.LHOTE7:
.p2align 4
.globl appendStringInfo
.type appendStringInfo, @function
appendStringInfo:
.LFB105:
.cfi_startproc
endbr64
pushq %r14
.cfi_def_cfa_offset 16
.cfi_offset 14, -16
pushq %r13
.cfi_def_cfa_offset 24
.cfi_offset 13, -24
pushq %r12
.cfi_def_cfa_offset 32
.cfi_offset 12, -32
movq %rsi, %r12
pushq %rbp
.cfi_def_cfa_offset 40
.cfi_offset 6, -40
pushq %rbx
.cfi_def_cfa_offset 48
.cfi_offset 3, -48
movq %rdi, %rbx
subq $208, %rsp
.cfi_def_cfa_offset 256
movq %rdx, 48(%rsp)
movq %rcx, 56(%rsp)
movq %r8, 64(%rsp)
movq %r9, 72(%rsp)
testb %al, %al
je .L48
movaps %xmm0, 80(%rsp)
movaps %xmm1, 96(%rsp)
movaps %xmm2, 112(%rsp)
movaps %xmm3, 128(%rsp)
movaps %xmm4, 144(%rsp)
movaps %xmm5, 160(%rsp)
movaps %xmm6, 176(%rsp)
movaps %xmm7, 192(%rsp)
.L48:
movq %fs:40, %rax
movq %rax, 24(%rsp)
xorl %eax, %eax
movq %rsp, %r13
call __errno_location@PLT
movl (%rax), %r14d
movq %rax, %rbp
jmp .L50
.p2align 4,,10
.p2align 3
.L53:
movq %rbx, %rdi
call enlargeStringInfo
.L50:
movl %r14d, 0(%rbp)
movq %r12, %rsi
movq %r13, %rdx
movq %rbx, %rdi
leaq 256(%rsp), %rax
movl $16, (%rsp)
movq %rax, 8(%rsp)
leaq 32(%rsp), %rax
movl $48, 4(%rsp)
movq %rax, 16(%rsp)
call appendStringInfoVA
movl %eax, %esi
testl %eax, %eax
jne .L53
movq 24(%rsp), %rax
xorq %fs:40, %rax
jne .L54
addq $208, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 48
popq %rbx
.cfi_def_cfa_offset 40
popq %rbp
.cfi_def_cfa_offset 32
popq %r12
.cfi_def_cfa_offset 24
popq %r13
.cfi_def_cfa_offset 16
popq %r14
.cfi_def_cfa_offset 8
ret
.L54:
.cfi_restore_state
call __stack_chk_fail@PLT
.cfi_endproc
.LFE105:
.size appendStringInfo, .-appendStringInfo
.p2align 4
.globl appendStringInfoChar
.type appendStringInfoChar, @function
appendStringInfoChar:
.LFB108:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movl %esi, %ebp
pushq %rbx
.cfi_def_cfa_offset 24
.cfi_offset 3, -24
movq %rdi, %rbx
subq $8, %rsp
.cfi_def_cfa_offset 32
movslq 8(%rdi), %rax
leal 1(%rax), %edx
cmpl 12(%rdi), %edx
jge .L58
.L56:
movq (%rbx), %rdx
movb %bpl, (%rdx,%rax)
movl 8(%rbx), %eax
movq (%rbx), %rdx
addl $1, %eax
movl %eax, 8(%rbx)
cltq
movb $0, (%rdx,%rax)
addq $8, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 24
popq %rbx
.cfi_def_cfa_offset 16
popq %rbp
.cfi_def_cfa_offset 8
ret
.p2align 4,,10
.p2align 3
.L58:
.cfi_restore_state
movl $1, %esi
call enlargeStringInfo
movslq 8(%rbx), %rax
jmp .L56
.cfi_endproc
.LFE108:
.size appendStringInfoChar, .-appendStringInfoChar
.p2align 4
.globl appendStringInfoSpaces
.type appendStringInfoSpaces, @function
appendStringInfoSpaces:
.LFB109:
.cfi_startproc
endbr64
testl %esi, %esi
jg .L65
ret
.p2align 4,,10
.p2align 3
.L65:
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rdi, %rbp
pushq %rbx
.cfi_def_cfa_offset 24
.cfi_offset 3, -24
movl %esi, %ebx
subq $8, %rsp
.cfi_def_cfa_offset 32
call enlargeStringInfo
movslq 8(%rbp), %rdi
movslq %ebx, %rdx
addq 0(%rbp), %rdi
movl $32, %esi
call memset@PLT
addl 8(%rbp), %ebx
movq 0(%rbp), %rax
movl %ebx, 8(%rbp)
movslq %ebx, %rbx
movb $0, (%rax,%rbx)
addq $8, %rsp
.cfi_def_cfa_offset 24
popq %rbx
.cfi_def_cfa_offset 16
popq %rbp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE109:
.size appendStringInfoSpaces, .-appendStringInfoSpaces
.p2align 4
.globl appendBinaryStringInfo
.type appendBinaryStringInfo, @function
appendBinaryStringInfo:
.LFB110:
.cfi_startproc
endbr64
pushq %r12
.cfi_def_cfa_offset 16
.cfi_offset 12, -16
pushq %rbp
.cfi_def_cfa_offset 24
.cfi_offset 6, -24
pushq %rbx
.cfi_def_cfa_offset 32
.cfi_offset 3, -32
testq %rdi, %rdi
je .L69
movq %rdi, %rbp
movq %rsi, %r12
movl %edx, %ebx
movl %edx, %esi
call enlargeStringInfo
movslq 8(%rbp), %rdi
movslq %ebx, %rdx
addq 0(%rbp), %rdi
movq %r12, %rsi
call memcpy@PLT
addl 8(%rbp), %ebx
movq 0(%rbp), %rax
movl %ebx, 8(%rbp)
movslq %ebx, %rbx
movb $0, (%rax,%rbx)
popq %rbx
.cfi_remember_state
.cfi_def_cfa_offset 24
popq %rbp
.cfi_def_cfa_offset 16
popq %r12
.cfi_def_cfa_offset 8
ret
.L69:
.cfi_restore_state
movl $283, %edx
leaq .LC0(%rip), %rsi
leaq .LC3(%rip), %rdi
call ExceptionalCondition@PLT
.cfi_endproc
.LFE110:
.size appendBinaryStringInfo, .-appendBinaryStringInfo
.p2align 4
.globl appendStringInfoString
.type appendStringInfoString, @function
appendStringInfoString:
.LFB107:
.cfi_startproc
endbr64
pushq %r12
.cfi_def_cfa_offset 16
.cfi_offset 12, -16
movq %rdi, %r12
movq %rsi, %rdi
pushq %rbp
.cfi_def_cfa_offset 24
.cfi_offset 6, -24
movq %rsi, %rbp
subq $8, %rsp
.cfi_def_cfa_offset 32
call strlen@PLT
addq $8, %rsp
.cfi_def_cfa_offset 24
movq %rbp, %rsi
movq %r12, %rdi
popq %rbp
.cfi_def_cfa_offset 16
movq %rax, %rdx
popq %r12
.cfi_def_cfa_offset 8
jmp appendBinaryStringInfo
.cfi_endproc
.LFE107:
.size appendStringInfoString, .-appendStringInfoString
.p2align 4
.globl appendBinaryStringInfoNT
.type appendBinaryStringInfoNT, @function
appendBinaryStringInfoNT:
.LFB111:
.cfi_startproc
endbr64
pushq %r12
.cfi_def_cfa_offset 16
.cfi_offset 12, -16
pushq %rbp
.cfi_def_cfa_offset 24
.cfi_offset 6, -24
pushq %rbx
.cfi_def_cfa_offset 32
.cfi_offset 3, -32
testq %rdi, %rdi
je .L75
movq %rdi, %rbx
movl %edx, %ebp
movq %rsi, %r12
movl %edx, %esi
call enlargeStringInfo
movslq 8(%rbx), %rdi
movslq %ebp, %rdx
addq (%rbx), %rdi
movq %r12, %rsi
call memcpy@PLT
addl %ebp, 8(%rbx)
popq %rbx
.cfi_remember_state
.cfi_def_cfa_offset 24
popq %rbp
.cfi_def_cfa_offset 16
popq %r12
.cfi_def_cfa_offset 8
ret
.L75:
.cfi_restore_state
movl $309, %edx
leaq .LC0(%rip), %rsi
leaq .LC3(%rip), %rdi
call ExceptionalCondition@PLT
.cfi_endproc
.LFE111:
.size appendBinaryStringInfoNT, .-appendBinaryStringInfoNT
.p2align 4
.globl destroyStringInfo
.type destroyStringInfo, @function
destroyStringInfo:
.LFB113:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movl 12(%rdi), %eax
testl %eax, %eax
je .L79
movq %rdi, %rbp
movq (%rdi), %rdi
call pfree@PLT
movq %rbp, %rdi
popq %rbp
.cfi_remember_state
.cfi_def_cfa_offset 8
jmp pfree@PLT
.L79:
.cfi_restore_state
movl $412, %edx
leaq .LC0(%rip), %rsi
leaq .LC2(%rip), %rdi
call ExceptionalCondition@PLT
.cfi_endproc
.LFE113:
.size destroyStringInfo, .-destroyStringInfo
.section .rodata
.align 16
.type __func__.5254, @object
.size __func__.5254, 18
__func__.5254:
.string "enlargeStringInfo"
.ident "GCC: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0"
.section .note.GNU-stack,"",@progbits
.section .note.gnu.property,"a"
.align 8
.long 1f - 0f
.long 4f - 1f
.long 5
0:
.string "GNU"
1:
.align 8
.long 0xc0000002
.long 3f - 2f
2:
.long 0x3
3:
.align 8
4:
