xBimTeam / XbimEssentials

A .NET library to work with data in the IFC format. This is the core component of the Xbim Toolkit
https://xbimteam.github.io/
Other
477 stars 171 forks source link

InverseProperty performance #538

Closed simonedd closed 8 months ago

simonedd commented 8 months ago

Hi,

When I'm parsing big files I find that most of the time is spent on resolving inverse properties, for example, the following.

`[InverseProperty("Item")]
[EntityAttribute(-1, EntityAttributeState.Mandatory, EntityAttributeType.Set, EntityAttributeType.Class, new int[] {0}, new int[] {1}, 2)]
public IEnumerable<IfcStyledItem> StyledByItem => this.Model.Instances.Where<IfcStyledItem>((Func<IfcStyledItem, bool>) (e => this.Equals(e.Item)), "Item", (IPersistEntity) this);

Is there any way or option to improve this?

I'm using Xbim.Essentials 5.1.341

Thanks

andyward commented 8 months ago

I'm assuming you mean Querying rather than Parsing, based on the context (there's a lower level Parsing concept we use to turn STEP text into an object model).

There's a mechanism called Inverse Caching that can help Querying a lot. Take a look at the section of the docs at https://docs.xbim.net/examples/using-linq-for-optimal-performance.html


IModel model = OpenModel(...);
using (var cache = model.BeginInverseCaching())
{
   // your query here
}

This should help most when you're hitting the same parts of the model over again (e.g. with StyledItems)

simonedd commented 8 months ago

Yes, I mean querying. I tried the solution and it works really faster, thank you.