-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faster ElementTree iterating #70061
Comments
Proposed patch refactors and optimize the code for iterating ElementTree. Refactoring and minor optimization makes the code about 30 lines smaller and 2-3% faster. Using a continuous array instead of linked list makes the code up to 40% faster (lxml benchmark was used to measurement). In addition the patch fixes possible issue with owning references. |
Looks technically correct as far as my knowledge of the malloc routines goes. What was the problem with references that you fixed? Maybe with parent_stack_push_new() failure? The main reference counting bug that sticks out to me is with the text and tail elements, because element_get_text() etc return a borrowed reference. It might be good to fix this while you are at it: >>> element = Element("tag")
>>> class Text:
... def __bool__(self):
... element.text = "changed"
... return True
...
>>> element.text = Text()
>>> i = element.itertext()
>>> next(i)
Segmentation fault (core dumped)
[Exit 139] |
Good catch Martin. I missed this case. Following patch fixes it. Other bugs look similar. They presumably can be triggered when remove the element itself during executing the __next__() method. I have no a reproducer though. I don't know wherever it is worth to fix these bugs in maintained releases. |
Thank you for your review Martin. I have opened a separate bpo-25902 for refcount bugs in iteration. Its patch is purposed for all versions, while this issue is for developer version only. |
New changeset 5a5d5268afd5 by Serhiy Storchaka in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: