[Modeling-users] Performance Boost
Status: Abandoned
Brought to you by:
sbigaret
|
From: Yannick G. <yan...@sa...> - 2003-05-26 18:37:35
|
=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
After tweaking on my side to find a better implementation of DOM in
terms of performance I found that xml.dom.minidom.parseString() is
near 3 times faster than Sax2.Reader().fromStream().=20
Since Modeling uses Sax2 in ModelSet to parse the XML model you might
want to try this patch :=20
diff -u -r ModelingCore-0.9-pre-7.1/Modeling/Attribute.py=20
ModelingCore-minidom/Modeling/Attribute.py
=2D --- ModelingCore-0.9-pre-7.1/Modeling/Attribute.py 2003-04-22=20
05:31:56.000000000 -0400
+++ ModelingCore-minidom/Modeling/Attribute.py 2003-05-26 14:32:08.00000000=
0=20
=2D -0400
@@ -534,7 +534,7 @@
"""
_attrDict=3Dself.xmlAttributesDict()
_attrNode=3DaNode.attributes
=2D - attributes=3D[attr.name for attr in aNode.attributes]
+ attributes=3Dmap(lambda attrPair:attrPair[0], _attrNode.items())
=20
# Now we must make sure that the type is initialized BEFORE the default
# value is set --> we simply make sure that this will be the first one
diff -u -r ModelingCore-0.9-pre-7.1/Modeling/Entity.py=20
ModelingCore-minidom/Modeling/Entity.py
=2D --- ModelingCore-0.9-pre-7.1/Modeling/Entity.py 2003-04-22 05:31:56.000=
000000=20
=2D -0400
+++ ModelingCore-minidom/Modeling/Entity.py 2003-05-26 14:31:19.000000000=20
=2D -0400
@@ -1260,8 +1260,10 @@
raise ValueError, 'Ooops, parameter phase should be 1 or 2!'
_attrDict=3Dself.xmlAttributesDict()
_attrNode=3DaNode.attributes
=2D - for attributeName in [attr.name for attr in aNode.attributes]:
+
+ _attrNames =3D map(lambda attrPair:attrPair[0], _attrNode.items())
+ for attributeName in _attrNames:
# Iterate on attributes which are in the xml
attrType=3Dself.xmlAttributeType(attributeName)
set=3Dself.xmlSetAttribute(attributeName)
=20
diff -u -r ModelingCore-0.9-pre-7.1/Modeling/Model.py=20
ModelingCore-minidom/Modeling/Model.py
=2D --- ModelingCore-0.9-pre-7.1/Modeling/Model.py 2003-04-22 05:31:56.0000=
00000=20
=2D -0400
+++ ModelingCore-minidom/Modeling/Model.py 2003-05-26 14:30:38.000000000 -0=
400
@@ -242,7 +242,9 @@
raise XMLImportError, "Cannot initialize a non-empty model"=20
_attrDict=3Dself.xmlAttributesDict()
_attrNode=3DaNode.attributes
=2D - for attributeName in [attr.name for attr in aNode.attributes]:
+
+ _attrNames =3D map(lambda attrPair:attrPair[0], _attrNode.items())
+ for attributeName in _attrNames:
attrType=3Dself.xmlAttributeType(attributeName)
set=3Dself.xmlSetAttribute(attributeName)
value=3Dxpath.Evaluate(attrType+'(@'+attributeName+')',=20
contextNode=3DaNode)
diff -u -r ModelingCore-0.9-pre-7.1/Modeling/ModelSet.py=20
ModelingCore-minidom/Modeling/ModelSet.py
=2D --- ModelingCore-0.9-pre-7.1/Modeling/ModelSet.py 2003-02-28=20
18:21:26.000000000 -0500
+++ ModelingCore-minidom/Modeling/ModelSet.py 2003-05-26 14:11:26.000000000=
=20
=2D -0400
@@ -54,6 +54,7 @@
NC=3DNotificationCenter
import ClassDescription
import types
+from xml.dom.minidom import parseString
=20
from logging import error
=20
@@ -143,14 +144,13 @@
#import pdb; pdb.set_trace()
if xmlSource.has_key('string'):
encoding=3DautoDetectXMLEncoding(xmlSource['string'])
=2D - reader=3DSax2.Reader()
=2D - xmldoc=3Dreader.fromString(xmlSource['string'])
+ xmldoc=3DparseString(xmlSource['string'])
elif xmlSource.has_key('file'):
f=3Dopen(xmlSource['file'], 'rb')
encoding=3DautoDetectXMLEncoding(f.read())
f.close()
=2D - reader=3DSax2.Reader()
=2D - xmldoc=3Dreader.fromStream(xmlSource['file'])
+ print xmlSource['file']
+ xmldoc=3DparseString(open(xmlSource['file']).read())
else:
raise AttributeError, "xmlSource parameter has no key 'string' or=20
'file'"
# Do we have only one model? _TBD: a DTD should be responsible for thi=
s!
diff -u -r ModelingCore-0.9-pre-7.1/Modeling/XMLutils.py=20
ModelingCore-minidom/Modeling/XMLutils.py
=2D --- ModelingCore-0.9-pre-7.1/Modeling/XMLutils.py 2003-03-14=20
06:40:10.000000000 -0500
+++ ModelingCore-minidom/Modeling/XMLutils.py 2003-05-26 14:07:49.000000000=
=20
=2D -0400
@@ -50,11 +50,6 @@
pass
=20
try:
=2D - from xml.dom.ext.reader import Sax2
=2D - from xml.dom.ext.reader.Sax import FromXmlStream
=2D -except:
=2D - raise 'ImportError', 'PyXML is not installed'
=2D -try:
from xml import xpath
except:
raise 'ImportError', 'XPath is not installed'
=2D --=20
Yannick Gingras
Byte Gardener, Savoir-faire Linux inc.
(514) 276-5468
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE+0l+Irhy5Fqn/MRARAs+tAJ4kl5i0Mb39egSO4MlWxsb+wEUqXgCeNcrX
9LwzMZtbamAuUv0XWppEGrw=3D
=3DJ7Rj
=2D----END PGP SIGNATURE-----
|