GNU bug report logs - #70231
Performance issue on sort with zero-sized pseudo files

Previous Next

Package: coreutils;

Reported by: Takashi Kusumi <tkusumi <at> zlab.co.jp>

Date: Sat, 6 Apr 2024 06:39:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Takashi Kusumi <tkusumi <at> zlab.co.jp>
To: bug-coreutils <at> gnu.org
Subject: Performance issue on sort with zero-sized pseudo files
Date: Sat, 6 Apr 2024 11:52:17 +0900
[Message part 1 (text/plain, inline)]
Hi,

I have found a performance issue with the sort command when used on
pseudo files with zero size. For instance, sorting `/proc/kallsyms`, as
demonstrated below, takes significantly longer than executing with
`cat`, generating numerous temporary files. I confirmed this issue on
v8.32 as well as on commit 8f3989d in the master branch.

  $ time cat /proc/kallsyms | sort > /dev/null
  real    0m0.954s
  user    0m0.873s
  sys     0m0.096s

  $ time sort /proc/kallsyms > /dev/null
  real    0m8.555s
  user    0m3.367s
  sys     0m5.064s

  $ strace -e trace=openat sort /proc/kallsyms 2>&1 > /dev/null \
    | grep /tmp/sort | head -100
  ...
  openat(AT_FDCWD, "/tmp/sortM6Y6Y1", ...
  openat(AT_FDCWD, "/tmp/sortPrHKMG", ...

  $ strace -e trace=openat -c sort /proc/kallsyms > /dev/null
  % time     seconds  usecs/call     calls    errors syscall
  ------ ----------- ----------- --------- --------- ----------------
  100.00    6.419777          19    333258         8 openat
  ------ ----------- ----------- --------- --------- ----------------
  100.00    6.419777          19    333258         8 total

It appears that the buffer size allocated for pseudo files with zero
size is insufficient, likely because it is based on their file size,
which is zero. As seen in the attached patch, I think using
`INPUT_FILE_SIZE_GUESS` to calculate the buffer size when the file size
is zero would resolve this issue.

Best regards,
Takashi Kusumi
[0001-sort-fix-performance-issue-on-zero-sized-pseudo-file.patch (text/plain, attachment)]

This bug report was last modified 1 year and 39 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.