Subject: bug#26193: closed (Re: bug#26193: [0-9] versus [[:digit:]])

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 23 Mar 2017 01:58:02 +0000

Your bug report

#26193: [0-9] versus [[:digit:]]

which was filed against the grep package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
26193: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=26193
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#26193: [0-9] versus [[:digit:]]
From: Jim Meyering <[email-masked]>
To: "John P. Linderman" <[email-masked]>
Cc: [email-masked], Paul Eggert <[email-masked]>, Gnulib bugs <[email-masked]>
Date: Wed, 22 Mar 2017 18:57:05 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

On Wed, Mar 22, 2017 at 2:58 PM, John P. Linderman <[email-masked]> wrote:
> I used to use LC_ALL=C, but, as I vaguely recall, it got in the way of
> dealing with UNICODE. I tried a couple LC values aimed at UNICODE and the
> US, but something always went pear-shaped. I finally give up. I am perfectly
> happy to suffer a tiny bit of performance, to have most things work without
> thinking. A factor of 6, or 35, is not tiny, since I use grep and friends
> intensely. That's how I discovered the performance problem to begin with.
> Anyway, thank you for fixing my problem. I suspect that many of us pioneers
> (using UNIX since 1973) have '[0-9]' wired into our fingers.
>
> On Wed, Mar 22, 2017 at 2:01 PM, Paul Eggert <[email-masked]> wrote:
>>
>> On 03/22/2017 05:44 AM, John P. Linderman wrote:
>>>
>>> That puts the runtimes on equal footing:
>>>
>> In my measurements, P[0-9] is still a tiny bit slower if one is using
>> glibc regex, due to a performance problem in glibc. You can work around it
>> by configuring --with-included-regex. It's probably not worth worrying
>> about, though.
>>
>> By the way, using LC_ALL=C should help avoid performance problems like
>> these in the future, if all you're doing is something where single-byte
>> pattern matching suffices.

I've just pulled that gnulib change into grep's repository with the
attached, along with a NEWS update:
From e2b7253524b92c316e2f51fc1998b8595554e777 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email-masked]>
Date: Tue, 21 Mar 2017 20:19:49 -0700
Subject: [PATCH] gnulib: update to latest for dfa [0-9] performance
 improvement

This pulls in the following change that is very relevant to grep:

    commit 6afba02d7869d39ed7f61981045ddbdcb2814101
    Author: Paul Eggert <[email-masked]>
    dfa: make [0-9] faster in non-C locales

* gnulib: Update to latest.
* NEWS (Improvements): Describe the effect on grep.
---
 NEWS   | 5 +++++
 gnulib | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index c387aef..0a8cbbc 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ GNU grep NEWS                                    -*- outline -*-

 * Noteworthy changes in release ?.? (????-??-??) [?]

+** Improvements
+
+  grep '[0-9]' is now just as fast as grep '[[:digit:]]' when run
+  in a multi-byte locale.  Before, it was several times slower.
+
 ** Changes in behavior

   The following changes affect only MS-Windows platforms.  First, the
diff --git a/gnulib b/gnulib
index fad631e..bd78ca3 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit fad631e74dd6c1f0c7fadd99bad1b4b732f6eeb8
+Subproject commit bd78ca3d3d7b5ec2679af1ea3d23e278c81e01d8
-- 
2.9.3

Subject: [0-9] versus [[:digit:]]
From: "John P. Linderman" <[email-masked]>
To: [email-masked]
Date: Mon, 20 Mar 2017 11:34:05 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

In what follows, file "conjectures" is a 6 billion bytes file in which each
line contains at most one letter P, and few (see output) have a digit
following a P. "rusage" is just a home-brew resource usage summary command.

  rusage egrep 'P[0-9]' conjectures > xxx
695.55 real 688.33 user 2.40 sys 0 pf 186 pr 0 sw 0 rb 8 wb 1 vcx 19206 icx
2488 mx 0 ix 0 id 0 is

  cat xxx
A[21]=11{11}:22<LP3

  rusage egrep 'P[[:digit:]]' conjectures > xxx
14.88 real 13.36 user 1.43 sys 0 pf 186 pr 0 sw 0 rb 8 wb 0 vcx 516 icx
2500 mx 0 ix 0 id 0 is

  cat xxx
A[21]=11{11}:22<LP3

Using what is to me the more obvious [0-9] pattern takes almost 50 times as
long as using the [[:digit:]] pattern. Seems very strange.

  grep --version
grep (GNU grep) 2.25
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html
>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/
grep.git/tree/AUTHORS>.

  uname -a
Linux jpl 4.4.0-66-generic #87-Ubuntu SMP Fri Mar 3 15:29:05 UTC 2017
x86_64 x86_64 x86_64 GNU/Linux