Commit Graph

185 Commits

Author SHA1 Message Date
Todd Grunke 56374ab393 use var where appropriate 2020-06-15 13:15:38 -07:00
Todd Grunke 2c594199c3 Fix a bug in DefaultRazorSourceLineCollection.GetLineStarts 2020-06-12 17:56:19 -07:00
Todd Grunke a1dd898994 Get rid of LineTrackingStringBuffer class and instead use the line information provided by RazorSourceDocument.
This additionally gets rid of an extra whole buffer allocation in the ParserContext. The most complex bit of the change is around avoiding TextLineCollection.GetLocation.

Overall, I'm seeing a pretty big win here, about 35% less time spent in RazorSyntaxTree.Parse for the typing scenario I was doing in a very large file.
2020-06-12 17:22:24 -07:00
Todd Grunke 073cd0aa40
Merge pull request #22877 from dotnet/dev/toddgrun/MorePerfOptimizations
Dev/toddgrun/more perf optimizations
2020-06-12 13:25:31 -07:00
Todd Grunke 43a628e9fb Small memory allocation optimization in DefaultRazorTagHelperBinderPhase.TrySplitNamespaceAndType
This method allocated multiple strings on every invocation when they were rarely needed. With this change, I see a reduction in memory allocated during RazorProjectEngine.ProcessDesignTime of 1.4%.
2020-06-12 12:04:47 -07:00
Todd Grunke 9cf611b9e2 Revert change to EndLocation as it was incorrectly changed. 2020-06-12 08:28:32 -07:00
Todd Grunke 904fd19605 A couple more perf optimizations focused around memory allocations.
This is the last of the easy wins that I could find for typing in large razor files (minus the logged bug to move the divergence checker code off the UI thread). In the profile for the large document editing, these changes reduce allocated memory during RazorSyntaxTree.Parse by about 25%. CPU wise, the win isn't quite as dramatic, only a couple percent improvement under RazorSyntaxTree.Parse.
2020-06-11 18:11:29 -07:00
Todd Grunke 73f04eecac
Add mechanism where IR token generation can defer allocation of it's … (#22792)
* Add mechanism where IR token generation can defer allocation of it's content.

It turns out that many IR tokens access their content, and thus allocating it is unnecessary. In particular, with this change against a large file, I've seen allocations under SyntaxNodeExtensions.GetContent reduced by about 33%. Performance wise, I've seen the number of CPU samples in the profile under GetContent reduce by about 40% (in my sample I typed 26 characters and there was about 600 ms less spent in GetContent)

* ContentGetter => ContentFactory

* Make tests happy with the switch from IntermediateToken to IntermediateTokenWithDeferreedContentAllocation

