Re: A micro-optimisation for walkdir() - Mailing list pgsql-hackers

From Andres Freund
Subject Re: A micro-optimisation for walkdir()
Date
Msg-id 20200904214510.uoky67sf3pfz6gln@alap3.anarazel.de
Whole thread Raw
In response to Re: A micro-optimisation for walkdir()  (Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>)
Responses Re: A micro-optimisation for walkdir()  (Thomas Munro <thomas.munro@gmail.com>)
List pgsql-hackers
Hi,

On 2020-09-02 17:51:27 +0200, Juan José Santamaría Flecha wrote:
> Win32 could also benefit from this micro-optimisation if we expanded the
> dirent port to include d_type. Please find attached a patch that does
> so
.
>      }
>      strcpy(d->ret.d_name, fd.cFileName);    /* Both strings are MAX_PATH long */
>      d->ret.d_namlen = strlen(d->ret.d_name);
> +    /*
> +     * The only identifed types are: directory, regular file or symbolic link.
> +     * Errors are treated as a file type that could not be determined.
> +     */
> +    attrib = GetFileAttributes(d->ret.d_name);
> +    if (attrib == INVALID_FILE_ATTRIBUTES)
> +        d->ret.d_type = DT_UNKNOWN;
> +    else if ((attrib & FILE_ATTRIBUTE_DIRECTORY) != 0)
> +        d->ret.d_type = DT_DIR;
> +    else if ((attrib & FILE_ATTRIBUTE_REPARSE_POINT) != 0)
> +        d->ret.d_type = DT_LNK;
> +    else
> +        d->ret.d_type = DT_REG;
>  
>      return &d->ret;
>  }

Is this really an optimization? The benefit of Thomas' patch is that
that information sometimes already is there. But here you're doing a
separate lookup with GetFileAttributes()?

What am I missing?

Greetings,

Andres Freund



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Questionable ping logic in LogicalRepApplyLoop
Next
From: Alvaro Herrera
Date:
Subject: Re: A micro-optimisation for walkdir()