ppittle / pMixins

pMixins - Mixin framework for C#
http://pMixins.com
Apache License 2.0
23 stars 5 forks source link

Visual Studio hangs and crashes on building. #33

Open naskovai opened 9 years ago

naskovai commented 9 years ago

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.

ppittle commented 9 years ago

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.

naskovai commented 9 years ago

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.

ppittle commented 9 years ago

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.

naskovai commented 9 years ago

The workaround works well for me. Thank you.

naskovai commented 9 years ago

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.

ppittle commented 9 years ago

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.

naskovai commented 9 years ago

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