Maniphest T38261

x3d scene importer inefficient with big files; (with proposed fix)
Closed, Archived

Assigned To
Brendon Murphy (meta-androcto)
Authored By
Jonatan Bijl (jonim8or)
Jan 17 2014, 12:35 PM
Tags
  • Import/Export
  • Add-ons (Community)
Subscribers
Brendon Murphy (meta-androcto)
Campbell Barton (campbellbarton)
Jonatan Bijl (jonim8or)

Description

I recently needed to load a huge wrl file (zipped it was 63MB). That failed on memory issues.
Then I started to look through the x3d scene importer, and found out what it was doing:

  1. read the whole file into a string (!)
  2. split the string into lines, do some filtering, and merge that.
  3. split the string into lines, do some filtering (place { and [ and ] and } on separate lines) , and merge that.
  4. split the string into lines, remove unneeded whitespace , and merge that.
  5. split the string into lines
  6. start processing the lines.

I found it hard to understand how the parser internally worked (very complicated, and no documentation of the AST that is being generated), but figured out that all the functions are passing line-numbers to each other, telling where in the global array of lines they should be reading.

As far as I could see, it is never really needed to look backward more than 1 line. So I used some generator-functions and iterators to read and cleanup the wrl file line by line, and created an object which behaves like an array to replace the lines array.

However, I don't have a wide range of wrl files to check all the features of the importer, nor do I have x3d files to check if that still works.


This zip file contains an acceptance test, and a small test wrl file (the real files I can't include due to copyright reasons).
It also contains the version of the importing code that was shipped with 2.69, and my version, and tests whether or not the ASTs that are generated by the two, are the same.

To test it, unzip the zip somewhere, paste some wrl files in the folder, open blender, open comparison.py in blender, and add the names of the wrl files in the TESTFILES list.
It will write the output to files, and print a diff in blender console if there are differences.

Event Timeline

Jonatan Bijl (jonim8or) created this task.Jan 17 2014, 12:35 PM
Jonatan Bijl (jonim8or) raised the priority of this task from to 90.
Jonatan Bijl (jonim8or) updated the task description.
Jonatan Bijl (jonim8or) added projects: Add-ons (Community), Import/Export.
Jonatan Bijl (jonim8or) edited a custom field.
Jonatan Bijl (jonim8or) added a subscriber: Jonatan Bijl (jonim8or).
Jonatan Bijl (jonim8or) added a comment.Jan 17 2014, 2:18 PM

I had one part not figured out yet: how to handle referenced files.
Here's a new version of my "test suite"

Brecht Van Lommel (brecht) lowered the priority of this task from 90 to Normal.Jan 17 2014, 2:39 PM
Brecht Van Lommel (brecht) added a subscriber: Campbell Barton (campbellbarton).
Jonatan Bijl (jonim8or) added a comment.EditedJan 20 2014, 2:29 PM

Small fix to make multi-line strings in file work.

Jonatan Bijl (jonim8or) added a comment.Apr 16 2014, 2:36 PM

My previous version accidently broke the x3d importer (minidom could not handle the line-by-line input).
The x3d parser is now very slow (well, as slow as it used to be) for big files, because it still loads the file into a string first. For wrl files however it is much memory-friendlier.

Here's my new version, with also the PixelTexture code from T39594 integrated into it.

Brendon Murphy (meta-androcto) changed the task status from Unknown Status to Unknown Status.Jan 8 2016, 7:51 AM
Brendon Murphy (meta-androcto) claimed this task.
Brendon Murphy (meta-androcto) added a subscriber: Brendon Murphy (meta-androcto).

closing as archived, no activity 1.5 years.