7
7
using System . Collections . Generic ;
8
8
using System . Diagnostics ;
9
9
using System . Runtime . CompilerServices ;
10
- using Microsoft . AspNetCore . Components . Profiling ;
11
10
using Microsoft . AspNetCore . Components . Rendering ;
12
11
13
12
namespace Microsoft . AspNetCore . Components . RenderTree
@@ -28,7 +27,6 @@ public static RenderTreeDiff ComputeDiff(
28
27
ArrayRange < RenderTreeFrame > oldTree ,
29
28
ArrayRange < RenderTreeFrame > newTree )
30
29
{
31
- ComponentsProfiling . Instance . Start ( ) ;
32
30
var editsBuffer = batchBuilder . EditsBuffer ;
33
31
var editsBufferStartLength = editsBuffer . Count ;
34
32
@@ -37,7 +35,6 @@ public static RenderTreeDiff ComputeDiff(
37
35
38
36
var editsSegment = editsBuffer . ToSegment ( editsBufferStartLength , editsBuffer . Count ) ;
39
37
var result = new RenderTreeDiff ( componentId , editsSegment ) ;
40
- ComponentsProfiling . Instance . End ( ) ;
41
38
return result ;
42
39
}
43
40
@@ -49,7 +46,6 @@ private static void AppendDiffEntriesForRange(
49
46
int oldStartIndex , int oldEndIndexExcl ,
50
47
int newStartIndex , int newEndIndexExcl )
51
48
{
52
- ProfilingStart ( ) ;
53
49
// This is deliberately a very large method. Parts of it could be factored out
54
50
// into other private methods, but doing so comes at a consequential perf cost,
55
51
// because it involves so much parameter passing. You can think of the code here
@@ -300,12 +296,10 @@ private static void AppendDiffEntriesForRange(
300
296
diffContext . KeyedItemInfoDictionaryPool . Return ( keyedItemInfos ) ;
301
297
}
302
298
}
303
- ProfilingEnd ( ) ;
304
299
}
305
300
306
301
private static Dictionary < object , KeyedItemInfo > BuildKeyToInfoLookup ( DiffContext diffContext , int oldStartIndex , int oldEndIndexExcl , int newStartIndex , int newEndIndexExcl )
307
302
{
308
- ProfilingStart ( ) ;
309
303
var result = diffContext . KeyedItemInfoDictionaryPool . Get ( ) ;
310
304
var oldTree = diffContext . OldTree ;
311
305
var newTree = diffContext . NewTree ;
@@ -351,7 +345,6 @@ private static Dictionary<object, KeyedItemInfo> BuildKeyToInfoLookup(DiffContex
351
345
newStartIndex = NextSiblingIndex ( frame , newStartIndex ) ;
352
346
}
353
347
354
- ProfilingEnd ( ) ;
355
348
return result ;
356
349
}
357
350
@@ -384,7 +377,6 @@ private static void AppendAttributeDiffEntriesForRange(
384
377
int oldStartIndex , int oldEndIndexExcl ,
385
378
int newStartIndex , int newEndIndexExcl )
386
379
{
387
- ProfilingStart ( ) ;
388
380
// The overhead of the dictionary used by AppendAttributeDiffEntriesForRangeSlow is
389
381
// significant, so we want to try and do a merge-join if possible, but fall back to
390
382
// a hash-join if not. We'll do a merge join until we hit a case we can't handle and
@@ -433,7 +425,6 @@ private static void AppendAttributeDiffEntriesForRange(
433
425
ref diffContext ,
434
426
oldStartIndex , oldEndIndexExcl ,
435
427
newStartIndex , newEndIndexExcl ) ;
436
- ProfilingEnd ( ) ;
437
428
return ;
438
429
}
439
430
@@ -459,20 +450,16 @@ private static void AppendAttributeDiffEntriesForRange(
459
450
ref diffContext ,
460
451
oldStartIndex , oldEndIndexExcl ,
461
452
newStartIndex , newEndIndexExcl ) ;
462
- ProfilingEnd ( ) ;
463
453
return ;
464
454
}
465
455
}
466
-
467
- ProfilingEnd ( ) ;
468
456
}
469
457
470
458
private static void AppendAttributeDiffEntriesForRangeSlow (
471
459
ref DiffContext diffContext ,
472
460
int oldStartIndex , int oldEndIndexExcl ,
473
461
int newStartIndex , int newEndIndexExcl )
474
462
{
475
- ProfilingStart ( ) ;
476
463
var oldTree = diffContext . OldTree ;
477
464
var newTree = diffContext . NewTree ;
478
465
@@ -511,15 +498,13 @@ private static void AppendAttributeDiffEntriesForRangeSlow(
511
498
512
499
// We should have processed any additions at this point. Reset for the next batch.
513
500
diffContext . AttributeDiffSet . Clear ( ) ;
514
- ProfilingEnd ( ) ;
515
501
}
516
502
517
503
private static void UpdateRetainedChildComponent (
518
504
ref DiffContext diffContext ,
519
505
int oldComponentIndex ,
520
506
int newComponentIndex )
521
507
{
522
- ProfilingStart ( ) ;
523
508
var oldTree = diffContext . OldTree ;
524
509
var newTree = diffContext . NewTree ;
525
510
ref var oldComponentFrame = ref oldTree [ oldComponentIndex ] ;
@@ -546,8 +531,6 @@ private static void UpdateRetainedChildComponent(
546
531
{
547
532
componentState . SetDirectParameters ( newParameters ) ;
548
533
}
549
-
550
- ProfilingEnd ( ) ;
551
534
}
552
535
553
536
private static int NextSiblingIndex ( in RenderTreeFrame frame , int frameIndex )
@@ -570,7 +553,6 @@ private static void AppendDiffEntriesForFramesWithSameSequence(
570
553
int oldFrameIndex ,
571
554
int newFrameIndex )
572
555
{
573
- ProfilingStart ( ) ;
574
556
var oldTree = diffContext . OldTree ;
575
557
var newTree = diffContext . NewTree ;
576
558
ref var oldFrame = ref oldTree [ oldFrameIndex ] ;
@@ -583,7 +565,6 @@ private static void AppendDiffEntriesForFramesWithSameSequence(
583
565
{
584
566
InsertNewFrame ( ref diffContext , newFrameIndex ) ;
585
567
RemoveOldFrame ( ref diffContext , oldFrameIndex ) ;
586
- ProfilingEnd ( ) ;
587
568
return ;
588
569
}
589
570
@@ -709,8 +690,6 @@ private static void AppendDiffEntriesForFramesWithSameSequence(
709
690
default :
710
691
throw new NotImplementedException ( $ "Encountered unsupported frame type during diffing: { newTree [ newFrameIndex ] . FrameType } ") ;
711
692
}
712
-
713
- ProfilingEnd ( ) ;
714
693
}
715
694
716
695
// This should only be called for attributes that have the same name. This is an
@@ -720,7 +699,6 @@ private static void AppendDiffEntriesForAttributeFrame(
720
699
int oldFrameIndex ,
721
700
int newFrameIndex )
722
701
{
723
- ProfilingStart ( ) ;
724
702
var oldTree = diffContext . OldTree ;
725
703
var newTree = diffContext . NewTree ;
726
704
ref var oldFrame = ref oldTree [ oldFrameIndex ] ;
@@ -749,13 +727,10 @@ private static void AppendDiffEntriesForAttributeFrame(
749
727
// since it was unchanged.
750
728
newFrame = oldFrame ;
751
729
}
752
-
753
- ProfilingEnd ( ) ;
754
730
}
755
731
756
732
private static void InsertNewFrame ( ref DiffContext diffContext , int newFrameIndex )
757
733
{
758
- ProfilingStart ( ) ;
759
734
var newTree = diffContext . NewTree ;
760
735
ref var newFrame = ref newTree [ newFrameIndex ] ;
761
736
switch ( newFrame . FrameType )
@@ -808,12 +783,10 @@ private static void InsertNewFrame(ref DiffContext diffContext, int newFrameInde
808
783
default :
809
784
throw new NotImplementedException ( $ "Unexpected frame type during { nameof ( InsertNewFrame ) } : { newFrame . FrameType } ") ;
810
785
}
811
- ProfilingEnd ( ) ;
812
786
}
813
787
814
788
private static void RemoveOldFrame ( ref DiffContext diffContext , int oldFrameIndex )
815
789
{
816
- ProfilingStart ( ) ;
817
790
var oldTree = diffContext . OldTree ;
818
791
ref var oldFrame = ref oldTree [ oldFrameIndex ] ;
819
792
switch ( oldFrame . FrameType )
@@ -855,7 +828,6 @@ private static void RemoveOldFrame(ref DiffContext diffContext, int oldFrameInde
855
828
default :
856
829
throw new NotImplementedException ( $ "Unexpected frame type during { nameof ( RemoveOldFrame ) } : { oldFrame . FrameType } ") ;
857
830
}
858
- ProfilingEnd ( ) ;
859
831
}
860
832
861
833
private static int GetAttributesEndIndexExclusive ( RenderTreeFrame [ ] tree , int rootIndex )
@@ -889,7 +861,6 @@ private static void AppendStepOut(ref DiffContext diffContext)
889
861
890
862
private static void InitializeNewSubtree ( ref DiffContext diffContext , int frameIndex )
891
863
{
892
- ProfilingStart ( ) ;
893
864
var frames = diffContext . NewTree ;
894
865
var endIndexExcl = frameIndex + frames [ frameIndex ] . ElementSubtreeLength ;
895
866
for ( var i = frameIndex ; i < endIndexExcl ; i ++ )
@@ -911,12 +882,10 @@ private static void InitializeNewSubtree(ref DiffContext diffContext, int frameI
911
882
break ;
912
883
}
913
884
}
914
- ProfilingEnd ( ) ;
915
885
}
916
886
917
887
private static void InitializeNewComponentFrame ( ref DiffContext diffContext , int frameIndex )
918
888
{
919
- ProfilingStart ( ) ;
920
889
var frames = diffContext . NewTree ;
921
890
ref var frame = ref frames [ frameIndex ] ;
922
891
@@ -933,7 +902,6 @@ private static void InitializeNewComponentFrame(ref DiffContext diffContext, int
933
902
var initialParametersLifetime = new ParameterViewLifetime ( diffContext . BatchBuilder ) ;
934
903
var initialParameters = new ParameterView ( initialParametersLifetime , frames , frameIndex ) ;
935
904
childComponentState . SetDirectParameters ( initialParameters ) ;
936
- ProfilingEnd ( ) ;
937
905
}
938
906
939
907
private static void InitializeNewAttributeFrame ( ref DiffContext diffContext , ref RenderTreeFrame newFrame )
@@ -978,7 +946,6 @@ private static void InitializeNewComponentReferenceCaptureFrame(ref DiffContext
978
946
979
947
private static void DisposeFramesInRange ( RenderBatchBuilder batchBuilder , RenderTreeFrame [ ] frames , int startIndex , int endIndexExcl )
980
948
{
981
- ProfilingStart ( ) ;
982
949
for ( var i = startIndex ; i < endIndexExcl ; i ++ )
983
950
{
984
951
ref var frame = ref frames [ i ] ;
@@ -991,7 +958,6 @@ private static void DisposeFramesInRange(RenderBatchBuilder batchBuilder, Render
991
958
batchBuilder . DisposedEventHandlerIds . Append ( frame . AttributeEventHandlerId ) ;
992
959
}
993
960
}
994
- ProfilingEnd ( ) ;
995
961
}
996
962
997
963
/// <summary>
@@ -1033,18 +999,5 @@ public DiffContext(
1033
999
SiblingIndex = 0 ;
1034
1000
}
1035
1001
}
1036
-
1037
- // Having too many calls to ComponentsProfiling.Instance.Start/End has a measurable perf impact
1038
- // even when capturing is disabled. So, to enable detailed profiling for this class, define the
1039
- // Profile_RenderTreeDiffBuilder compiler symbol, otherwise the calls are compiled out entirely.
1040
- // Enabling detailed profiling adds about 5% to rendering benchmark times.
1041
-
1042
- [ Conditional ( "Profile_RenderTreeDiffBuilder" ) ]
1043
- private static void ProfilingStart ( [ CallerMemberName ] string ? name = null )
1044
- => ComponentsProfiling . Instance . Start ( name ) ;
1045
-
1046
- [ Conditional ( "Profile_RenderTreeDiffBuilder" ) ]
1047
- private static void ProfilingEnd ( [ CallerMemberName ] string ? name = null )
1048
- => ComponentsProfiling . Instance . End ( name ) ;
1049
1002
}
1050
1003
}
0 commit comments