Please optimise code in PsiExtensions.GetTemplateParameterName
ollka opened this issue · 6 comments
You can see screenshot from snapshot where Member.GetAttributeInstances method took long time. Most of usages came from PsiExtensions.GetTemplateParameterName and all other ReSharper usages took a little.
There is a special instrument in ReSharper for caching information from attributes. Hope it can help. You can create YourOwnAttributeProvider and mark it with [CodeAnnotationProvider] attribute and inherit CodeAnnotationInfoProvider class. It will take care about attribute information caching.
Hi @ollka,
Thank you for the report.
There is a special instrument in ReSharper for caching information from attributes. Hope it can help. You can create YourOwnAttributeProvider and mark it with [CodeAnnotationProvider] attribute and inherit CodeAnnotationInfoProvider class. It will take care about attribute information caching.
Could you please send an example or probably there is documentation about it?
CodeAnnotationInfoProvider<TAttributesOwner , TResult>.GetInfo works as follows:
- check if TAttributesOwner attributesOwner is accepted by method Accept, if not then return GetDefaultInfo(attributesOwner)
- look if there any result of type TResult into DirectMappedCache for the key TAttributesOwner and returns if any
- collect all attribute instances from TAttributesOwner attributesOwner including its bases (using global cache about attributesOwner without any attribute), if the collection is empty return GetDefaultInfo(attributesOwner)
- invoke CalculateInfo(TAttributesOwner attributesOwner, IAttributeInstanceCollection attributesInstanceCollection) on collected attribute instances to get TResult result
- cache result to DirectMappedCache and return it
Hope it helps.
The main idea is that when attribute collection is created then all [CodeAnnotationProvider] providers are invoked on this attribute collection to cache their value.
Thank you for the help. I'll try to implement the caching soon.
@ollka done!
I've tested it with a profiler and it looks like the issue is fixed, thank you! 💯
Could you please review the implementation in the related commits?
Closed due to inactivity, feel free to reopen the issue.