Improve Parsing Performance

I did some changes to increase performance.

Remove findRemainingTypes()

src/ifc-parser/ifc-services/ifc-processor.js
function loadIfcFileItems(ifcData) {
   const ifcItems = readIfcItems(ifcData);
   // findRemainingTypes(ifcItems);
   return loadItems(ifcItems);
 }

Check isArray once

I moved the isArray outside the loop. This a dirty trick... but it should work.

src/ifc-project-builder/ifc-elements-binder.js
function bindElements(finder, type, relating, related, property) {
    const relations = finder.findByType(type);
    if (Object.keys(relations).length === 0) return;
    const _isArray = isArray(Object.keys(relations)[0]);
    Object.values(relations).forEach((relation) => {
          return _isArray
                ? bindMultiple(relation, relating, related, property)
                : bindSingle(relation, relating, related, property);
    });
}

getName once

I moved the getName outside the loop. This will improve performance for large files.

src/ifc-project-builder/items-finder.js
findByType(ifcType) {
    const matches = {};
    const name = getName(ifcType);
    Object.keys(this.ifcData).forEach((e) => {
        if (this.getType(e) === name) {
            matches[e] = this.ifcData[e];
        }
    });
    return matches;
}

Const instead of var

When we target modern browser, Babel will use const instead of var. I saw a ~4 second increase with the IFC Sample File.

Last updated