-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Delay Creation of ElementLocation #6980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Using the interface named "IInternalLocation" to expose the internal IElementLocation. "ILocation" is a better name public name. Thoughts? |
|
@yuehuang010 I have reviewed this PR and I do not understand how are those changes improving perf or GC. On the other hand, the presented performance measurement show improvements. Wonder what I am missing... What tooling did you use to collect this perf samples? |
Before, XML object -> get_Location -> Verify. After, XML object -> Verify -> get_Location. Verify only needs location when it prints a message. In most use case, it doesn't need it.
Updated description on perf collection methods. |
|
I have looked at the code again and to me situation looks like this: So the amount of Location object allocations is same in both cases - if I understand it correctly, there is no lazy Location object creation. |
|
Good call. I found an issue. In my case, the XmlElementWithLocation.OwnerDocument.FullPath is null, so it never match with current location, thus it will always create a new copy of ElementLocation. Let me re-run baseline. |
|
Team triage: |
|
@Forgind, I have moved this pr back to draft. Don't like draft, feel free to close it. |
Issue
Many ElementLocation objects are created for Verify() but is often not used outside of an error. So instead of creating an new object, add an interface IInternalLocation to the XML objects and pass the interface instead. When needed, Verify() would call get_Location() to get the IElementLocation.
Note
ProjectTaskElement.EnsureParametersInitialized() still creates locations and caches the location. It would be great to delay it too.
Tests
Each line is a run of a "helloworld" vcxproj project doing load/evaluation/unload 1000 times averaged. Forced GC afterwards. First run discarded. Project created with Microsoft.Build.Evaluation.Project() then Zombify() to dispose.
After:
Evaluation average 497046tick + GC 66284tick = 563331tick
Evaluation average 496872tick + GC 65720tick = 562592tick
Evaluation average 495546tick + GC 65837tick = 561384tick
Evaluation average 501929tick + GC 66190tick = 568119tick
Evaluation average 498541tick + GC 66604tick = 565145tick
Evaluation average 497091tick + GC 65755tick = 562846tick
Evaluation average 494466tick + GC 65964tick = 560431tick
Evaluation average 498267tick + GC 65885tick = 564153tick
Before:
Evaluation average 487367tick + GC 64650tick = 552017tick
Evaluation average 478148tick + GC 64545tick = 542694tick
Evaluation average 478841tick + GC 64590tick = 543431tick
Evaluation average 479940tick + GC 64787tick = 544728tick
Evaluation average 494942tick + GC 66813tick = 561755tick
Evaluation average 506728tick + GC 65485tick = 572214tick
Evaluation average 498566tick + GC 65650tick = 564217tick
Evaluation average 500238tick + GC 65723tick = 565961tick
Evaluation average 497829tick + GC 65577tick = 563406tick
Evaluation average 551038tick + GC 67453tick = 618491tickEvaluation average 549966tick + GC 67914tick = 617881tickEvaluation average 546807tick + GC 67633tick = 614440tickEvaluation average 554436tick + GC 68152tick = 622589tickEvaluation average 547378tick + GC 66956tick = 614335tick