On Wed, 25 Nov 2026 at 22:43, Tom Lane <[email protected]> wrote:
>
> I wrote:
> > I wonder whether this would be a net negative for many use-cases.
> > Creating and dropping a memory context is hardly free.  Have you
> > done any performance measurements on cases that don't eat enough
> > memory to be OOM hazards?
>
> I did this simple test:
>
> \timing on
> do $$
> declare arr text[] default array_fill(''::text, ARRAY[50]);
> begin
>   for i in 1..1000000 loop
>     perform xmlelement(name a, arr);
>   end loop;
> end$$;
>
> With HEAD this takes about 6400ms for me, with the patch
> about 6700ms.  (These numbers are in an assert-enabled
> build, so take them with a grain of salt.)  That seems
> like it's not really enough of a hit to justify contorting
> the code, so consider this objection withdrawn.
>
> Another thing I noticed is that we are doing the type-output
> function lookup over again for each array element, though
> with some refactoring we could do it just once.  Since that
> lookup is skipped for "bool" elements, I compared
>
> regression=# select length(xmlelement(name a, array_fill(true,
> ARRAY[16000000]))::text);
>   length
> -----------
>  368000007
> (1 row)
>
> Time: 1196.610 ms (00:01.197)
> regression=# select length(xmlelement(name a, array_fill(''::text,
> ARRAY[16000000]))::text);
>   length
> -----------
>  304000007
> (1 row)
>
> Time: 2005.366 ms (00:02.005)
>
> Now the time taken by textout is not zero, but it still looks like
> close to 50% of the runtime is going into those repeat lookups.
> Maybe that's enough to worry about?
>
>                         regards, tom lane

>From my testing, it also turns out impact is measurable.
I used the following setup:

    CREATE TEMP TABLE xml_perf (v integer[]);
    INSERT INTO xml_perf
    SELECT ARRAY(SELECT g FROM generate_series(1, 8192) AS g);
    ANALYZE xml_perf;

query:
    SELECT xmlelement(name r, v)
    FROM xml_perf CROSS JOIN generate_series(1, 182);

results, 15 runs:

                    median       min       max
    master          150.19    148.69    153.77
    + v2-0001       223.98    221.27    226.66

-- 
Best regards,
Kirill Reshke


Reply via email to