* IntermediateTokenWithDeferredContentAllocation => LazyIntermediateToken
2020-06-11 18:20:41 +00:00
Todd Grunke 837c639041 Expand the SyntaxTokenCache to contain more than just whitespace tokens. 2020-06-08 15:37:35 -07:00
Todd Grunke a5d433103c Stop boxing to compare the SyntaxKind enum during tokenization
This accounts for a significant portion of razor's allocations during parsing.
2020-06-08 10:45:11 -07:00
John Luo 836001cf96
Set PublishWindowsPdb for Razor tooling packages (#22605) 2020-06-05 23:38:17 +00:00
Todd Grunke da52d6b636
Move IsSpacingToken perf optimizations down to base class (#22555)
This gives the HtmlMarkupParser the same non-allocating behavior for it's IsSpacing* method invocations. Profile from following feedback ticket showed ~100ms time spent doing these allocations: https://developercommunity.visualstudio.com/content/problem/1006207/vs-2019-constant-freezing-please-wait-for-an-edito.html?childToView=1065769
2020-06-04 23:56:50 +00:00
Ajay Bhargav B d68ff6182e
Add IVT from Razor.Language to LanguageServerClient.Razor assembly (#22474) 2020-06-02 19:21:44 +00:00
John Luo 50f3a16571 aspnetcore-tooling migration fixups 2020-05-26 12:31:49 -07:00
Todd Grunke d782a06462 Decrease allocations from using method groups (dotnet/aspnetcore-tooling#1896)
* Previous optimization didn't help as much as intended.

By specifying a method group as the arguments to method like ReadWhile, an allocation was still occurring. Instead, cache the Func as a member in the class and use it instead of the method group.\n\nCommit migrated from 2e6aa150bc
2020-05-13 16:00:34 -07:00
Todd Grunke 016fd1ee9e Improve CSharpLanguageCharacteristics.MapKeyword performance (dotnet/aspnetcore-tooling#1879)
* Improve CSharpLanguageCharacteristics.MapKeyword performance

The razor typing perf test profile I'm looking at has 156 ms of CPU cycles spent in this method, mostly in Enum.ToString()
\n\nCommit migrated from e821a4642e
2020-05-11 12:42:39 -07:00
Todd Grunke a70de6b67b Small perf improvement in TokenizerBackedParser.Accept and ReadWhile. (dotnet/aspnetcore-tooling#1882)
In the razor perf typing test, Accept was showing 27 ms allocating enumerators. Additionally, modified ReadWhile to only allocate if it would return a non-empty collection (and to not use the complexity introduced by using yield enumerators)\n\nCommit migrated from 27a14af36a
2020-05-11 10:28:31 -07:00
Todd Grunke 485924edd2 Improve Annotation and SpanContext performance. (dotnet/aspnetcore-tooling#1881)
The razor perf test shows about 70 ms CPU of WithSpanContext is in allocation. GetAnnotation similarly is showing about 60 ms in allocation (of which this only partly improves)\n\nCommit migrated from a060f129ff
2020-05-11 10:27:40 -07:00
Todd Grunke d1e7d8e466 Improve HtmlTokenizer.AtToken performance. (dotnet/aspnetcore-tooling#1880)
Our razor typing test measured 153 CPU ms in this method. Optimized by fewer calls to CurrentCharacter, not checking '<' twice, and uswing a switch stmt.\n\nCommit migrated from c601c2f11e
2020-05-11 10:26:56 -07:00
Todd Grunke b0d819f1e8 Several changes targeted to improving perf of RazorSyntaxTree.Parse (dotnet/aspnetcore-tooling#1874)
* Several changes targeted to improving perf of RazorSyntaxTree.Parse

1) Modify ParserHelpers.IsNewLine to use a switch instead of Array.IndexOf
2) Modify Tokenizer.CreateToken to take in an array of RazorDiagnostics rather than an IReadOnlyList as that was causing a ToArray call on an empty diagnostics very often (during a SyntaxFactory.Token call)
3) Modify TokenizerBackedParser.Putback to allow an IReadOnlyList as a parameter to not require creation of a reverse enumerator.
4) Cut down allocations in HtmlMarkupParser.GetParserState by:
    a) Using an IReadOnlyList instead of IEnumerable to get rid of the allocations from the .any calls
    b) Don't allocate while reading initial spacing
    c) Inline the IsSpacingToken code so cut down on code executed and need to allocate a separate Func
5) Modify CSharpCodeParser.IsSpacingToken to now be a set of methods instead of a single method that allocates a Func. This is a very high traffic method.
6) Implement a fairly rudimentary Whitespace token cache, as they can be reused. This was based off Roslyn's SyntaxNodeCache, but simplified significantly. It's probably worth investigating whether you should more fully embrance token caching outside of whitespace.

* PR feedback and added one more optimization in LocateOwner that's been bugging me for years. Assuming all chidlren are contained within a nodes span, we can short-circuit the DFS this code was doing significantly cutting time in this method which is important as it's exercised on the main thread during typing.

* missed a space

* StringTextToSnapshot's switch to IsNewLine needed to use start as the index to begin the search, not zero.\n\nCommit migrated from 45411f7526
2020-05-09 06:06:13 -07:00
N. Taylor Mullen ed7338c15a Remove RazorDeveloperTools because they were infrequently used and caused problems.
\n\nCommit migrated from c2d717bc98
2020-05-08 16:52:27 -07:00
Todd Grunke c027fcf8e6 Missed a minor optimization as I wasn't using a parameter for the binary search method. The files I've opened don't actually hit the code path (they always hit the optimization for checking the previous/next/current line)
\n\nCommit migrated from 75f34eec60
2020-05-07 20:44:15 -07:00
Todd Grunke 069b409dd4 Fix perf issue in LineTrackingStringbuffer.ScanLines.
I noticed several hundred ms spent in this method from a customer profile. Primarilly, the method was doing a linear scan of all lines trying to find one that contained the requested position. I changed this to a binary search, but kept/improved the optimization around checking next/previous lines before instigating the search.

Note, there was also a bug where the old code did:

