Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH] Do not enable optimizations by default to work-around pycparser issue
Date: Sat, 02 Sep 2017 21:05:31
Message-Id: 1504386325.13997.6.camel@gentoo.org
In Reply to: Re: [gentoo-portage-dev] [PATCH] Do not enable optimizations by default to work-around pycparser issue by Zac Medico
1 W dniu sob, 02.09.2017 o godzinie 12∶19 -0700, użytkownik Zac Medico
2 napisał:
3 > On 09/02/2017 10:46 AM, Michał Górny wrote:
4 > > dev-python/pycparser-2.18+ exposes a design flaw in dev-python/ply that
5 > > makes it unable to work with -OO code. Remove the optimizations from
6 > > Portage shebangs to prevent triggering the issue until we find a proper
7 > > solution for it.
8 > >
9 > > Bug: https://bugs.gentoo.org/628386
10 > > ---
11 > > bin/clean_locks | 2 +-
12 > > bin/dispatch-conf | 2 +-
13 > > bin/ebuild | 2 +-
14 > > bin/emaint | 2 +-
15 > > bin/env-update | 2 +-
16 > > bin/portageq | 2 +-
17 > > tabcheck.py | 2 +-
18 > > 7 files changed, 7 insertions(+), 7 deletions(-)
19 > >
20 > > diff --git a/bin/clean_locks b/bin/clean_locks
21 > > index 13af06197..fb245972f 100755
22 > > --- a/bin/clean_locks
23 > > +++ b/bin/clean_locks
24 > > @@ -1,4 +1,4 @@
25 > > -#!/usr/bin/python -bO
26 > > +#!/usr/bin/python -b
27 >
28 > The diff shows -O, but the commit messages says -OO, so which one is it really?
29
30 Yes, it's a curious problem. -OO is the one breaking it but py<3.5 seems
31 to be happy to load -OO files with -O:
32
33 $ python2.7 -O -c 'import pycparser; print(pycparser.__file__)'
34 /usr/lib64/python2.7/site-packages/pycparser/c_parser.py:20: RuntimeWarning: parsing methods must have __doc__ for pycparser to work properly
35 class CParser(PLYParser):
36 /usr/lib64/python2.7/site-packages/pycparser/__init__.pyo
37
38 $ python3.4 -O -c 'import pycparser; print(pycparser.__cached__)'
39 /usr/lib64/python3.4/site-packages/pycparser/c_parser.py:20: RuntimeWarning: parsing methods must have __doc__ for pycparser to work properly
40 class CParser(PLYParser):
41 /usr/lib64/python3.4/site-packages/pycparser/__pycache__/__init__.cpython-34.pyo
42
43 This doesn't seem to be the case anymore for py3.5+:
44
45 $ python3.5 -O -c 'import pycparser; print(pycparser.__cached__)'
46 /usr/lib64/python3.5/site-packages/pycparser/__pycache__/__init__.cpython-35.opt-1.pyc
47
48 > Are we sure that it's worth it to load all of the __doc__ strings into
49 > memory, given that we have alternative implementations for everything
50 > that pycrypto provides?
51
52 I dare say that if -O can cause completely random total breakage, then
53 we shouldn't risk doing that for the sake of some minor memory savings.
54 It's not a case of 'support for pycryptodome' vs '1M memory saving'.
55 It's a case of 'loading random module can wreak total havoc in Portage'.
56
57 > For the record, I measure an increase of from 30248K to 31504K for -OO vs without when
58 > importing all portage modules, tested as follows:
59 >
60 > $ python3.6 -OO pym/portage/tests/runTests.py pym/portage/tests/lint/test_import_modules.py
61 > testImportModules (portage.tests.lint.test_import_modules.ImportModulesTestCase) ... 30248
62 >
63 > $ python3.6 -O pym/portage/tests/runTests.py pym/portage/tests/lint/test_import_modules.py
64 > testImportModules (portage.tests.lint.test_import_modules.ImportModulesTestCase) ... 31468
65 >
66 > $ python3.6 pym/portage/tests/runTests.py pym/portage/tests/lint/test_import_modules.py
67 > testImportModules (portage.tests.lint.test_import_modules.ImportModulesTestCase) ... 31504
68 >
69 > Using this patch:
70 >
71 > diff --git a/pym/portage/tests/lint/test_import_modules.py b/pym/portage/tests/lint/test_import_modules.py
72 > index fcdcb3b33..6350197eb 100644
73 > --- a/pym/portage/tests/lint/test_import_modules.py
74 > +++ b/pym/portage/tests/lint/test_import_modules.py
75 > @@ -2,6 +2,7 @@
76 > # Distributed under the terms of the GNU General Public License v2
77 >
78 > from itertools import chain
79 > +import resource
80 >
81 > from portage.const import PORTAGE_PYM_PATH, PORTAGE_PYM_PACKAGES
82 > from portage.tests import TestCase
83 > @@ -24,6 +25,7 @@ class ImportModulesTestCase(TestCase):
84 > if mod not in expected_failures:
85 > self.assertTrue(False, "failed to import '%s': %s" % (mod, e))
86 > del e
87 > + print(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
88 >
89 > def _iter_modules(self, base_dir):
90 > for parent, dirs, files in os.walk(base_dir):
91 >
92
93 --
94 Best regards,
95 Michał Górny

Replies