New Posts New Posts RSS Feed: Skip metadata searching when running T4s?
  FAQ FAQ  Forum Search Search  Calendar Calendar  Register Register  Login Login

Skip metadata searching when running T4s?

 Post Reply Post Reply
Author
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Topic: Skip metadata searching when running T4s?
    Posted: 31-Jul-2012 at 5:45pm
Our EDMX models are in a very large project.  Running the T4s has become slower and slower and has reached a point where it seems out of control.

I did some profiling and it looks like nearly all the time is spent when the BaseDomainModelTemplate makes the MetadataTypeHelper in the Generate() method.  I put some timings in and the overall process of generating our T4s takes between 23 and 33 seconds (seems to depend on whether there have been other changes in the project, whether it has been rebuilt, etc.).  And just to do the metadata stuff takes between 20 and 32 seconds.  That is a lot of time.

Making matters worse, we don't use any metadata 'buddy' classes in our app.  From what I could tell, the MetadataTypeHelper stuff was used for these buddy classes.  Of course, I just took a quick look so maybe that class supports other features as well.

I guess my two questions are:  Is the MetadataTypeHelper stuff only necessary to support the 'buddy' classes?  And if so, could we have an option to disable that processing to speed up the code generation?
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 01-Aug-2012 at 11:46pm
Hi Stephen,

1. You're correct. The MetadataTypeHelper stuff is only necessary for buddy classes.

2. The MetadataTypeHelper traverses your domain model project to search for any class marked with the MetadataTypeAttribute so it does take a while if you have a very large project. I will file a feature request to have an option to disable this. Unfortunately for now, the only suggestion I can think of is to manually exclude that piece of code in your custom T4 template.

I am curious though. Generating the model may take a while but it should only be done when there are changes on your model. Is this not the case?

Back to Top
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Posted: 02-Aug-2012 at 9:27am
That is good to hear that the MetadataTypeHelper logic can be skipped.  For now, I suppose I can complete replace the Generate() method to get rid of the MetadataTypeHelper.  I generally don't like copy large methods into our custom T4s since I have to be careful with each upgrade that nothing has changed in the T4s.  But in this case, it's worth it.  And when the feature request goes though, I'll be able to remove the copy/pasted code so that will be nice.

It's true that running the T4s isn't something that gets done all the time.  However, we do make lots of changes to our EDMXs (add a parameter to a stored procedure, tweak a column in a table, etc.) even during normal developement.  And having to wait 30 seconds everytime you save gets very annoying.  Also, we leverage custom T4s to do a lot of work for us so even when there aren't any model changes, we'll sometimes be running the T4s over and over again.  Couple that with the fact that we have quite a few models (where each model takes a long time - even for tiny models)....we are starting to feel the pain.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 13-Aug-2012 at 12:28pm
Hi Stephen,

I was browsing the forum and came across this post again. I noticed something that I didn't notice before.

Also, we leverage custom T4s to do a lot of work for us so even when there aren't any model changes, we'll sometimes be running the T4s over and over again

Correct me if I'm wrong but is it possible to speed things up more by separating the model T4 code and the custom T4 code that does the other stuff ?
Back to Top
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Posted: 13-Aug-2012 at 3:18pm

The 'custom T4s' that I was talking about is actually the model T4s.  We use our custom T4s to further tweak the generated code that DevForce turns out.  

For example, maybe I want to add a custom attribute called "[IsFoo]" to any property in our model that has the word "Foo" in it.  In that case, I use the custom model T4s to do that very easily.  But then if I want to change the attribute to be called [HasAFoo] then I need to tweak the T4 code and re-run the models T4s.  (this is maybe not a great example but it's the kind of thing that we couldn't really do in a separate T4).

Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 20-Aug-2012 at 11:33am
Ah I see. Thanks for the clarification!
Back to Top
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Posted: 08-Apr-2014 at 2:44pm
I'm wondering if there has been any update to this?  Each time we upgrade to a new Dev Force version, it becomes increasingly annoying to maintain our own version of the 'Generate' method in our custom T4s.  It would be really nice if there could be a way to opt-out of the metadata searching in cases where people don't need it.  Since I'm already overriding the standard templates, I'd be fine with a code-only solution.  For example, the logic related to metadata searching could be moved to its own method and then marked virtual.  Then I'd be able to override it so I can skip just that logic.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 09-Apr-2014 at 2:31pm
Hi Stephen,

Sorry but this feature is yet to be implemented and I still don't have a timeline.

Your suggestion makes sense and is well taken.

I'll post to this thread again as soon as I have some updates.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down