Issue1665693

classification
Title: Optimized types.java
Type: Severity: normal
Components: None Versions:
Milestone:
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, hsk0
Priority: normal Keywords: patch

Created on 2007-02-21.23:36:08 by hsk0, last changed 2007-02-22.14:09:13 by hsk0.

Messages
msg2656 (view) Author: howard kapustein (hsk0) Date: 2007-02-21.23:36:08
classDictInit() creates identical objects multiple times; this patch precalculates these redundancies:

types.java contains patch 1665260 (the patch for [1661679] Invalid types.UnicodeType)

typeshkopt.java is the optimized form

--- types.java	2007-02-21 09:29:24.581942400 -0500
+++ typeshkpot.java	2007-02-21 09:32:43.356472100 -0500
@@ -13,48 +13,53 @@

     // xxx change some of these
     public static void classDictInit(PyObject dict) {
+        // Precalculate some reused types
+        PyObject PyType_PyDictionary = PyType.fromClass(PyDictionary.class);
+        PyObject PyType_PyFunction = PyType.fromClass(PyFunction.class);
+        PyObject PyType_PyMethod = PyType.fromClass(PyMethod.class);
+        PyObject PyType_PyString = PyType.fromClass(PyString.class);
+        PyObject PyType_PyUnicode = PyType.fromClass(PyUnicode.class);
+
+        // Let's do it...
         dict.__setitem__("ArrayType", PyType.fromClass(PyArray.class));
         dict.__setitem__("BuiltinFunctionType",
                          PyType.fromClass(PyReflectedFunction.class));
         dict.__setitem__("BuiltinMethodType",
-                         PyType.fromClass(PyMethod.class));
+                         PyType_PyMethod);
         dict.__setitem__("ClassType", PyType.fromClass(PyClass.class));
         dict.__setitem__("CodeType", PyType.fromClass(PyCode.class));
         dict.__setitem__("ComplexType", PyType.fromClass(PyComplex.class));
-        dict.__setitem__("DictType", PyType.fromClass(PyDictionary.class));
-        dict.__setitem__("DictionaryType",
-                         PyType.fromClass(PyDictionary.class));
+        dict.__setitem__("DictType", PyType_PyDictionary);
+        dict.__setitem__("DictionaryType", PyType_PyDictionary);
         dict.__setitem__("EllipsisType",
                          PyType.fromClass(PyEllipsis.class));
         dict.__setitem__("FileType", PyType.fromClass(PyFile.class));
         dict.__setitem__("FloatType", PyType.fromClass(PyFloat.class));
         dict.__setitem__("FrameType", PyType.fromClass(PyFrame.class));
-        dict.__setitem__("FunctionType",
-                         PyType.fromClass(PyFunction.class));
+        dict.__setitem__("FunctionType", PyType_PyFunction);
         dict.__setitem__("GeneratorType",
                          PyType.fromClass(PyGenerator.class));
         dict.__setitem__("InstanceType",
                          PyType.fromClass(PyInstance.class));
         dict.__setitem__("IntType", PyType.fromClass(PyInteger.class));
-        dict.__setitem__("LambdaType", PyType.fromClass(PyFunction.class));
+        dict.__setitem__("LambdaType", PyType_PyFunction);
         dict.__setitem__("ListType", PyType.fromClass(PyList.class));
         dict.__setitem__("LongType", PyType.fromClass(PyLong.class));
-        dict.__setitem__("MethodType", PyType.fromClass(PyMethod.class));
+        dict.__setitem__("MethodType", PyType_PyMethod);
         dict.__setitem__("ModuleType", PyType.fromClass(PyModule.class));
         dict.__setitem__("NoneType", PyType.fromClass(PyNone.class));
         dict.__setitem__("SliceType", PyType.fromClass(PySlice.class));
-        dict.__setitem__("StringType", PyType.fromClass(PyString.class));
+        dict.__setitem__("StringType", PyType_PyString);
         dict.__setitem__("TracebackType",
                          PyType.fromClass(PyTraceback.class));
         dict.__setitem__("TupleType", PyType.fromClass(PyTuple.class));
         dict.__setitem__("TypeType", PyType.fromClass(PyJavaClass.class));
-        dict.__setitem__("UnboundMethodType",
-                         PyType.fromClass(PyMethod.class));
-        dict.__setitem__("UnicodeType", PyType.fromClass(PyUnicode.class));
+        dict.__setitem__("UnboundMethodType", PyType_PyMethod);
+        dict.__setitem__("UnicodeType", PyType_PyUnicode);
         dict.__setitem__("XRangeType", PyType.fromClass(PyXRange.class));

         dict.__setitem__("StringTypes", new PyTuple(new PyObject[] {
-                PyType.fromClass(PyString.class), PyType.fromClass(PyUnicode.class)
+                         PyType_PyString, PyType_PyUnicode
         }));
     }
 }
msg2657 (view) Author: Charlie Groves (cgroves) Date: 2007-02-22.02:56:09
It's easier to apply and test these things if you attach your patch as a file instead of putting it in your message
msg2658 (view) Author: Charlie Groves (cgroves) Date: 2007-02-22.02:58:59
Actually, what's the difference between this and http://jython.org/patches/1665263  If this is just a revised version of the first patch, it should just be attached to it.
msg2659 (view) Author: howard kapustein (hsk0) Date: 2007-02-22.14:06:05
>It's easier to apply and test these things if you attach your patch as a
>file instead of putting it in your message
Ah. So sorry. First time I submitted a patch this way. I'll attach them from now on.

I don't know why this appears twice. The contents appear identical, just created @ 09:37 and 18:36. I created the earlier one - while having my morning cup of coffee. I don't know how the other one got created. I've closed the other one as a Dupe.

1665260 just fixes types.UnicodeType == <type 'str'> instead of <type 'unicode'>
This patch contains that _AND_ optimizations for the initialization.
If you're happy with the optimization, you can ignore 166260 and just apply this one.

Q: I submitted these as 2 separate patches they're separate issues (fix vs. optimization) that, unfortunately, overlap the same code. I didn't see any comments specifically about this in the patch submission guidelines so I assumed 1-patch-per-issue is preferred, as many projects follow that policy e.g. the Linux kernel. What's preferred for Jython?
msg2660 (view) Author: howard kapustein (hsk0) Date: 2007-02-22.14:09:13
Sorry, I meant I closed _this one_ as the dupe -- this was created by SF for some unknown reason; identical to 1665263 but with a later creation timestamp.
History
Date User Action Args
2007-02-21 23:36:08hsk0create