Gentoo Archives: gentoo-dev

From: Neil Cahill <ncahill_alt@×××××.com>
To: "gentoo-dev@l.g.o" <gentoo-dev@l.g.o>
Subject: [gentoo-dev] Patch to sys-apps/portage-2.2.7 giving 2% performance increase
Date: Fri, 18 Oct 2013 16:46:29
Message-Id: 1382114778.35123.YahooMailNeo@web171903.mail.ir2.yahoo.com
1 I profiled an execution of "emerge -pv sed" to look for easy ways to increase the speed of that command.  The following 2-line patch gives a 2% reduced run time.  The profile showed that regex matching accounts for 8.3% of the run time, so these updated regular expressions are at least 25% quicker.  I hoped it would help more but it should all add up.
2
3 As I get more time I may look to submit other small improvements.
4
5 As for how the patch works, the version number part of a package name has many options so that part of the regular expression is time consuming.  It was advantageous to use an assertion to visit that part of the expression less often.  Python since 2.4 supports what I've used so this should work on all current versions.
6
7 Thank you.
8 Neil Cahill.
9
10 ### patch ###
11 --- pym/portage/versions.py    2013-09-23 21:59:21.000000000 +0100
12 +++ pym/portage/versions.py    2013-10-08 14:48:11.178441337 +0100
13 @@ -45,8 +45,8 @@
14  # It must not begin with a hyphen,
15  # and must not end in a hyphen followed by one or more digits.
16  _pkg = {
17 -    "dots_disallowed_in_PN": r'[\w+][\w+-]*?',
18 -    "dots_allowed_in_PN":    r'[\w+][\w+.-]*?',
19 +    "dots_disallowed_in_PN": r'[\w+][\w+-]*?(?![\w+])',
20 +    "dots_allowed_in_PN":    r'[\w+][\w+.-]*?(?![\w+.])',
21  }
22  
23  _v = r'(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)'
24 ### end patch ###

Replies