[pypy-commit] pypy default: Use a cache to avoid parsing the same cdecl again and again, which is done

antocuni pypy.commits at gmail.com
Fri Dec 6 10:33:31 EST 2019


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r98242:317104f1b067
Date: 2019-12-06 16:32 +0100
http://bitbucket.org/pypy/pypy/changeset/317104f1b067/

Log:	Use a cache to avoid parsing the same cdecl again and again, which
	is done e.g. for all the various cts.cast(...) around. On my
	machine, with this patch the time needed to run a single cpyext test
	goes from ~54s to ~29s

diff --git a/pypy/module/cpyext/cparser.py b/pypy/module/cpyext/cparser.py
--- a/pypy/module/cpyext/cparser.py
+++ b/pypy/module/cpyext/cparser.py
@@ -705,6 +705,7 @@
         self.struct_typedefs = {}
         self._handled = set()
         self._frozen = False
+        self._cdecl_type_cache = {} # {cdecl: TYPE} cache
         if includes is not None:
             for header in includes:
                 self.include(header)
@@ -840,6 +841,14 @@
             raise NotImplementedError
 
     def gettype(self, cdecl):
+        try:
+            return self._cdecl_type_cache[cdecl]
+        except KeyError:
+            result = self._real_gettype(cdecl)
+            self._cdecl_type_cache[cdecl] = result
+            return result
+
+    def _real_gettype(self, cdecl):
         obj = self.ctx.parse_type(cdecl)
         result = self.convert_type(obj)
         if isinstance(result, DelayedStruct):


More information about the pypy-commit mailing list