77using System . Collections . Generic ;
88using System . Diagnostics ;
99using System . Runtime . CompilerServices ;
10- using Microsoft . AspNetCore . Components . Profiling ;
1110using Microsoft . AspNetCore . Components . Rendering ;
1211
1312namespace Microsoft . AspNetCore . Components . RenderTree
@@ -28,7 +27,6 @@ public static RenderTreeDiff ComputeDiff(
2827 ArrayRange < RenderTreeFrame > oldTree ,
2928 ArrayRange < RenderTreeFrame > newTree )
3029 {
31- ComponentsProfiling . Instance . Start ( ) ;
3230 var editsBuffer = batchBuilder . EditsBuffer ;
3331 var editsBufferStartLength = editsBuffer . Count ;
3432
@@ -37,7 +35,6 @@ public static RenderTreeDiff ComputeDiff(
3735
3836 var editsSegment = editsBuffer . ToSegment ( editsBufferStartLength , editsBuffer . Count ) ;
3937 var result = new RenderTreeDiff ( componentId , editsSegment ) ;
40- ComponentsProfiling . Instance . End ( ) ;
4138 return result ;
4239 }
4340
@@ -49,7 +46,6 @@ private static void AppendDiffEntriesForRange(
4946 int oldStartIndex , int oldEndIndexExcl ,
5047 int newStartIndex , int newEndIndexExcl )
5148 {
52- ProfilingStart ( ) ;
5349 // This is deliberately a very large method. Parts of it could be factored out
5450 // into other private methods, but doing so comes at a consequential perf cost,
5551 // because it involves so much parameter passing. You can think of the code here
@@ -300,12 +296,10 @@ private static void AppendDiffEntriesForRange(
300296 diffContext . KeyedItemInfoDictionaryPool . Return ( keyedItemInfos ) ;
301297 }
302298 }
303- ProfilingEnd ( ) ;
304299 }
305300
306301 private static Dictionary < object , KeyedItemInfo > BuildKeyToInfoLookup ( DiffContext diffContext , int oldStartIndex , int oldEndIndexExcl , int newStartIndex , int newEndIndexExcl )
307302 {
308- ProfilingStart ( ) ;
309303 var result = diffContext . KeyedItemInfoDictionaryPool . Get ( ) ;
310304 var oldTree = diffContext . OldTree ;
311305 var newTree = diffContext . NewTree ;
@@ -351,7 +345,6 @@ private static Dictionary<object, KeyedItemInfo> BuildKeyToInfoLookup(DiffContex
351345 newStartIndex = NextSiblingIndex ( frame , newStartIndex ) ;
352346 }
353347
354- ProfilingEnd ( ) ;
355348 return result ;
356349 }
357350
@@ -394,7 +387,6 @@ private static void AppendAttributeDiffEntriesForRange(
394387 int oldStartIndex , int oldEndIndexExcl ,
395388 int newStartIndex , int newEndIndexExcl )
396389 {
397- ProfilingStart ( ) ;
398390 // The overhead of the dictionary used by AppendAttributeDiffEntriesForRangeSlow is
399391 // significant, so we want to try and do a merge-join if possible, but fall back to
400392 // a hash-join if not. We'll do a merge join until we hit a case we can't handle and
@@ -443,7 +435,6 @@ private static void AppendAttributeDiffEntriesForRange(
443435 ref diffContext ,
444436 oldStartIndex , oldEndIndexExcl ,
445437 newStartIndex , newEndIndexExcl ) ;
446- ProfilingEnd ( ) ;
447438 return ;
448439 }
449440
@@ -469,20 +460,16 @@ private static void AppendAttributeDiffEntriesForRange(
469460 ref diffContext ,
470461 oldStartIndex , oldEndIndexExcl ,
471462 newStartIndex , newEndIndexExcl ) ;
472- ProfilingEnd ( ) ;
473463 return ;
474464 }
475465 }
476-
477- ProfilingEnd ( ) ;
478466 }
479467
480468 private static void AppendAttributeDiffEntriesForRangeSlow (
481469 ref DiffContext diffContext ,
482470 int oldStartIndex , int oldEndIndexExcl ,
483471 int newStartIndex , int newEndIndexExcl )
484472 {
485- ProfilingStart ( ) ;
486473 var oldTree = diffContext . OldTree ;
487474 var newTree = diffContext . NewTree ;
488475
@@ -521,15 +508,13 @@ private static void AppendAttributeDiffEntriesForRangeSlow(
521508
522509 // We should have processed any additions at this point. Reset for the next batch.
523510 diffContext . AttributeDiffSet . Clear ( ) ;
524- ProfilingEnd ( ) ;
525511 }
526512
527513 private static void UpdateRetainedChildComponent (
528514 ref DiffContext diffContext ,
529515 int oldComponentIndex ,
530516 int newComponentIndex )
531517 {
532- ProfilingStart ( ) ;
533518 var oldTree = diffContext . OldTree ;
534519 var newTree = diffContext . NewTree ;
535520 ref var oldComponentFrame = ref oldTree [ oldComponentIndex ] ;
@@ -556,8 +541,6 @@ private static void UpdateRetainedChildComponent(
556541 {
557542 componentState . SetDirectParameters ( newParameters ) ;
558543 }
559-
560- ProfilingEnd ( ) ;
561544 }
562545
563546 private static int NextSiblingIndex ( in RenderTreeFrame frame , int frameIndex )
@@ -580,7 +563,6 @@ private static void AppendDiffEntriesForFramesWithSameSequence(
580563 int oldFrameIndex ,
581564 int newFrameIndex )
582565 {
583- ProfilingStart ( ) ;
584566 var oldTree = diffContext . OldTree ;
585567 var newTree = diffContext . NewTree ;
586568 ref var oldFrame = ref oldTree [ oldFrameIndex ] ;
@@ -593,7 +575,6 @@ private static void AppendDiffEntriesForFramesWithSameSequence(
593575 {
594576 InsertNewFrame ( ref diffContext , newFrameIndex ) ;
595577 RemoveOldFrame ( ref diffContext , oldFrameIndex ) ;
596- ProfilingEnd ( ) ;
597578 return ;
598579 }
599580
@@ -719,8 +700,6 @@ private static void AppendDiffEntriesForFramesWithSameSequence(
719700 default :
720701 throw new NotImplementedException ( $ "Encountered unsupported frame type during diffing: { newTree [ newFrameIndex ] . FrameType } ") ;
721702 }
722-
723- ProfilingEnd ( ) ;
724703 }
725704
726705 // This should only be called for attributes that have the same name. This is an
@@ -730,7 +709,6 @@ private static void AppendDiffEntriesForAttributeFrame(
730709 int oldFrameIndex ,
731710 int newFrameIndex )
732711 {
733- ProfilingStart ( ) ;
734712 var oldTree = diffContext . OldTree ;
735713 var newTree = diffContext . NewTree ;
736714 ref var oldFrame = ref oldTree [ oldFrameIndex ] ;
@@ -759,13 +737,10 @@ private static void AppendDiffEntriesForAttributeFrame(
759737 // since it was unchanged.
760738 newFrame = oldFrame ;
761739 }
762-
763- ProfilingEnd ( ) ;
764740 }
765741
766742 private static void InsertNewFrame ( ref DiffContext diffContext , int newFrameIndex )
767743 {
768- ProfilingStart ( ) ;
769744 var newTree = diffContext . NewTree ;
770745 ref var newFrame = ref newTree [ newFrameIndex ] ;
771746 switch ( newFrame . FrameType )
@@ -818,12 +793,10 @@ private static void InsertNewFrame(ref DiffContext diffContext, int newFrameInde
818793 default :
819794 throw new NotImplementedException ( $ "Unexpected frame type during { nameof ( InsertNewFrame ) } : { newFrame . FrameType } ") ;
820795 }
821- ProfilingEnd ( ) ;
822796 }
823797
824798 private static void RemoveOldFrame ( ref DiffContext diffContext , int oldFrameIndex )
825799 {
826- ProfilingStart ( ) ;
827800 var oldTree = diffContext . OldTree ;
828801 ref var oldFrame = ref oldTree [ oldFrameIndex ] ;
829802 switch ( oldFrame . FrameType )
@@ -865,7 +838,6 @@ private static void RemoveOldFrame(ref DiffContext diffContext, int oldFrameInde
865838 default :
866839 throw new NotImplementedException ( $ "Unexpected frame type during { nameof ( RemoveOldFrame ) } : { oldFrame . FrameType } ") ;
867840 }
868- ProfilingEnd ( ) ;
869841 }
870842
871843 private static int GetAttributesEndIndexExclusive ( RenderTreeFrame [ ] tree , int rootIndex )
@@ -899,7 +871,6 @@ private static void AppendStepOut(ref DiffContext diffContext)
899871
900872 private static void InitializeNewSubtree ( ref DiffContext diffContext , int frameIndex )
901873 {
902- ProfilingStart ( ) ;
903874 var frames = diffContext . NewTree ;
904875 var endIndexExcl = frameIndex + frames [ frameIndex ] . ElementSubtreeLength ;
905876 for ( var i = frameIndex ; i < endIndexExcl ; i ++ )
@@ -921,12 +892,10 @@ private static void InitializeNewSubtree(ref DiffContext diffContext, int frameI
921892 break ;
922893 }
923894 }
924- ProfilingEnd ( ) ;
925895 }
926896
927897 private static void InitializeNewComponentFrame ( ref DiffContext diffContext , int frameIndex )
928898 {
929- ProfilingStart ( ) ;
930899 var frames = diffContext . NewTree ;
931900 ref var frame = ref frames [ frameIndex ] ;
932901
@@ -943,7 +912,6 @@ private static void InitializeNewComponentFrame(ref DiffContext diffContext, int
943912 var initialParametersLifetime = new ParameterViewLifetime ( diffContext . BatchBuilder ) ;
944913 var initialParameters = new ParameterView ( initialParametersLifetime , frames , frameIndex ) ;
945914 childComponentState . SetDirectParameters ( initialParameters ) ;
946- ProfilingEnd ( ) ;
947915 }
948916
949917 private static void InitializeNewAttributeFrame ( ref DiffContext diffContext , ref RenderTreeFrame newFrame )
@@ -988,7 +956,6 @@ private static void InitializeNewComponentReferenceCaptureFrame(ref DiffContext
988956
989957 private static void DisposeFramesInRange ( RenderBatchBuilder batchBuilder , RenderTreeFrame [ ] frames , int startIndex , int endIndexExcl )
990958 {
991- ProfilingStart ( ) ;
992959 for ( var i = startIndex ; i < endIndexExcl ; i ++ )
993960 {
994961 ref var frame = ref frames [ i ] ;
@@ -1001,7 +968,6 @@ private static void DisposeFramesInRange(RenderBatchBuilder batchBuilder, Render
1001968 batchBuilder . DisposedEventHandlerIds . Append ( frame . AttributeEventHandlerId ) ;
1002969 }
1003970 }
1004- ProfilingEnd ( ) ;
1005971 }
1006972
1007973 /// <summary>
@@ -1043,18 +1009,5 @@ public DiffContext(
10431009 SiblingIndex = 0 ;
10441010 }
10451011 }
1046-
1047- // Having too many calls to ComponentsProfiling.Instance.Start/End has a measurable perf impact
1048- // even when capturing is disabled. So, to enable detailed profiling for this class, define the
1049- // Profile_RenderTreeDiffBuilder compiler symbol, otherwise the calls are compiled out entirely.
1050- // Enabling detailed profiling adds about 5% to rendering benchmark times.
1051-
1052- [ Conditional ( "Profile_RenderTreeDiffBuilder" ) ]
1053- private static void ProfilingStart ( [ CallerMemberName ] string ? name = null )
1054- => ComponentsProfiling . Instance . Start ( name ) ;
1055-
1056- [ Conditional ( "Profile_RenderTreeDiffBuilder" ) ]
1057- private static void ProfilingEnd ( [ CallerMemberName ] string ? name = null )
1058- => ComponentsProfiling . Instance . End ( name ) ;
10591012 }
10601013}
0 commit comments