mono / monodevelop

MonoDevelop is a cross platform .NET IDE
http://www.monodevelop.com
2.84k stars 1.02k forks source link

Listening to batched tags changed causes way too many line updates #6249

Closed Therzok closed 6 years ago

Therzok commented 6 years ago
1.40%   HandlerInternal  •  3,077 ms  •  472 calls  •  MonoDevelop.Ide.DispatchService+GtkSynchronizationContext+TimeoutProxy.HandlerInternal(IntPtr)
  1.15%   cctor>b__20_0  •  2,532 ms  •  61 calls  •  Microsoft.VisualStudio.Threading.JoinableTaskFactory+SingleExecuteProtector+<>c.cctor>b__20_0(Object)
    1.15%   MoveNext  •  2,530 ms  •  61 calls  •  Microsoft.VisualStudio.Utilities.JoinableTaskHelper+<>c__DisplayClass4_0+<<RunOnUIThread>b__0>d.MoveNext
      1.15%   RaiseBatchedTagsChanged  •  2,528 ms  •  61 calls  •  Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator`1.RaiseBatchedTagsChanged
        1.15%   RaiseEvent  •  2,527 ms  •  61 calls  •  Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent(Object, EventHandler, TArgs)
          1.15%   OnBatchedTagsChanged  •  2,527 ms  •  61 calls  •  Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierAggregator.OnBatchedTagsChanged(Object, BatchedTagsChangedEventArgs)
            1.15%   OnClassificationChanged  •  2,527 ms  •  83 calls  •  Microsoft.VisualStudio.Platform.TagBasedSyntaxHighlighting.OnClassificationChanged(Object, ClassificationChangedEventArgs)
              1.10%   GetHighlightedLineAsync  •  2,418 ms  •  3,935 calls  •  Microsoft.VisualStudio.Platform.TagBasedSyntaxHighlighting.GetHighlightedLineAsync(IDocumentLine, CancellationToken)
                ►1.03%   GetClassificationSpans  •  2,264 ms  •  3,935 calls  •  Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierAggregator.GetClassificationSpans(SnapshotSpan)
                 0.03%   25 functions hidden  •  57 ms total  •  432162 calls total
                ►0.01%   GetScopeStackFromClassificationType  •  21 ms  •  20,144 calls  •  Microsoft.VisualStudio.Platform.TagBasedSyntaxHighlighting.GetScopeStackFromClassificationType(IClassificationType)
                ►0.01%   op_Subtraction  •  16 ms  •  30,088 calls  •  Microsoft.VisualStudio.Text.SnapshotPoint.op_Subtraction(SnapshotPoint, Int32)
                ►0.01%   get_End  •  13 ms  •  24,079 calls  •  Microsoft.VisualStudio.Text.SnapshotSpan.get_End
                ►0.01%   ColoredSegment..ctor  •  12 ms  •  30,093 calls  •  MonoDevelop.Ide.Editor.Highlighting.ColoredSegment..ctor(Int32, Int32, ScopeStack)
              ►0.02%   get_ColorStyleKey  •  42 ms  •  60,084 calls  •  MonoDevelop.Ide.Editor.Highlighting.ColoredSegment.get_ColorStyleKey
               0.02%   21 functions hidden  •  37 ms total  •  203676 calls total
              ►0.01%   get_End  •  11 ms  •  4,439 calls  •  Mono.TextEditor.MdTextViewLineCollection+MdTextViewLine.get_End
             0.00%   8 functions hidden  •  1 ms total  •  764 calls total
           0.00%   3 functions hidden  •  0 ms total  •  183 calls total
         0.00%   6 functions hidden  •  0 ms total  •  337 calls total
       0.00%   5 functions hidden  •  3 ms total  •  305 calls total
  ►0.15%   <RaiseEvent>b__11_0  •  330 ms  •  35 calls  •  MonoDevelop.Core.EventQueue+<>c__11`1.<RaiseEvent>b__11_0(Object)
  ►0.08%   PostCallback  •  185 ms  •  305 calls  •  MonoDevelop.Core.SynchronizationContextTaskScheduler.PostCallback(Object)
  ►0.01%   <RunInMainThread>b__40_0  •  16 ms  •  56 calls  •  MonoDevelop.Core.Runtime+<>c.<RunInMainThread>b__40_0(Object)
  ►0.01%   cctor>b__8_0  •  13 ms  •  14 calls  •  System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation+<>c.cctor>b__8_0(Object)
   0.00%   3 functions hidden  •  1 ms total  •  945 calls total

VS bug #700077

Therzok commented 6 years ago

cc @KirillOsenkov @DavidKarlas there's a few things wrong here:

https://github.com/mono/monodevelop/blob/master/main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs#L200-L221

Blocking sync waits on the UI thread and it looks like way too many line updates.

Therzok commented 6 years ago

Later edit; Don't think it matters

There's this peculiar thing here: https://github.com/Microsoft/vs-editor-api/blob/745eea2fa0c121b43f4d0f4148e290e8310e86ef/src/Text/Impl/TagAggregator/TagAggregator.cs#L299-L332

It seems like the retrying on the UI thread is not hit because we never set InLayout to true for MonoTextEditor.

https://github.com/mono/monodevelop/blob/15123ffbcbce2652e7935085ffa7a08974e7786d/main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/MonoTextEditor.ITextView.cs#L204

Therzok commented 6 years ago

~Also, why we are iterating all the lines instead of just taking the intersection with the change span?~

xamarin-release-manager commented 6 years ago

[sync] [VS-13] Comment by xamarinc

Fixed in version 7.8.0.779 (master)

Pull Request #6250 merged by: Mike Krüger
Author: mono
Commit: 49733687242ce1186dde13cc9d6236696181b3e8 (mono/monodevelop)

xamarin-release-manager commented 4 years ago

[sync] [VS-27] Comment by xamarinc

Fixed in version 8.6.0.802 (master)

Pull Request #6250 merged by: Mike Kr??ger
Author: mono
Commit: 49733687242ce1186dde13cc9d6236696181b3e8 (xamarin/monodevelop)