Re: Proposal: add new API to stringinfo

From: Tatsuo Ishii <ishii(at)postgresql(dot)org>
To: dgrowleyml(at)gmail(dot)com
Cc: gurjeet(at)singh(dot)im, pgsql-hackers(at)postgresql(dot)org, michael(at)paquier(dot)xyz, andrew(at)dunslane(dot)net
Subject: Re: Proposal: add new API to stringinfo
Date: 2025-01-06 01:57:23
Message-ID: 20250106.105723.406243349279859124.ishii@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi David,

Thanks for the review.

> On Sun, 5 Jan 2025 at 21:03, Tatsuo Ishii <ishii(at)postgresql(dot)org> wrote:
>> Attached is the v2 patch to reflect above.
>
> A quick review.
>
> I don't see any users of STRINGINFO_SMALL_SIZE, so I question the
> value in defining it.
>
> I think it might be worth adding a comment to initStringInfoExt and
> makeStringInfoExt which mentions the valid ranges of initsize. 1 to
> MaxAllocSize by the looks of it. The reason that it's good to document
> this is that if we ever get any bug reports where some code is passing
> something like 0 as the size, we'll know right away that it's the
> caller's fault rather than the callee.

Agreed.

> I'm also curious if this change has much of a meaningful impact in the
> size of the compiled binary. The macro idea isn't quite how I'd have
> done it as it does mean passing an extra parameter for every current
> callsite. If I were doing this, I'd just have created the new
> functions in stringinfo.c and have the current functions call the new
> external function and rely on the compiler inlining, basically, that's
> the same as what makeStringInfo() does today with initStringInfo().
>
> I'd have done it like:
>
> StringInfo
> makeStringInfo(void)
> {
> return makeStringInfoExt(STRINGINFO_DEFAULT_SIZE);
> }
>
> Using current master, you can see from the following that
> initStringInfo is inlined, despite being an external function. I've no
> reason to doubt the compiler won't do the same for makeStringInfo()
> and makeStringInfoExt().
>
> $ gcc src/common/stringinfo.c -I src/include -O2 -S | cat stringinfo.s
> | grep makeStringInfo -A 10
[snip]
> Note, there is no "call initStringInfo"

I have tried with this direction. See attached v2 patch. In the asm
code I don't see "call makeStringInfoExt" as expected. But I see
"call initStringInfoExt". I assume this is an expected behavior.

$ gcc src/common/stringinfo.c -I src/include -O2 -S; cat stringinfo.s|grep makeStringInfo -A 20
.globl makeStringInfoExt
.type makeStringInfoExt, @function
makeStringInfoExt:
.LFB99:
.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
subq $8, %rsp
.cfi_def_cfa_offset 32
testl %edi, %edi
jle .L11
movl %edi, %ebp
movl $24, %edi
call palloc(at)PLT
movl %ebp, %esi
movq %rax, %rdi
movq %rax, %r12
call initStringInfoExt
--
.size makeStringInfoExt, .-makeStringInfoExt
.p2align 4
.globl makeStringInfo
.type makeStringInfo, @function
makeStringInfo:
.LFB98:
.cfi_startproc
endbr64
pushq %r12
.cfi_def_cfa_offset 16
.cfi_offset 12, -16
movl $24, %edi
call palloc(at)PLT
movl $1024, %esi
movq %rax, %r12
movq %rax, %rdi
call initStringInfoExt
movq %r12, %rax
popq %r12
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE98:
.size makeStringInfo, .-makeStringInfo
.section .rodata.str1.1
.LC2:
.string "str->maxlen != 0"
.text
.p2align 4
.globl resetStringInfo
.type resetStringInfo, @function
resetStringInfo:
.LFB102:
.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:

Best reagards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp

Attachment Content-Type Size
v2-0001-Add-new-StringInfo-APIs-to-allow-callers-to-speci.patch application/octet-stream 4.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sami Imseih 2025-01-06 02:00:16 Re: Vacuum statistics
Previous Message Paul Jungwirth 2025-01-05 23:20:07 Re: Index AM API cleanup