public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "terra at gnome dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/99876] New: std::filesystem::absolute is inefficient
Date: Thu, 01 Apr 2021 19:25:22 +0000	[thread overview]
Message-ID: <bug-99876-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99876

            Bug ID: 99876
           Summary: std::filesystem::absolute is inefficient
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: terra at gnome dot org
  Target Milestone: ---

Created attachment 50498
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50498&action=edit
Preprocesses source code

The documentation for std::filesystem::absolute states:

"For POSIX-based operating systems, std::filesystem::absolute(p) is equivalent
to std::filesystem::current_path() / p except for when p is the empty path. "

g++ implements it is way -- that is correct, but wasteful.

If the given filename is already absolute, it should be simply returned.
There is no need to call current_path() which leads to a getcwd syscall.





# /usr/local/products/gcc/10.1.0/bin/g++ -std=gnu++17 -Wall -O2 ttt.C

# strace ./a.out 2>&1 | tail
getcwd("/work/nova7/23232/src", 4096)   = 22
getcwd("/work/nova7/23232/src", 4096)   = 22
getcwd("/work/nova7/23232/src", 4096)   = 22
getcwd("/work/nova7/23232/src", 4096)   = 22
getcwd("/work/nova7/23232/src", 4096)   = 22
getcwd("/work/nova7/23232/src", 4096)   = 22
getcwd("/work/nova7/23232/src", 4096)   = 22
getcwd("/work/nova7/23232/src", 4096)   = 22
exit_group(0)                           = ?
+++ exited with 0 +++

# cat ttt.C
#include <filesystem>

int
main()
{
  std::filesystem::path foo ("/home/welinder");

  for (int i = 0; i < 10000; i++)
    (void)std::filesystem::absolute(foo);
}

# uname -a
Linux monsterd03 5.3.18-lp152.66-default #1 SMP Tue Mar 2 13:18:19 UTC 2021
(73933a3) x86_64 x86_64 x86_64 GNU/Linux

# /usr/local/products/gcc/10.1.0/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/usr/local/products/gcc/10.1.0/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/products/gcc/10.1.0/lib/gcc/x86_64-suse-linux/10.1.0/lto-wrapper
Target: x86_64-suse-linux
Configured with: ../../gcc-10.1.0/configure --enable-languages=c,c++,fortran
--enable-targets=x86_64-suse-linux,i686-suse-linux
--prefix=/usr/local/products/gcc/10.1.0 --with-gnu-as
--with-as=/usr/local/products/gcc/binutils-2.32/bin/as --with-gnu-ld
--with-ld=/usr/local/products/gcc/binutils-2.32/bin/ld --enable-threads=posix
--enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=pool
x86_64-suse-linux
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.1.0 (GCC)

             reply	other threads:[~2021-04-01 19:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-01 19:25 terra at gnome dot org [this message]
2021-04-01 20:39 ` [Bug libstdc++/99876] " redi at gcc dot gnu.org
2021-04-01 20:41 ` redi at gcc dot gnu.org
2021-04-19 10:40 ` redi at gcc dot gnu.org
2021-08-28 11:02 ` redi at gcc dot gnu.org
2021-08-28 11:02 ` redi at gcc dot gnu.org
2021-08-28 12:07 ` cvs-commit at gcc dot gnu.org
2021-10-12 10:59 ` cvs-commit at gcc dot gnu.org
2021-10-12 16:28 ` cvs-commit at gcc dot gnu.org
2021-10-12 16:32 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-99876-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).