简体   繁体   English

python XML解析器最小内存使用情况

[英]python xml parser minidom memory usage

I recently use minidom to parse some xml files. 我最近使用minidom解析了一些xml文件。

The funny thing is it takes me 8G memroy to read a 56MB file, which is relative flat, ie, most of the nodes are in the same level. 有趣的是,我需要8G内存来读取一个56MB的文件,该文件是相对平坦的,即,大多数节点处于同一级别。

Why is this true? 为什么会这样呢?

You are not the only one to face this . 您不是唯一面对这个问题的人

From my humble opinion, the main reason minidom based program consume lot of memory is due to the fact lot of minidom functions are implemented recursively (recursion and memory usage are generally not good friends). 根据我的拙见,基于minidom的程序消耗大量内存的主要原因是由于许多minidom是递归实现的(递归和内存使用通常不是好朋友)。

I advice you to opt for other Python XML parser libraries which are faster (notably lxml ). 我建议您选择速度更快的其他Python XML解析器库(特别是lxml )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM