Text editor to open big (giant, huge, large) text files
#1
In search of a robust text editor to handle huge XML files, specifically those over 100MB, I’ve encountered significant performance issues with common editors. Sublime Text, Notepad++, and even VS Code struggle at times. I require an editor that doesn’t just crash or freeze when trying to open or search through large files. Syntax highlighting would be a plus, but stability and speed are paramount. Does anyone have any recommendations based on their own experience with exceptionally large files?
Reply
#2
For gargantuan files, you may want to consider using Vim or Emacs. They are both extremely powerful and efficient when dealing with large texts. Vim, in particular, is known for its low memory footprint and speed. You said you need to look through a large XML file; if you're comfortable with the command line, you might even consider using tools specifically designed for parsing XML. For instance, `xmlstarlet` or similar command-line tools can be quite effective.
Reply
#3
While Vim and Emacs are indeed powerful, their interfaces can be quite daunting for users not familiar with them. I’m looking for a solution that provides both the ease of a graphical interface and the power to handle large files effectively. For the sake of argument, let’s say I choose to parse the XML with a Python script instead of a traditional text editor. This could potentially allow me to process the file in chunks and extract the needed information. Here's some sample code I’ve been experimenting with using ElementTree:

Code:
if event == 'end'
and elem.tag == 'parent_tag':
    process_xml_chunk(iter([(event, elem)]))
root.clear()
parse_large_xml('large_file.xml')

Would a solution like this be considered viable in your experience? It's not a traditional text editor, but it's a way to navigate an enormous XML file without crashing.
Reply
#4
Indeed, the Python route is a solid choice when you need to handle and process large XML files, especially when text editors fail to perform. The script you've written is a good starting point. However, I would suggest using `lxml` instead of `ElementTree`. `lxml` is generally faster and more memory-efficient, which is crucial when working with files of that size. Also, consider using `iterparse` in a way that only holds relevant XML sections in memory. Here is how you could adapt your script using `lxml`:

Code:
t need it again.
elem.clear()
while elem.getprevious() is not None:
    del elem.getparent()[0]
parse_large_xml('large_file.xml')

Remember to install `lxml` via pip if you haven't done so. This approach should enable you to work through your large XML file with much better performance.
Reply
#5
That’s a valuable suggestion. I hadn’t considered `lxml`, but given its performance advantages, it seems like an optimal tool for the job. Here is a revised version of the script incorporating your recommendations and a simple performance improvement by reducing the frequency of `clear()` on the root element. It should minimize the memory usage even further:


You need to ensure `lxml` is installed, which can be done via pip:

Code:
pip install lxml
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)