ASP.NET MVC3 Razor views - extremely slow editing

2020-06-30 05:36发布

问题:

I've got a relatively small project written in ASP.NET MVC3. After working a while, Visual Studio 2010 becomes very slow in Razor views (other file types work fine). With "slow" I mean "every keystroke takes around 1 second to register". It doesn't matter what that keystroke was - typing a single letter is as slow as pasting a screenful of markup. During this slowdown VS2010 consumes 1 CPU core to 100%. After I restart VS2010, everything goes smoothly again for a small while. This happens in any and all Razor views.

My PC isn't the best, but it should be enough: Core 2 Duo 6700, 4GB of RAM (currently only 75% filled with VS2010 being slow and all, so it's not a RAM shortage), Windows 7 x64.

The project is close to an end, and I remember that for most time there were no problems. This has started only recently, although I cannot imagine what could have caused it.

Does anyone have any ideas about what could be wrong and what could be done to fix it?

回答1:

It is plugins - TFS/AnkvSVN and ReSharper have all caused problems for me.

Turn them off one by one, to discern which one (if only one) is causing you grief.

When you find the culprit, make sure you keep up on any patches with it.

In extreme cases, turn if off if you have a long development session and don't need it the whole time (SVN for instance could be turned on when you are ready to do commits and check ins, etc.)



回答2:

The issue is resolved for me, by installing the Mvc Html5 Templates.

After the installation, I picked XHTML5 and then back HTML5 from the "Target schema" combo box. After that, the paste was instant!

Edit: I uninstalled "Mvc Html5 Templates" and the issue didn't reappear. Perhaps it has something to do with the "HTML 5 Intellisense"



回答3:

Have you installed sp 1 it fixed some performance related issues when loading IntelliSense for markup



回答4:

Run the Resource Monitor (CTRL+SHIFT+ESC, click Performance tab then Resource Monitor button at the bottom). Pay special attention to disk I/O and perhaps CPU usage. Sort disk I/O by Total B/Sec descending. As you type, see if it can identify a process which is causing the issue. Hopefully it's a virus scanner or some other famous performance destroyer and not the Visual Studio process itself, which wouldn't be very helpful.



回答5:

Have you tried opening the same project on a different machine? This will give you an idea whether issue is in the project or VS install. Quite obvious, but is there anything in the event viewer. Are you connected to a domain while this is happening?



回答6:

Well, for me the problem has turned out to be anti virus - we use (or are made to suffer) Sunbelt Vipre on our workstations and as soon as I switch off active protection (so that's basically disabling AV completely) all of a sudden all the performance issues in all windows are gone.



回答7:

Sorry for adding another answer, but there seem to be lots of different causes, so - lets list all possible fixes here.

I tried disabling ReSharper and other addons - did not work. What did work - is reapplying the SP1 again.

PS. Weird, I know. Don't ask, no idea... My guess is - VS was "repairing" itself silently at some point and restored some non-SP1 components.

PPS. You might also want to try disabling "Productivity Power Tools" addon. If you have ReSharper installed - almost all the PPT features are already there, in ReSharper.

PPPS. I have a blog post with several performance tips for Visual Studio & ReSharper, might come handy..



回答8:

Have you tried Cleaning the solution?

In my case, high CPU usage started out of nowhere (WPF project). Restarts of Visual Studio didn't help, neither disabling/uninstalling addons. But Cleaning the solution did help!



回答9:

I was experiencing a very similar issue on a large cshtml file in VS 2015 and was solved for me by turning off all of the automatic formatting options in Options > Text Editor > C# > Formatting > General:

I then use the "Control+K,D" key combination to format the page once I have finished making the necessary code changes.