DataObjects-NET / dataobjects-net

https://dataobjects.net
MIT License
61 stars 25 forks source link

Improves memory efficiency of building indexes. #331

Closed alex-kulakov closed 1 year ago

alex-kulakov commented 1 year ago

This should be merged after #297.

alex-kulakov commented 1 year ago

@SergeiPavlov, this should reduce memory usage, especially on big models without lazy columns (declared lazy in FieldAttribute). Similar to List<T>, it may waste some array space, but not more than (number of lazy columns + TypeId column) but it doesn't use copying when capacity of list changes. Since list grows x2 every time for regular columns we could easily stuck with inner array of 32 items with 15 wasted items or worse. Statistically, memory consumption will grow if >50% of all of columns in index are lazy but I assume it is very rare case.

P.S. On my test model of 400 entities in 200 hierarchies containing 8700 IndexInfo instances (domain.Model.Types.SelectMany(t => t.Indexes).Count()), this change reduced allocated memory by 1 MB (from 244MB down to 243MB).

SergeiPavlov commented 1 year ago

Looks good to me