Robert Haschke added the comment:
Thanks, Josh, for this clarification. What is the suggested mitigation?
Obviously, I need to pass all symbols from my hierarchical dictionary in a
flattend version as a dict to globals. Or do you see another option
Robert Haschke added the comment:
Looks like the list generator is considered as a new nested scope, which
prohibits access to local variables?
This basic expression, passing local symbols only, fails as well:
eval('[abc[i]*abc[i] for i in [0, 1, 2]]', {}, dict(abc=[1, 2, 3]))
New submission from Robert Haschke :
The attached file implements a custom dict-like class (MyDict) as a minimal
example of code I am using in a larger codebase.
Before you ask, why I reimplemented a dict-like object: The real code base
employs a hierarchical dict, referencing recursively to
Robert Haschke added the comment:
Thank you very much for further improving the code. As I understand it, the
trick is to use temporary variables to minimize access time. Learned something
new.
I adapted your patch to python 2.7 again. Now, in python3, the new code is even
faster than the
Robert Haschke added the comment:
I don't see how to further minimize the checks - all of them are required. I
think, the most common uses cases to create a document are appendChild(), which
is not affected, and insertBefore() using the same refChild for a while. In
that case, the patch
Robert Haschke added the comment:
Indeed there is a small slow down for insertion at the beginning.
However, this is simply due to the extra function _index() and thus linear in
the number of insertion operations.
My patch essentially boosts insertions before /any fixed/ node.
If this
Robert Haschke added the comment:
I uploaded a simple example to illustrate the tremendous performance boost.
Obviously, the example exploits the caching improvement as much as possible:
The code assembles a XML document by inserting new nodes before the last one...
These are the timing
Robert Haschke added the comment:
Uploaded a "hg diff" against the recent 2.7 branch of the source repo.
--
Added file: http://bugs.python.org/file43414/minidom.insertBefore.patch
___
Python tracker
<http://bugs.python.o
New submission from Robert Haschke:
Node.insertBefore() has a serious performance issue:
Using self.childNodes.index(refChild) it searches for the correct index in
childNodes where the newChild should be inserted.
However, index() is linear in time w.r.t. the size of childNodes.
Hence, if