Re: [PATCH] Small optimization across postgres (remove strlen duplicate usage)

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Small optimization across postgres (remove strlen duplicate usage)
Date: 2020-04-19 22:00:28
Message-ID: CAApHDvo5rrUpOzQZogwEV5ZNteE4bTZNbWN4WUFza8oinGxy0A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 20 Apr 2020 at 09:38, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> The cases where Ranier proposes to replace strlen(foo) == 0
> with a test on foo[0] do seem like wins, though. Asking for
> the full string length to be computed is more computation than
> necessary, and it's less clear that the compiler could be
> expected to save you from that. Anyway there's a coding style
> proposition that we should be doing this consistently, and
> certainly lots of places do do this without using strlen().

Looking at https://godbolt.org/z/6XsjbA it seems like GCC is pretty
good at getting rid of the strlen call even at -O0. It takes -O1 for
clang to use it and -O2 for icc.

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2020-04-19 22:07:22 v13: Performance regression related to FORTIFY_SOURCE
Previous Message Tom Lane 2020-04-19 21:38:03 Re: [PATCH] Small optimization across postgres (remove strlen duplicate usage)