You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The use of std::max_element in CResourceHandler::makePackageResourceID makes the time complexity of this method O(n) which results in making IDs for all resources in a package O(n2) i.e. quadratic.
This is a performance regression over older versions of lib3mf.
If there is a need to get the biggest ID, then it is better to make m_resourceIDs an (ordered) std::map instead of std::unoredered_map.
That way m_resourceIDs.rbegin()->first will give the biggest ID in constant time.
This will reduce the time complexity of CResourceHandler::makePackageResourceID to O(log(n)). There are other std::map look ups in that method, but log(n) is much better. Overall ID creation in entire package will be O(n * log(n)).
There will be a side effect of this change on 2 other methods of CResourceHandler - findResourceIDByUniqueID and removePackageResourceID. Their time complexities will increase from constant to O(log(n)). But overall performance of lib3mf should still be better.
This above fix could be implemented with minimal changes - replace unordered_map with map and max_element with rbegin()->first.
However, if the side effects are not acceptable, then it is best to maintain biggestID separately rather than finding it in linear fashion every time we make a new resource ID.
The use of std::max_element in CResourceHandler::makePackageResourceID makes the time complexity of this method O(n) which results in making IDs for all resources in a package O(n2) i.e. quadratic.
This is a performance regression over older versions of lib3mf.
If there is a need to get the biggest ID, then it is better to make m_resourceIDs an (ordered) std::map instead of std::unoredered_map.
That way m_resourceIDs.rbegin()->first will give the biggest ID in constant time.
This will reduce the time complexity of CResourceHandler::makePackageResourceID to O(log(n)). There are other std::map look ups in that method, but log(n) is much better. Overall ID creation in entire package will be O(n * log(n)).
There will be a side effect of this change on 2 other methods of CResourceHandler - findResourceIDByUniqueID and removePackageResourceID. Their time complexities will increase from constant to O(log(n)). But overall performance of lib3mf should still be better.
This above fix could be implemented with minimal changes - replace unordered_map with map and max_element with rbegin()->first.
However, if the side effects are not acceptable, then it is best to maintain biggestID separately rather than finding it in linear fashion every time we make a new resource ID.
@martinweismann Any thoughts on this?
The text was updated successfully, but these errors were encountered: