Conversation
|
|
||
| var selectedSpans = new List<ITagSpan<IntraTextAdornmentTag>>(); | ||
| foreach (var tagSpan in _cache) | ||
| for (var i = 0; i < _cache.Count; i++) |
There was a problem hiding this comment.
| for (var i = 0; i < _cache.Count; i++) | |
| foreach (var (mappingTagSpan, tagSpan) in _cache) |
There was a problem hiding this comment.
The index is required for assigning a value back.
| if (spans.IntersectsWith(tagSpan)) | ||
| { | ||
| selectedSpans.Add(tagSpan); | ||
| if (_cache[i].tagSpan is not { } hintTagSpan) |
There was a problem hiding this comment.
| if (_cache[i].tagSpan is not { } hintTagSpan) | |
| if (_cache[i].tagSpan is null) |
There was a problem hiding this comment.
changing to deconstructed foreach will change this slightly, but there's name collisions so it will depend on what you name the deconstructed parts
There was a problem hiding this comment.
This doesn't work for lazy initialization.
| } | ||
|
|
||
| var document = snapshot.GetOpenDocumentInCurrentContextWithChanges(); | ||
| var classify = document?.Project.Solution.Workspace.Options.GetOption(InlineHintsOptions.ColorHints, document?.Project.Language) ?? false; |
There was a problem hiding this comment.
| var classify = document?.Project.Solution.Workspace.Options.GetOption(InlineHintsOptions.ColorHints, document?.Project.Language) ?? false; | |
| var classify = document is null | |
| ? false | |
| : document.Project.Solution.Workspace.Options.GetOption(InlineHintsOptions.ColorHints, document.Project.Language); |
There was a problem hiding this comment.
I prefer to keep the original form here so it's clear this is the same code just moved down.
| } | ||
|
|
||
| // Encapsulates the textblock within a border. Gets foreground/background colors from the options menu. | ||
| block.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); |
There was a problem hiding this comment.
While it's good to measure only what's needed, I imagine this won't be much of a perf gain. TextBlock measurement is the expensive part, the border likely had very little overhead here.
There was a problem hiding this comment.
Yes, this was an opportunistic improvement from the performance trace. The lazy evaluation is the big win, and this is the distant second but easy to fix.
| /// stores the parameter hint tags in a global location | ||
| /// </summary> | ||
| private readonly List<ITagSpan<IntraTextAdornmentTag>> _cache; | ||
| private readonly List<(IMappingTagSpan<InlineHintDataTag> mappingTagSpan, ITagSpan<IntraTextAdornmentTag>? tagSpan)> _cache; |
There was a problem hiding this comment.
| private readonly List<(IMappingTagSpan<InlineHintDataTag> mappingTagSpan, ITagSpan<IntraTextAdornmentTag>? tagSpan)> _cache; | |
| private readonly List<(IMappingTagSpan<InlineHintDataTag> mappingTagSpan, ITagSpan<IntraTextAdornmentTag>? tagSpan)> _cache = new(); |
There was a problem hiding this comment.
This lets you remove the line in the constructor and keeps it easy to change in the future if needed
There was a problem hiding this comment.
that's a better pattern to have, changed.
ryzngard
left a comment
There was a problem hiding this comment.
Still not 100% sure what cases we're hitting the cache here. snapshot != _cacheSnapshot will be true for scrolling as well as typing right? or is that snapshot only for text changes and not the view changing?
| tag.Tag.Hint, Format, _textView, dataTagSpan, _taggerProvider, _formatMap, classify); | ||
|
|
||
| _cache.Add(new TagSpan<IntraTextAdornmentTag>(dataTagSpan, parameterHintUITag)); | ||
| _cache.Add((tag, null)); |
There was a problem hiding this comment.
💡 named tuple element for null would be good
|
@ryzngard cache hits during scrolling. Lazy calculation of tags in the current view (previously was whole document) happens during typing. |
|
Ah, so the snapshot is the full document text and not the same as the |
|
💭 They should be the same |
Fixes: AB#1361128
Reconfigured code surrounding the creation of inline hint tags. Now we make sure we are in a span that is going to have a hint added prior to calling for the creation of a hint.
Also, Measure is very expensive and I was calling it on the border object rather than the textblock, but it was only necessary for the textblock.