else if (absoluteIndex > _currentLine.Index && _currentLine.Index + 1 < _lines.Count)

but it should have been coparing absoluteIndex with _currentLine.Start
\n\nCommit migrated from 32a0f28708
2020-05-07 17:35:41 -07:00
Tanay Parikh 26c5807c98 <text> Tag IntelliSense Support (dotnet/aspnetcore-tooling#1675)
* <text> Tag IntelliSense Implementation

* Text node language context support

* Added Tests\n\nCommit migrated from a0f99cd14f
2020-03-12 22:45:50 -07:00
N. Taylor Mullen b89d98da19 Split Razor Language Server into library and executable.
- This is a pre-requisite work item to run our language server in-process in Visual Studio. VS is a .NET framework application so we can't have a language server which targets netcoreapp be loaded. Therefore, in order to account for this I needed to re-target our language server library to netstandard2.0 so it can be referenced via a netcoreapp (rzls.exe) and a .NET framework app.
- Added a new `rzls` project to be the maintainer of our OOP language server
- Had to make adjustments to the existing language server project to be compatible with netstandard2.0.
- Created a new `RazorLanguageServer` type to initiate our Language Server but not start and initialize it. To enable a consumer to initialize the new language server I had to use private reflection to `Initialize` O#'s internal type. This is a temporary measure which I intend to expand the O# lib to make their Initialize method public.

dotnet/aspnetcoredotnet/aspnetcore-tooling#19185
\n\nCommit migrated from 79841b9371
2020-02-28 22:32:47 -08:00
Ajay Bhargav B d41276b0fa Publish generated HTML in the client (dotnet/aspnetcore-tooling#1633)
* Publish generated HTML in the client

* feedback

* fix
\n\nCommit migrated from a666c6f5e3
2020-02-27 14:49:52 -08:00
Ajay Bhargav B b84fc9b3b6 Generate pure HTML document as part of Razor code generation (dotnet/aspnetcore-tooling#1624)
* Generate pure HTML document as part of Razor code generation

* feedback
\n\nCommit migrated from 478e2ceda8
2020-02-25 13:40:08 -08:00
Ajay Bhargav B f1ccf855eb LSP Razor formatting for Razor code block directives (dotnet/aspnetcore-tooling#1573)
LSP Razor formatting for Razor code block directives
- Support for @code/@functions block formatting
    - Except when it contains Markup or other Razor constructs
- Added a RazorFormattingService which is invoked by the RazorFormattingEndpoint.
- Added a custom razor/rangeFormatting command that the server can use to ask the client to format a range of the projected C# or HTML document
- Added a CSharpFormatter and HTMLFormatter that invoke the above mentioned command
- Added FormattingSpan and its corresponding visitor to represent Razor understanding of indentation
- Moved the document mapping code to a separate RazorDocumentMappingService service for ease of use
- Added necessary extension methods for convenience. Some of them were copied from Roslyn
- Some cleanup
- Added a C# test formatter to enable unit testing. Right now it calls Roslyn APIs directly. As far as I've seen its behavior is the same as OmniSharp formatting except it doesn't remove trailing whitespace and empty lines. I am following up with people to understand why that is the case.
Added/updated tests
\n\nCommit migrated from 62051b9ad7
2020-02-13 16:37:15 -08:00
N. Taylor Mullen 8ea0f36d39 Remove Test variant Newtonsoft.Json.
- Our Newtonsoft.Json versions are now aligned.
\n\nCommit migrated from e7a506b1f4
2020-01-14 14:35:13 -08:00
Kevin Pilch 52b9fd85a2 Update links for repo moves/renames (dotnet/aspnetcore-tooling#1474)
\n\nCommit migrated from fae9a5fdbc
2020-01-08 16:51:55 -08:00
N. Taylor Mullen e2dc96c7b9 Fix runtime preventDefault / stopPropagation break.
- The Blazor runtime doesn't support adding attributes prior to any sort of content frames being applied. This change ensures that `ComponentAttributes` (how preventDefault / stopPropagation are represented) are handled like other HTML attributes (applied first).
- Updated existing tests and their baselines.

aspnet/AspNetCoredotnet/aspnetcore-tooling#16611
\n\nCommit migrated from 1513cd2a5b
2019-10-28 12:41:44 -07:00
Ajay Bhargav Baaskaran 7f126d5694 Addressed minor comments
\n\nCommit migrated from c170fd9837
2019-10-18 10:55:45 -07:00
Ajay Bhargav Baaskaran 5badd94182 Add support for PreventDefault and StopPropagation in event handlers
\n\nCommit migrated from ae5be3efc0
2019-10-18 10:55:45 -07:00
Ryan Nowak 73877e9c2f Allow expressions with @bind:event
Fixes aspnet/AspNetCoredotnet/aspnetcore-tooling#13181

The big change here is that we have to allow an HtmlAttributeIRNode to have
a dynamically computed attribute name. This isn't something that exists
anywhere else in the system.
\n\nCommit migrated from 559f0f5e52
2019-10-07 18:08:13 -07:00
Ryan Nowak dcc4084af8 Merge branch 'release/3.1' into merge/release/3.0-to-release/3.1\n\nCommit migrated from f9ac723b29 2019-10-07 12:10:26 -07:00
Ryan Nowak f19dc08305 Fix dotnet/aspnetcore-tooling#10498 - void elements with directive attributes
This change updates tag helper binding logic to allow directive
attributes (when they appear alone) to bind to any kind of tag
(start/end, void, self-closing).

Tag Helpers don't have a semantic that allows this level of flexibility
- using StartTagOnly as suggested in the issue means that this would
*only* work for void elements.

There's no change to any of the directive attribute implementations
because this is a global change in the tag helper infra.
\n\nCommit migrated from fd72afc1c6
2019-10-04 13:46:01 -07:00
wtgodbe 7a61205024 Add workaround to one more project
\n\nCommit migrated from 381138fc72
2019-10-02 12:21:01 -07:00
Ajay Bhargav Baaskaran ef8830ffec Update baselines to unbreak tests (dotnet/aspnetcore-tooling#1184)
\n\nCommit migrated from 0d1e0d6eba
2019-10-01 13:59:41 -07:00
N. Taylor Mullen 1e9c0f01af Add Blazor partial class support in Visual Studio. (dotnet/aspnetcore-tooling#1182)
- No longer mark declaration files as single file generators. Prior to this we relied on SingleFileGenerators to dynamically update the declaration files when .razor files changed. However, to make partial classes work we can no longer depend on declaration files being available because their existence causes us to have to mangle class names for opened documents; otherwise you get two files with same name and result in ambiguous definition errors.
- Stopped including declaration files as part of the users compilation. This was intended to make the design time experience operate more similar to how Blazor apps function at runtime (directly access each component instead of their declarations). We now rely on the background code generation effort built from the find all references work to supply users with strongly typed component names.
- Stop mangling class names for Visual Studio. Razor.VSCode has its own set of configurations which i'm not addressing as part of this changeset.
- Start generating components with the partial modifier to their class name to enable partial class support.
- Updated existing tests to expect partial modifier.

aspnet/AspNetCoredotnet/aspnetcore-tooling#5487\n\nCommit migrated from 73858cdd37
2019-10-01 13:59:33 -07:00
Ajay Bhargav Baaskaran 3dcc779659 Prefer child content over a matching component (dotnet/aspnetcore-tooling#1180)
* Prefer child content over a matching component

* feedback
\n\nCommit migrated from 9c83a09944
2019-09-27 14:27:10 -07:00
Ajay Bhargav Baaskaran 39d8e322d1 Fix misc attribute content sometimes getting ignored (dotnet/aspnetcore-tooling#1176)
\n\nCommit migrated from 8108f50021
2019-09-27 14:22:21 -07:00
William Godbe b8575a5098 Merge branch 'release/3.1' into merge/release/3.0-to-release/3.1\n\nCommit migrated from 68f7376ef6 2019-09-26 10:18:00 -07:00
Pranav K 5ac56229e1 Fixup build errors
\n\nCommit migrated from 83b434dfc3
2019-09-24 18:12:16 -07:00
N. Taylor Mullen 66f2aac299 Integrate Razor LanguageServer (without plugin) into src/Razor.
- Added tests for both the language server and the common language server projects.
- Updated publish MSBuild bits to publish to `artifacts/LanguageServer/$(Configuration)/TFM`
- Updated the language server to be netcoreapp3.0

aspnet/AspNetCoredotnet/aspnetcore-tooling#13494
\n\nCommit migrated from 984c638b37
2019-09-20 11:44:08 -07:00
Ryan Nowak cb35a0aa40 Reaction to API review changes
This change updates the snapshot of components APIs used in compiler
tests and updates the tests to react tot hose changes.
\n\nCommit migrated from c8cc588bca
2019-08-20 08:20:36 -07:00
N. Taylor Mullen f3536ca403 Revert "Fix: dotnet/aspnetcore-tooling#11197 automatic backing-field for @ref (dotnet/aspnetcore-tooling#707)"
This reverts commit dadf9fa.
\n\nCommit migrated from afddfcb49e
2019-08-15 14:35:26 -07:00
N. Taylor Mullen 9584c7e34f Revert "Fix a bug with ref and declaration phase"
This reverts commit dotnet/aspnetcore-tooling@09b50151ef.

# Conflicts:
#	src/Razor/test/RazorLanguage.Test/IntegrationTests/ComponentDeclarationIntegrationTest.cs
\n\nCommit migrated from c0e934ed7c
2019-08-15 14:35:26 -07:00
dotnet-maestro[bot] 781743fa30 [release/3.0] Update dependencies from aspnet/Extensions (dotnet/aspnetcore-tooling#975)
* Update dependencies from https://github.com/aspnet/Extensions build 20190815.2

- Microsoft.AspNetCore.BenchmarkRunner.Sources - 3.0.0-preview9.19415.2
- Microsoft.AspNetCore.Testing - 3.0.0-preview9.19415.2
- Microsoft.Extensions.CommandLineUtils.Sources - 3.0.0-preview9.19415.2
- Microsoft.Extensions.HashCodeCombiner.Sources - 3.0.0-preview9.19415.2
- Microsoft.Extensions.NonCapturingTimer.Sources - 3.0.0-preview9.19415.2
- Microsoft.Extensions.Logging - 3.0.0-preview9.19415.2

Dependency coherency updates

- Microsoft.NETCore.App.Runtime.win-x64 - 3.0.0-preview9-19414-17 (parent: Microsoft.Extensions.Logging)
- Microsoft.Extensions.DependencyModel - 3.0.0-preview9-19414-17 (parent: Microsoft.Extensions.Logging)
- Microsoft.NETCore.App.Ref - 3.0.0-preview9-19414-17 (parent: Microsoft.Extensions.Logging)
- Microsoft.Net.Compilers.Toolset - 3.3.0-beta3-19415-01 (parent: Microsoft.Extensions.Logging)

* Update dependencies from https://github.com/aspnet/Extensions build 20190814.4

- Microsoft.AspNetCore.BenchmarkRunner.Sources - 3.0.0-preview9.19414.4
- Microsoft.AspNetCore.Testing - 3.0.0-preview9.19414.4
- Microsoft.Extensions.CommandLineUtils.Sources - 3.0.0-preview9.19414.4
- Microsoft.Extensions.HashCodeCombiner.Sources - 3.0.0-preview9.19414.4
- Microsoft.Extensions.NonCapturingTimer.Sources - 3.0.0-preview9.19414.4
- Microsoft.Extensions.Logging - 3.0.0-preview9.19414.4

* Update dependencies from https://github.com/aspnet/Extensions build 20190815.2

- Microsoft.AspNetCore.BenchmarkRunner.Sources - 3.0.0-preview9.19415.2
- Microsoft.AspNetCore.Testing - 3.0.0-preview9.19415.2
- Microsoft.Extensions.CommandLineUtils.Sources - 3.0.0-preview9.19415.2
- Microsoft.Extensions.HashCodeCombiner.Sources - 3.0.0-preview9.19415.2
- Microsoft.Extensions.NonCapturingTimer.Sources - 3.0.0-preview9.19415.2
- Microsoft.Extensions.Logging - 3.0.0-preview9.19415.2

* React to namespace removal
\n\nCommit migrated from 543a1ae2a3
2019-08-15 20:12:47 +00:00
Pranav K 80d6dfea89 Give "builder" a less discoverable name
Fixes https://github.com/aspnet/AspNetCore/issues/12991
\n\nCommit migrated from 7e974693b6
2019-08-13 12:39:55 -07:00
Pranav K 32196f8023 Use globally qualified type name when generating TypeInference (dotnet/aspnetcore-tooling#946)
The code-generated TypeInference type resides in a custom namespace.
Any types that it refers to in user code must be qualified using the "global::" prefix
to avoid type \ namespace conflicts.

Fixes https://github.com/aspnet/AspNetCore/issues/12116\n\nCommit migrated from f0e09e4a97
2019-08-13 12:35:37 -07:00