pMixins icon indicating copy to clipboard operation
pMixins copied to clipboard

Visual Studio hangs and crashes on building.

Open naskovai opened this issue 10 years ago • 7 comments

Since pMixins generates mixin files always on save the build process becomes incredibly slow. It looks like the main thread of devenv is being used for the code generation because VS hangs. Sometimes it crashes. It would be better to regenerate the mixin file only if the main file is dirty.

naskovai avatar Dec 15 '14 13:12 naskovai

Hi paletov, thanks for posting this.

You are correct, pMixins currently uses a very naive approach for deciding when to (re)generate the mixin code behind files. All code behind files are (re)generated on Solution Open (in case the file system has changed outside of VS) and on Build (just in case anything was missed).

The plan for the next release is to optimize this process for better performance (as well as more complex scenarios) so pMixins doesn't slow down VS as much.

That said, I've only seen pMixins slow down builds by a few seconds for my projects. Granted that's a very relative statement, but could you expand on "incredibly slow". I'm curious if there is anything in your project that is causing abnormal pMixins performance due to something other than the unoptimized code behind generation strategy.

ppittle avatar Dec 15 '14 16:12 ppittle

Hi ppittle, thanks for the quick response.

Let me apologise for not being specific. My project is a client library for payment gateway API. I have 70 models of requests and responses. The average number of mixins per entity is 5 and the average number of properties in a mixin is also 5.

Visual Studio freezes during the time (from 10 to 15 seconds) of code behind generation on each project build. This makes continuous testing very inconvenient.

naskovai avatar Dec 16 '14 08:12 naskovai

Ok, what you are experiencing makes sense. I'll prioritize addressing this issue, and if it makes sense can publish it as a separate release.

In the mean time, there is a special attribute DisableCodeGenerationAttribute that will short circuit code generation. You can decorate either a specific class or an entire assembly (in AssemblyInfo.cs) with it to turn off pMixins. You could use this as a work around for now to limit code generation to only when it's appropriate.

For example, in AssemblyInfo.cs:

[assembly: CopaceticSoftware.pMixins.Attributes.DisableCodeGeneration]

If you need to regenerate the code-behind files, you can comment out the line, then rebuild your project.

ppittle avatar Dec 16 '14 09:12 ppittle

The workaround works well for me. Thank you.

naskovai avatar Dec 17 '14 12:12 naskovai

Actually this attribute is causing generation of empty partial classes. They override the existing ones which have been generated correctly.

Update: Sometimes this happens on build even when the 'DisableCodeGeneration' attribute is missing.

naskovai avatar Dec 17 '14 15:12 naskovai

If an error occurs during the generation of a code behind file, then the code behind file is rewritten as empty. The reasoning was this would make what ever error occurred more visible to the user. For example, if you deleted the partial keyword on the Target, the code behind file is cleared and an VS warning is added.

However, the DisableCodeGeneration shouldn't be clearing out code-behind files. This sounds like a bug. I'll create an issue to investigate.

ppittle avatar Dec 18 '14 09:12 ppittle

It's great that you are keeping this project alive. Thank you for the support.

naskovai avatar Dec 18 '14 10:12 naskovai