Python Forum
Effeciency of passing XML tree object as function arguments - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Effeciency of passing XML tree object as function arguments (/thread-438.html)



Effeciency of passing XML tree object as function arguments - sandeepvl - Oct-11-2016

Hi all, 

Is it efficient to pass an object returned by lxml.etree.parse("a.xml") as argument to other functions? Is the object returned a C pointer-like mechanism referring to the in-memory tree representation of XML? Or is it something else? Will it cause any performance issues down the line? I expect the size of the tree when taken in-memory could be around 15 MB. 

I am planning to write multiple functions to process each child node and its sub-child nodes. To each function. I will be passing the object corresponding to child node. 

Thanks
Sandeep


RE: Effeciency of passing XML tree object as function arguments - micseydel - Oct-11-2016

You can think of all Python variables as pointers. Passing parameters won't be a problem. You can test this yourself too, if you'd like, by passing a list to a function, mutating it within the function (without returning it), and observing the side effect outside the function as evidence that the same object was passed around.


RE: Effeciency of passing XML tree object as function arguments - Ofnuts - Oct-11-2016

(Oct-11-2016, 07:39 AM)sandeepvl Wrote: Hi all, 

Is it efficient to pass an object returned by lxml.etree.parse("a.xml") as argument to other functions? Is the object returned a C pointer-like mechanism referring to the in-memory tree representation of XML? Or is it something else? Will it cause any performance issues down the line? I expect the size of the tree when taken in-memory could be around 15 MB. 

I am planning to write multiple functions to process each child node and its sub-child nodes. To each function. I will be passing the object corresponding to child node. 

Thanks
Sandeep

Definitely the most complete answer you'll get on the subject:




RE: Effeciency of passing XML tree object as function arguments - sandeepvl - Oct-13-2016

(Oct-11-2016, 09:13 PM)Ofnuts Wrote:
(Oct-11-2016, 07:39 AM)sandeepvl Wrote: Hi all, 

Is it efficient to pass an object returned by lxml.etree.parse("a.xml") as argument to other functions? Is the object returned a C pointer-like mechanism referring to the in-memory tree representation of XML? Or is it something else? Will it cause any performance issues down the line? I expect the size of the tree when taken in-memory could be around 15 MB. 

I am planning to write multiple functions to process each child node and its sub-child nodes. To each function. I will be passing the object corresponding to child node. 

Thanks
Sandeep

Definitely the most complete answer you'll get on the subject:


Thanks a lot for that video. It helped a lot. Really an eye opener.